m8chaa commited on
Commit
1819bc1
โ€ข
1 Parent(s): 24f3038

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -40
app.py CHANGED
@@ -101,10 +101,10 @@ business_card_sheet_headers = ['์ด๋ฆ„', 'ํšŒ์‚ฌ๋ช…', '์†Œ์† ๋ฐ ์ง์œ„', '์ฃผ
101
  sms_sheet_headers = ['๋‚ ์งœ', '๊ณ„์ขŒ', '์ž…๊ธˆ', '์ถœ๊ธˆ', '์ž”์•ก', '๋ฌธ์ž']
102
  contact_sheet_headers = ['์ด๋ฆ„', '์ „ํ™”๋ฒˆํ˜ธ1', '์ „ํ™”๋ฒˆํ˜ธ2', '์ „ํ™”๋ฒˆํ˜ธ3', '์ด๋ฉ”์ผ์ฃผ์†Œ1', '์ด๋ฉ”์ผ์ฃผ์†Œ2', '์ด๋ฉ”์ผ์ฃผ์†Œ3', '๊ทธ๋ฃน']
103
 
104
- receipts_ss = 0
105
- business_cards_ss = 344204272
106
- contacts_ss = 1943060316
107
- sms_ss = 799147214
108
 
109
  kst = pytz.timezone('Asia/Seoul')
110
 
@@ -170,37 +170,7 @@ async def request_gpt4o_completion(image_id: str, user_credit: int):
170
  # Step 1: Download the image file from Google Drive
171
  file_content, mime_type = await download_file_from_drive(image_id)
172
 
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
-
181
- # image = vision.Image(content=file_content)
182
-
183
- # response = client.text_detection(image=image)
184
- # texts = response.text_annotations
185
- # print("Texts:")
186
-
187
- # for text in texts:
188
- # print(f'\n"{text.description}"')
189
-
190
- # vertices = [
191
- # f"({vertex.x},{vertex.y})" for vertex in text.bounding_poly.vertices
192
- # ]
193
-
194
- # print("bounds: {}".format(",".join(vertices)))
195
-
196
- # if response.error.message:
197
- # raise Exception(
198
- # "{}\nFor more info on error messages, check: "
199
- # "https://cloud.google.com/apis/design/errors".format(response.error.message)
200
- # )
201
-
202
  # Step 3: Get text data from the image using Google Cloud Vision
203
- logging.info("Initiating text detection with Google Cloud Vision")
204
  client = vision.ImageAnnotatorClient()
205
  image = vision.Image(content=file_content)
206
  response = client.text_detection(image=image)
@@ -215,12 +185,10 @@ async def request_gpt4o_completion(image_id: str, user_credit: int):
215
 
216
  # Extract all detected text
217
  extracted_text = texts[0].description if texts else ""
218
- logging.info(f"Text extracted from image. Length: {len(extracted_text)} characters")
219
-
220
 
221
  # Step 4: Prepare the prompt for Gemini
222
  prompt = f'''
223
- Image content: {extracted_text[:500]}... # Truncated for logging purposes
224
 
225
  Please analyze the above text extracted from an image and perform the following tasks:
226
  1. Identify if the image contains receipts or business cards.
@@ -235,19 +203,17 @@ async def request_gpt4o_completion(image_id: str, user_credit: int):
235
  logging.info("Prompt prepared for Gemini model: " + prompt)
236
 
237
  # Generate content using the Gemini model
238
- logging.info("Sending request to Gemini model")
239
  response = model.generate_content(
240
  contents=[
241
  prompt
242
  ]
243
  )
244
- logging.info("Received response from Gemini model")
245
 
246
  # Check if the response has text content
247
  if response.text:
248
  logging.info("Parsing Gemini model response")
249
  json_response = json.loads(response.text)
250
- logging.info(f"JSON response parsed. Keys: {json_response.keys()}")
251
  return json.dumps(json_response)
252
  else:
253
  logging.error("Gemini model did not return a text response")
 
101
  sms_sheet_headers = ['๋‚ ์งœ', '๊ณ„์ขŒ', '์ž…๊ธˆ', '์ถœ๊ธˆ', '์ž”์•ก', '๋ฌธ์ž']
102
  contact_sheet_headers = ['์ด๋ฆ„', '์ „ํ™”๋ฒˆํ˜ธ1', '์ „ํ™”๋ฒˆํ˜ธ2', '์ „ํ™”๋ฒˆํ˜ธ3', '์ด๋ฉ”์ผ์ฃผ์†Œ1', '์ด๋ฉ”์ผ์ฃผ์†Œ2', '์ด๋ฉ”์ผ์ฃผ์†Œ3', '๊ทธ๋ฃน']
103
 
104
+ receipts_ss = 1395967745
105
+ business_cards_ss = 1733555840
106
+ contacts_ss = 1729750548
107
+ sms_ss = 1891574758
108
 
109
  kst = pytz.timezone('Asia/Seoul')
110
 
 
170
  # Step 1: Download the image file from Google Drive
171
  file_content, mime_type = await download_file_from_drive(image_id)
172
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
173
  # Step 3: Get text data from the image using Google Cloud Vision
 
174
  client = vision.ImageAnnotatorClient()
175
  image = vision.Image(content=file_content)
176
  response = client.text_detection(image=image)
 
185
 
186
  # Extract all detected text
187
  extracted_text = texts[0].description if texts else ""
 
 
188
 
189
  # Step 4: Prepare the prompt for Gemini
190
  prompt = f'''
191
+ Image content: {extracted_text}
192
 
193
  Please analyze the above text extracted from an image and perform the following tasks:
194
  1. Identify if the image contains receipts or business cards.
 
203
  logging.info("Prompt prepared for Gemini model: " + prompt)
204
 
205
  # Generate content using the Gemini model
 
206
  response = model.generate_content(
207
  contents=[
208
  prompt
209
  ]
210
  )
 
211
 
212
  # Check if the response has text content
213
  if response.text:
214
  logging.info("Parsing Gemini model response")
215
  json_response = json.loads(response.text)
216
+ logging.info(f"JSON response parsed: {response.text}")
217
  return json.dumps(json_response)
218
  else:
219
  logging.error("Gemini model did not return a text response")