m8chaa commited on
Commit
6fcc2cd
ยท
verified ยท
1 Parent(s): 4690bf9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -2
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()