mirror of
https://github.com/Paillat-dev/Botator.git
synced 2026-01-02 09:16:19 +00:00
[GENERAL] Code reformatting using Black standard
This commit is contained in:
@@ -2,12 +2,14 @@ import io
|
||||
import os
|
||||
import asyncio
|
||||
from config import debug
|
||||
|
||||
# Imports the Google Cloud client library
|
||||
from google.cloud import vision
|
||||
|
||||
# Instantiates a client
|
||||
client = vision.ImageAnnotatorClient()
|
||||
|
||||
|
||||
async def process(attachment):
|
||||
debug("Processing image...")
|
||||
image = vision.Image()
|
||||
@@ -18,18 +20,25 @@ async def process(attachment):
|
||||
labels = labels.label_annotations
|
||||
texts = texts.text_annotations
|
||||
objects = objects.localized_object_annotations
|
||||
#we take the first 4 labels and the first 4 objects
|
||||
# we take the first 4 labels and the first 4 objects
|
||||
labels = labels[:2]
|
||||
objects = objects[:7]
|
||||
final = "<image\n"
|
||||
if len(labels) > 0: final += "Labels:\n"
|
||||
if len(labels) > 0:
|
||||
final += "Labels:\n"
|
||||
for label in labels:
|
||||
final += label.description + ", "
|
||||
final = final[:-2] + "\n"
|
||||
if len(texts) > 0: final += "Text:\n"
|
||||
try: final += texts[0].description + "\n" #we take the first text, wich is the whole text in reality
|
||||
except: pass
|
||||
if len(objects) > 0: final += "Objects:\n"
|
||||
if len(texts) > 0:
|
||||
final += "Text:\n"
|
||||
try:
|
||||
final += (
|
||||
texts[0].description + "\n"
|
||||
) # we take the first text, wich is the whole text in reality
|
||||
except:
|
||||
pass
|
||||
if len(objects) > 0:
|
||||
final += "Objects:\n"
|
||||
for obj in objects:
|
||||
final += obj.name + ", "
|
||||
final = final[:-2] + "\n"
|
||||
@@ -39,8 +48,12 @@ async def process(attachment):
|
||||
if not os.path.exists("./../database/google-vision/results"):
|
||||
os.mkdir("./../database/google-vision/results")
|
||||
# we create the file
|
||||
with open(f"./../database/google-vision/results/{attachment.id}.txt", "w", encoding="utf-8") as f:
|
||||
with open(
|
||||
f"./../database/google-vision/results/{attachment.id}.txt",
|
||||
"w",
|
||||
encoding="utf-8",
|
||||
) as f:
|
||||
f.write(final)
|
||||
f.close()
|
||||
|
||||
return final
|
||||
return final
|
||||
|
||||
Reference in New Issue
Block a user