Update app.py
Browse files
app.py
CHANGED
@@ -198,7 +198,10 @@ async def request_gpt4o_completion(image_id: str, user_credit: int):
|
|
198 |
#Guideline
|
199 |
-strictly adhere to the given content of OCR text.
|
200 |
-it could be of receipt(s) or business card(s) but not both
|
201 |
-
-any other info that couldn't be classified
|
|
|
|
|
|
|
202 |
|
203 |
#Example
|
204 |
##Receipts
|
@@ -243,17 +246,17 @@ async def request_gpt4o_completion(image_id: str, user_credit: int):
|
|
243 |
2502230078357
|
244 |
|
245 |
Output
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
๋ํ๋ฆฌ๋ฒ์ฏ 1,000์ 1๊ฐ
|
252 |
์๋ฐฐ์ถ 1,800์ 1๊ฐ
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
|
258 |
##Business Cards
|
259 |
Input
|
@@ -270,16 +273,16 @@ async def request_gpt4o_completion(image_id: str, user_credit: int):
|
|
270 |
www.iprima.com
|
271 |
|
272 |
Output
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
|
284 |
Image content: {extracted_text}
|
285 |
'''
|
@@ -343,112 +346,6 @@ async def move_file_to_folder(file_id, current_parents, new_parents):
|
|
343 |
except Exception as e:
|
344 |
logging.error(f"Failed to move file {file_id} to new folders: {e}")
|
345 |
|
346 |
-
|
347 |
-
# async def update_user_sheet(spreadsheet_id:str, sheet_id:int, sheet_name, data: List[List[str]], is_reset: Optional[bool] = False):
|
348 |
-
# print(f"Spreadsheet ID: {spreadsheet_id}, Sheet ID: {sheet_id}, sheet name: {sheet_name}, Data: {data}")
|
349 |
-
# # first identify the area to insert the data
|
350 |
-
# no_of_rows = len(data)
|
351 |
-
# no_of_cols = len(data[0])
|
352 |
-
|
353 |
-
# if is_reset:
|
354 |
-
# # sheet_name = f"{sheet_name} {datetime.now(kst).strftime("%Y-%m-%d %H:%M:%S")}"
|
355 |
-
# sheet_name = f"{sheet_name} {datetime.now(kst).strftime('%Y-%m-%d %H:%M')}"
|
356 |
-
# duplicate_requests = [{
|
357 |
-
# "duplicateSheet": {
|
358 |
-
# "sourceSheetId": contacts_ss,
|
359 |
-
# "newSheetName": sheet_name
|
360 |
-
# }
|
361 |
-
# }]
|
362 |
-
# duplicate_response = sheet_service.spreadsheets().batchUpdate(
|
363 |
-
# spreadsheetId=spreadsheet_id,
|
364 |
-
# body={
|
365 |
-
# 'requests': duplicate_requests
|
366 |
-
# }
|
367 |
-
# ).execute()
|
368 |
-
# sheet_id = duplicate_response['replies'][0]['duplicateSheet']['properties']['sheetId']
|
369 |
-
|
370 |
-
# # Insert new rows
|
371 |
-
# requests = [
|
372 |
-
# {
|
373 |
-
# "updateSheetProperties": {
|
374 |
-
# "properties": {
|
375 |
-
# "sheetId": sheet_id,
|
376 |
-
# "hidden": False
|
377 |
-
# },
|
378 |
-
# "fields": "hidden"
|
379 |
-
# }
|
380 |
-
# },
|
381 |
-
# {
|
382 |
-
# "insertDimension": {
|
383 |
-
# "range": {
|
384 |
-
# "sheetId": sheet_id,
|
385 |
-
# "dimension": "ROWS",
|
386 |
-
# "startIndex": 1,
|
387 |
-
# "endIndex": no_of_rows + 1
|
388 |
-
# },
|
389 |
-
# "inheritFromBefore": False,
|
390 |
-
# }
|
391 |
-
# }]
|
392 |
-
|
393 |
-
|
394 |
-
# response = sheet_service.spreadsheets().batchUpdate(
|
395 |
-
# spreadsheetId=spreadsheet_id,
|
396 |
-
# body={
|
397 |
-
# 'requests': requests
|
398 |
-
# }
|
399 |
-
# ).execute()
|
400 |
-
|
401 |
-
# update_body = {
|
402 |
-
# 'values': data
|
403 |
-
# }
|
404 |
-
# start_column = 'A'
|
405 |
-
# end_column = chr(ord(start_column) + no_of_cols - 1)
|
406 |
-
# range_to_update = f'{sheet_name}!{start_column}2:{end_column}{no_of_rows + 1}'
|
407 |
-
|
408 |
-
# result = sheet_service.spreadsheets().values().update(
|
409 |
-
# spreadsheetId=spreadsheet_id,
|
410 |
-
# range=range_to_update,
|
411 |
-
# valueInputOption='USER_ENTERED',
|
412 |
-
# body=update_body
|
413 |
-
# ).execute()
|
414 |
-
|
415 |
-
# # Format the cells
|
416 |
-
# for row_index, row in enumerate(data):
|
417 |
-
# for col_index, cell_value in enumerate(row):
|
418 |
-
# if cell_value.startswith('=HYPERLINK'):
|
419 |
-
# color = {"red": 0, "green": 0, "blue": 1} # Blue for hyperlinks
|
420 |
-
# else:
|
421 |
-
# color = {"red": 0, "green": 0, "blue": 0} # Black for other text
|
422 |
-
|
423 |
-
# requests = [
|
424 |
-
# {
|
425 |
-
# "repeatCell": {
|
426 |
-
# "range": {
|
427 |
-
# "sheetId": sheet_id,
|
428 |
-
# "startRowIndex": row_index + 1,
|
429 |
-
# "endRowIndex": row_index + 2,
|
430 |
-
# "startColumnIndex": col_index,
|
431 |
-
# "endColumnIndex": col_index + 1
|
432 |
-
# },
|
433 |
-
# "cell": {
|
434 |
-
# "userEnteredFormat": {
|
435 |
-
# "textFormat": {
|
436 |
-
# "foregroundColor": color
|
437 |
-
# }
|
438 |
-
# }
|
439 |
-
# },
|
440 |
-
# "fields": "userEnteredFormat.textFormat.foregroundColor"
|
441 |
-
# }
|
442 |
-
# }
|
443 |
-
# ]
|
444 |
-
|
445 |
-
# response = sheet_service.spreadsheets().batchUpdate(
|
446 |
-
# spreadsheetId=spreadsheet_id,
|
447 |
-
# body={
|
448 |
-
# 'requests': requests
|
449 |
-
# }
|
450 |
-
# ).execute()
|
451 |
-
|
452 |
async def update_user_sheet(spreadsheet_id:str, sheet_name:str, data: List[List[str]], is_reset: Optional[bool] = False):
|
453 |
print(f"Spreadsheet ID: {spreadsheet_id}, Sheet Name: {sheet_name}, Data: {data}")
|
454 |
|
|
|
198 |
#Guideline
|
199 |
-strictly adhere to the given content of OCR text.
|
200 |
-it could be of receipt(s) or business card(s) but not both
|
201 |
+
-sort any other info that couldn't be classified as "๊ธฐํ"
|
202 |
+
-format the extracted information as a JSON object with two main keys: 'receipts' and 'busi_cards'.
|
203 |
+
-ensure the total number of receipts and business cards combined does not exceed 500.
|
204 |
+
|
205 |
|
206 |
#Example
|
207 |
##Receipts
|
|
|
246 |
2502230078357
|
247 |
|
248 |
Output
|
249 |
+
๋ฐํ์ผ: 2024/02/23 20:10
|
250 |
+
์ํธ: ์์ฑ๋ง์ผ
|
251 |
+
์ฌ์
์๋ฒํธ: 727-27-01455
|
252 |
+
ํฉ๊ณ๊ธ์ก: 2,800
|
253 |
+
๋ด์ญ:
|
254 |
๋ํ๋ฆฌ๋ฒ์ฏ 1,000์ 1๊ฐ
|
255 |
์๋ฐฐ์ถ 1,800์ 1๊ฐ
|
256 |
+
์นด๋๋ฒํธ: 4673-09**-****-515*
|
257 |
+
์นด๋์ข
๋ฅ: KB๊ตญ๋ฏผ์ฒดํฌ
|
258 |
+
์น์ธ๋ฒํธ: 30014507
|
259 |
+
๊ธฐํ: ๋ํ์: ํ์ ์ฑ, ์ฃผ์: ๊ฒฝ๊ธฐ ์ํฅ์ ๋ฐฐ๊ณง3๋ก 96, ์ ํ ๋ฒํธ: 031-431-1544, ๋ฉด์ธ๋ฌผํ: 2,800, ํฉ๊ณ: 2,800, ์ ์ฉ์นด๋์ง๋ถ:2,800, ์ ํNo:201036, ์ ์ถ VAN: JTNET-๋ฆฌ๋๊ธฐ, ๊ฑฐ๋NO:0223007835 ๊ณ์ฐ์: ๊ด๋ฆฌ์(001)
|
260 |
|
261 |
##Business Cards
|
262 |
Input
|
|
|
273 |
www.iprima.com
|
274 |
|
275 |
Output
|
276 |
+
์ด๋ฆ: ๋ฐ์ฅ์
|
277 |
+
ํ์ฌ๋ช
: ์์ดํ๋ฆฌ๋ง
|
278 |
+
์์ ๋ฐ ์ง์: ํ์ฅ/์ ์ฑ
์ฌ์
ํ R&D์ฌ์
์ค
|
279 |
+
์ฃผ์: ๊ฒฝ๊ธฐ๋ ํ์ฑ์ ์ ๋จ๋ฉด ๋ง๋
๋ก 98๋ฒ๊ธธ 55 (์ฐํธ๋ฒํธ) 18523
|
280 |
+
์ ํ: (031) 000-0000
|
281 |
+
ํด๋ํฐ: (031) 000-0000
|
282 |
+
ํฉ์ค: 010-0000-0000
|
283 |
+
e-mail: iprima@gmail.com
|
284 |
+
ํํ์ด์ง: www.iprima.com
|
285 |
+
๊ธฐํ: Over the MIRACLE
|
286 |
|
287 |
Image content: {extracted_text}
|
288 |
'''
|
|
|
346 |
except Exception as e:
|
347 |
logging.error(f"Failed to move file {file_id} to new folders: {e}")
|
348 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
349 |
async def update_user_sheet(spreadsheet_id:str, sheet_name:str, data: List[List[str]], is_reset: Optional[bool] = False):
|
350 |
print(f"Spreadsheet ID: {spreadsheet_id}, Sheet Name: {sheet_name}, Data: {data}")
|
351 |
|