omdivyatej commited on
Commit
a7b12e1
1 Parent(s): 4f145f2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -26
app.py CHANGED
@@ -14,37 +14,19 @@ def process_file(files):
14
  response = ocr_request(file.name)
15
  response_arr.append(response)
16
 
17
- print("Main file :", response_arr)
18
-
19
- #i= [[{'invoice_number': '349136', 'product_description': '1ST FLOOR WALLS', 'predicted_material': 'Framing', 'confidence': 0.8}, {'invoice_number': '349136', 'product_description': "11.875 X 16 ' Pro Lam 2.0 LVL 1.75 ( 7 @ 16 ' , 4 @\n8 ' )", 'predicted_material': 'Framing', 'confidence': 0.9}, {'invoice_number': '349136', 'product_description': "COLUMN\n11.875 X 10 ' Pro Lam 2.0 LVL 1.75", 'predicted_material': 'Framing', 'confidence': 0.9}, {'invoice_number': '3495565136', 'product_description': "Power Column 3 1/2 X 5 1/2 - 08 '", 'predicted_material': 'Framing', 'confidence': 0.9}],[{'invoice_number': '349136', 'product_description': ' FLOOR WALLS', 'predicted_material': 'Framing', 'confidence': 0.8}, {'invoice_number': '349136', 'product_description': "11.875 X 16 ' Pro Lam 2.0 LVL 1.75 ( 7 @ 16 ' , 4 @\n8 ' )", 'predicted_material': 'Framing', 'confidence': 0.9}, {'invoice_number': '349136', 'product_description': "COLUMN\n11.875 X 10 ' Pro Lam 2.0 LVL 1.75", 'predicted_material': 'Framing', 'confidence': 0.9}, {'invoice_number': '349136', 'product_description': "Power Column 3 1/2 X 5 1/2 - 08 '", 'predicted_material': 'Framing', 'confidence': 0.9}]]
20
- # flat_list = []
21
-
22
- # for item in response_arr:
23
- # invoice_number = item['invoice_number']
24
-
25
- # # Extracting product descriptions
26
- # products = item.get('predictions', []) or item.get('product_description', [])
27
-
28
- # for product in products:
29
- # # Rename 'description' key to 'product_description' for uniformity across all products
30
- # product_description = product.get('product_description', product.get('description'))
31
- # predicted_material = product['predicted_material']
32
- # confidence = product['confidence']
33
-
34
- # flat_list.append({
35
- # 'invoice_number': invoice_number,
36
- # 'product_description': product_description,
37
- # 'predicted_material': predicted_material,
38
- # 'confidence': confidence
39
- # })
40
-
41
  load_dotenv()
42
  # Initialize OpenAI with your API key
43
  openai.api_key = os.getenv("OPENAI_API_KEY")
44
 
45
  prompt =f"""
46
- you are an excellent programmer and an anlyst. Given a json array or a json, you need to analyse it and convert into a json format which can be converted in dataframe of pandas easily. You have a singular task :
47
- Once you have thought through, produce a json, easily convertible to a dataframe in python, which would contain invoice number, product description, predicted material, confidence. Remember: You just have to share the o/p json, no thought process or anything else.
 
 
 
 
48
 
49
  Here is the json array/json : {json.dumps(response_arr)}
50
  """
 
14
  response = ocr_request(file.name)
15
  response_arr.append(response)
16
 
17
+ print("Main file :", response_arr)
18
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  load_dotenv()
20
  # Initialize OpenAI with your API key
21
  openai.api_key = os.getenv("OPENAI_API_KEY")
22
 
23
  prompt =f"""
24
+ you are an excellent programmer and an anlyst. Given a json array or a json, you need to analyse it and convert into a json format which can be converted in dataframe of pandas easily.
25
+ You have a singular task :
26
+ Once you have thought through, produce a json, easily convertible to a dataframe in python, which would contain invoice number, product description, predicted material, confidence.
27
+ Remember:You just have to share the output json, NO thought process or extra words or anything else.
28
+ If it is a nested structure, flatten it. ONLY JSON should be in the output, not json within a list.
29
+
30
 
31
  Here is the json array/json : {json.dumps(response_arr)}
32
  """