gamingflexer commited on
Commit
f74a64b
1 Parent(s): cd5296d

Refactor get_details function to handle multiple image paths

Browse files
src/app/api/module/product_description.py CHANGED
@@ -5,12 +5,17 @@ from api.module.utils import extract_json_from_text
5
  # from vectorsearch import search , get_detail_df
6
  import json
7
 
8
- def get_details(image_path):
9
- details = azure_ocr(image_path)
10
- prompt = base_prompt.format(text = details)
 
 
 
 
11
  # print(prompt)
12
  obj = OpenAIVision()
13
- jsontext = obj.get_image_description(image_path,prompt)
 
14
  response = extract_json_from_text(jsontext['choices'][0]['message']['content'])
15
  return response
16
 
 
5
  # from vectorsearch import search , get_detail_df
6
  import json
7
 
8
+ def get_details(image_path_list):
9
+ total_ocr = ""
10
+ for image_path in image_path_list:
11
+ details = azure_ocr(image_path)
12
+ total_ocr += details
13
+ print(total_ocr)
14
+ prompt = base_prompt.format(text = total_ocr)
15
  # print(prompt)
16
  obj = OpenAIVision()
17
+ if len(image_path_list) > 1:
18
+ jsontext = obj.get_image_description(image_path_list[0],prompt)
19
  response = extract_json_from_text(jsontext['choices'][0]['message']['content'])
20
  return response
21
 
src/app/api/module/prompts/base.py CHANGED
@@ -16,11 +16,10 @@ base_prompt = dedent("""
16
 
17
  "brand": "sample_brand",
18
  "mrp": "The price might start with MRP or Rs.",
 
19
  "unit": "per pack",
20
- "Quantity": 1, ##num of products visible
21
  "parent_category": "from the above given list",
22
- "ingredients": ["ingredient1", "ingredient2", "ingredient3"],
23
- "calorie_count": "Would be in numbers",
24
  "marketed_by": "sample_marketer",
25
  "manufactured_by": "sample_manufacturer",
26
  "manufactured_in_country": "Country XYZ",
@@ -28,8 +27,9 @@ base_prompt = dedent("""
28
  "promotion_on_the_pack": "if any",
29
  "type_of_product": "give this your understanding",
30
  "pack_of_or_no_of_units": "No. of Units"
31
-
32
-
 
33
  Analyse data from the above product description to give me the following details in JSON format:
34
  Only return the output in the required json format.
35
  """)
 
16
 
17
  "brand": "sample_brand",
18
  "mrp": "The price might start with MRP or Rs.",
19
+ "price": "The price might start with MRP or Rs.",
20
  "unit": "per pack",
21
+ "Quantity": 1, ## num of products visible in the image
22
  "parent_category": "from the above given list",
 
 
23
  "marketed_by": "sample_marketer",
24
  "manufactured_by": "sample_manufacturer",
25
  "manufactured_in_country": "Country XYZ",
 
27
  "promotion_on_the_pack": "if any",
28
  "type_of_product": "give this your understanding",
29
  "pack_of_or_no_of_units": "No. of Units"
30
+ "description" : "Generate a description of the product"
31
+ "weight" : "If the weight is mentioned in the Image or OCR Text"
32
+
33
  Analyse data from the above product description to give me the following details in JSON format:
34
  Only return the output in the required json format.
35
  """)
src/app2.py CHANGED
@@ -72,7 +72,7 @@ def sample_fun(voice_input, product_id, progress=gr.Progress()):
72
 
73
  with gr.Blocks(theme=gr.themes.Default(primary_hue=gr.themes.colors.red, secondary_hue=gr.themes.colors.pink),title = "Edit Product by Voice") as demo:
74
 
75
- with gr.Tab("Add Your Image"):
76
  voice_input = gr.Audio(sources=["microphone"])
77
  prodcut_id = gr.Textbox(label="Enter Product ID")
78
  with gr.Row():
 
72
 
73
  with gr.Blocks(theme=gr.themes.Default(primary_hue=gr.themes.colors.red, secondary_hue=gr.themes.colors.pink),title = "Edit Product by Voice") as demo:
74
 
75
+ with gr.Tab("Edit Product by Voice"):
76
  voice_input = gr.Audio(sources=["microphone"])
77
  prodcut_id = gr.Textbox(label="Enter Product ID")
78
  with gr.Row():