m8chaa commited on
Commit
05713b0
ยท
verified ยท
1 Parent(s): 257f6c2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -25
app.py CHANGED
@@ -184,34 +184,52 @@ async def request_gpt4o_completion(image_id: str, user_credit: int, use_gpt4: bo
184
  messages=[
185
  {
186
  "role": "system",
187
- "content": """You are an employee of finance department of a company. Your task is to extract information from receipts and business cards and format it precisely according to these rules:
188
- - Strictly adhere to the given content of OCR text
189
- - It could be of receipt(s) or business card(s) but not both
190
- - For business cards, extract and format EXACTLY in this order:
191
- ์ด๋ฆ„, ํšŒ์‚ฌ๋ช…, ์†Œ์† ๋ฐ ์ง์œ„, ์ฃผ์†Œ, ์ „ํ™”, ํœด๋Œ€ํฐ, ํŒฉ์Šค, e-mail, ํ™ˆํŽ˜์ด์ง€
192
- - For receipts, extract and format EXACTLY in this order:
193
- ๋ฐœํ–‰์ผ, ์ƒํ˜ธ, ์‚ฌ์—…์ž๋ฒˆํ˜ธ (in format: ###-##-#####), ํ•ฉ๊ณ„๊ธˆ์•ก, ๋‚ด์—ญ (item name price quantity), ์นด๋“œ๋ฒˆํ˜ธ, ์นด๋“œ์ข…๋ฅ˜, ์Šน์ธ๋ฒˆํ˜ธ, ๊ธฐํƒ€ (all remaining information)
194
- - Format as JSON with two arrays: "receipts" and "busi_cards"
195
- - For business cards, ensure phone numbers are formatted with hyphens (e.g., 010-0000-0000)
196
- - For addresses with postal codes, format as: "์ฃผ์†Œ (์šฐํŽธ๋ฒˆํ˜ธ) ์ฝ”๋“œ"
197
- - Do not add any additional fields or information not present in the original text
198
- Example receipt format:
199
- {
200
- "๋ฐœํ–‰์ผ": "3/6/2024 15:31:00",
201
- "์ƒํ˜ธ": "์‹œํฅ๋ฐฐ๊ณง๋™์šฐ์ฒด๊ตญ",
202
- "์‚ฌ์—…์ž๋ฒˆํ˜ธ": "101-83-02925",
203
- "ํ•ฉ๊ณ„๊ธˆ์•ก": "4,300",
204
- "๋‚ด์—ญ": "๋ณดํ†ต 7g 10ํ†ต 430 4,300",
205
- "์นด๋“œ๋ฒˆํ˜ธ": "5286-6420-****-077",
206
- "์นด๋“œ์ข…๋ฅ˜": "NH๊ธฐ์—…์ฒดํฌ",
207
- "์Šน์ธ๋ฒˆํ˜ธ": "49980444",
208
- "๊ธฐํƒ€": "์ „ํ™”: 031-8042-2047, ์ฃผ์†Œ: ๊ฒฝ๊ธฐ๋„ ์‹œํฅ์‹œ ์ •์™•๋™ 2543, ๊ณ ๊ฐ๋ฌธ์˜ ์ „ํ™”: 1588-1300, ..."
209
- }"""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
210
  },
211
  {
212
  "role": "user",
213
  "content": [
214
- {"type": "text", "text": "Please analyze this image and extract the information according to the rules."},
215
  {
216
  "type": "image_url",
217
  "image_url": {
@@ -723,7 +741,7 @@ async def update_user_sheets_and_folders(user_data, transaction_ref, transaction
723
  business_card_sheet_headers,
724
  add_link=True,
725
  image_id=image_id,
726
- link_text="๋ช…ํ•จ๋ณด๊ธฐ",
727
  link_position=-1 # Link at the end
728
  )
729
  await update_user_sheet(user_data['gDrive_metadata']['spreadsheet'], "๋ช…ํ•จ", business_cards_data)
 
184
  messages=[
185
  {
186
  "role": "system",
187
+ "content": """You are a receipt and business card data extractor. Extract information EXACTLY in the specified format.
188
+
189
+ For receipts, follow this EXACT format and order:
190
+ 1. "๋ฐœํ–‰์ผ": Must be in format "M/D/YYYY HH:MM:SS"
191
+ 2. "์ƒํ˜ธ": Store/business name only
192
+ 3. "์‚ฌ์—…์ž๋ฒˆํ˜ธ": Must be in format "###-##-#####" (if present)
193
+ 4. "ํ•ฉ๊ณ„๊ธˆ์•ก": Total amount with comma for thousands (e.g., "4,300")
194
+ 5. "๋‚ด์—ญ": List items with format "item price quantity" (e.g., "๋ณดํ†ต 7g 10ํ†ต 430 4,300")
195
+ 6. "์นด๋“œ๋ฒˆํ˜ธ": Must include asterisks for hidden numbers (e.g., "5286-6420-****-077")
196
+ 7. "์นด๋“œ์ข…๋ฅ˜": Card type only
197
+ 8. "์Šน์ธ๋ฒˆํ˜ธ": Approval number only
198
+ 9. "๊ธฐํƒ€": All remaining information as key-value pairs separated by commas
199
+
200
+ Example receipt:
201
+ {
202
+ "receipts": [{
203
+ "๋ฐœํ–‰์ผ": "3/6/2024 15:31:00",
204
+ "์ƒํ˜ธ": "์‹œํฅ๋ฐฐ๊ณง๋™์šฐ์ฒด๊ตญ",
205
+ "์‚ฌ์—…์ž๋ฒˆํ˜ธ": "101-83-02925",
206
+ "ํ•ฉ๊ณ„๊ธˆ์•ก": "4,300",
207
+ "๋‚ด์—ญ": "๋ณดํ†ต 7g 10ํ†ต 430 4,300",
208
+ "์นด๋“œ๋ฒˆํ˜ธ": "5286-6420-****-077",
209
+ "์นด๋“œ์ข…๋ฅ˜": "NH๊ธฐ์—…์ฒดํฌ",
210
+ "์Šน์ธ๋ฒˆํ˜ธ": "49980444",
211
+ "๊ธฐํƒ€": "์ „ํ™”: 031-8042-2047, ์ฃผ์†Œ: ๊ฒฝ๊ธฐ๋„ ์‹œํฅ์‹œ ์ •์™•๋™ 2543, ๊ณ ๊ฐ๋ฌธ์˜ ์ „ํ™”: 1588-1300"
212
+ }],
213
+ "busi_cards": []
214
+ }
215
+
216
+ For business cards, follow this EXACT format and order:
217
+ 1. "์ด๋ฆ„": Full name
218
+ 2. "ํšŒ์‚ฌ๋ช…": Company name
219
+ 3. "์†Œ์† ๋ฐ ์ง์œ„": Position and department
220
+ 4. "์ฃผ์†Œ": Address with postal code in format "์ฃผ์†Œ (์šฐํŽธ๋ฒˆํ˜ธ) ์ฝ”๋“œ"
221
+ 5. "์ „ํ™”": Office phone with hyphens
222
+ 6. "ํœด๋Œ€ํฐ": Mobile with hyphens (e.g., "010-0000-0000")
223
+ 7. "ํŒฉ์Šค": Fax number with hyphens
224
+ 8. "e-mail": Email address
225
+ 9. "ํ™ˆํŽ˜์ด์ง€": Website URL
226
+
227
+ Output must be valid JSON with "receipts" and "busi_cards" arrays."""
228
  },
229
  {
230
  "role": "user",
231
  "content": [
232
+ {"type": "text", "text": "Extract the information from this image following the exact format specified."},
233
  {
234
  "type": "image_url",
235
  "image_url": {
 
741
  business_card_sheet_headers,
742
  add_link=True,
743
  image_id=image_id,
744
+ link_text="๋ช…๏ฟฝ๏ฟฝ๏ฟฝ๋ณด๊ธฐ",
745
  link_position=-1 # Link at the end
746
  )
747
  await update_user_sheet(user_data['gDrive_metadata']['spreadsheet'], "๋ช…ํ•จ", business_cards_data)