Update app.py
Browse files
app.py
CHANGED
|
@@ -92,9 +92,7 @@ model = genai.GenerativeModel(
|
|
| 92 |
# See https://ai.google.dev/gemini-api/docs/safety-settings
|
| 93 |
)
|
| 94 |
|
| 95 |
-
|
| 96 |
|
| 97 |
-
cloud_vision = vision.ImageAnnotatorClient()
|
| 98 |
|
| 99 |
# first three are "๋ฑ๋ก์ผ์", "์ธ๋ค์ผ", "๋ฐ๋ก๊ฐ๊ธฐ",
|
| 100 |
receipt_sheet_headers = ['๋ฐํ์ผ', '์ํธ', '์ฌ์
์๋ฒํธ', 'ํฉ๊ณ๊ธ์ก', '๋ด์ญ', '์นด๋๋ฒํธ', '์นด๋์ข
๋ฅ', '์น์ธ๋ฒํธ', '๊ธฐํ']
|
|
@@ -175,6 +173,34 @@ async def request_gpt4o_completion(image_id: str, user_credit: int):
|
|
| 175 |
# Step 2: Convert the image to base64
|
| 176 |
base64_image = base64.b64encode(file_content).decode('utf-8')
|
| 177 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
# Step 3: Get text data from the image using Google Cloud Vision
|
| 179 |
logging.info("Initiating text detection with Google Cloud Vision")
|
| 180 |
client = vision.ImageAnnotatorClient()
|
|
|
|
| 92 |
# See https://ai.google.dev/gemini-api/docs/safety-settings
|
| 93 |
)
|
| 94 |
|
|
|
|
| 95 |
|
|
|
|
| 96 |
|
| 97 |
# first three are "๋ฑ๋ก์ผ์", "์ธ๋ค์ผ", "๋ฐ๋ก๊ฐ๊ธฐ",
|
| 98 |
receipt_sheet_headers = ['๋ฐํ์ผ', '์ํธ', '์ฌ์
์๋ฒํธ', 'ํฉ๊ณ๊ธ์ก', '๋ด์ญ', '์นด๋๋ฒํธ', '์นด๋์ข
๋ฅ', '์น์ธ๋ฒํธ', '๊ธฐํ']
|
|
|
|
| 173 |
# Step 2: Convert the image to base64
|
| 174 |
base64_image = base64.b64encode(file_content).decode('utf-8')
|
| 175 |
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
client = vision.ImageAnnotatorClient()
|
| 179 |
+
|
| 180 |
+
with open(path, "rb") as image_file:
|
| 181 |
+
content = image_file.read()
|
| 182 |
+
|
| 183 |
+
image = vision.Image(content=file_content)
|
| 184 |
+
|
| 185 |
+
response = client.text_detection(image=image)
|
| 186 |
+
texts = response.text_annotations
|
| 187 |
+
print("Texts:")
|
| 188 |
+
|
| 189 |
+
for text in texts:
|
| 190 |
+
print(f'\n"{text.description}"')
|
| 191 |
+
|
| 192 |
+
vertices = [
|
| 193 |
+
f"({vertex.x},{vertex.y})" for vertex in text.bounding_poly.vertices
|
| 194 |
+
]
|
| 195 |
+
|
| 196 |
+
print("bounds: {}".format(",".join(vertices)))
|
| 197 |
+
|
| 198 |
+
if response.error.message:
|
| 199 |
+
raise Exception(
|
| 200 |
+
"{}\nFor more info on error messages, check: "
|
| 201 |
+
"https://cloud.google.com/apis/design/errors".format(response.error.message)
|
| 202 |
+
)
|
| 203 |
+
|
| 204 |
# Step 3: Get text data from the image using Google Cloud Vision
|
| 205 |
logging.info("Initiating text detection with Google Cloud Vision")
|
| 206 |
client = vision.ImageAnnotatorClient()
|