Spaces:
Sleeping
Sleeping
Update extract_insights.py
Browse files- extract_insights.py +17 -18
extract_insights.py
CHANGED
|
@@ -53,7 +53,6 @@ def prompt_for_categorization(data):
|
|
| 53 |
"Activewear": [],
|
| 54 |
"Others": []
|
| 55 |
}
|
| 56 |
-
"item_value": "1,590.00"
|
| 57 |
},
|
| 58 |
|
| 59 |
{
|
|
@@ -66,7 +65,6 @@ def prompt_for_categorization(data):
|
|
| 66 |
"Activewear": [],
|
| 67 |
"Others": []
|
| 68 |
}
|
| 69 |
-
"item_value":"1,078.01"
|
| 70 |
}
|
| 71 |
}
|
| 72 |
"""
|
|
@@ -86,29 +84,30 @@ def prompt_for_categorization(data):
|
|
| 86 |
async def extract_fashion_categories(user_id:str , email:str, message_id:str):
|
| 87 |
|
| 88 |
|
| 89 |
-
response = supabase.table("document_ai_entities").select("line_item_description
|
| 90 |
print("printing response.data")
|
| 91 |
print(response.data)
|
| 92 |
|
| 93 |
items = response.data[0].get('line_item_description',None)
|
| 94 |
values = response.data[0].get('line_item_amount',None)
|
| 95 |
print("items",items)
|
| 96 |
-
print("values",values)
|
| 97 |
-
combined_json = combine_json_arrays(items,values)
|
| 98 |
-
print(combined_json)
|
| 99 |
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
|
|
|
| 112 |
# response = (
|
| 113 |
# supabase.table("document_ai_entities")
|
| 114 |
# .update({"categorised_data": completion.choices[0].message})
|
|
|
|
| 53 |
"Activewear": [],
|
| 54 |
"Others": []
|
| 55 |
}
|
|
|
|
| 56 |
},
|
| 57 |
|
| 58 |
{
|
|
|
|
| 65 |
"Activewear": [],
|
| 66 |
"Others": []
|
| 67 |
}
|
|
|
|
| 68 |
}
|
| 69 |
}
|
| 70 |
"""
|
|
|
|
| 84 |
async def extract_fashion_categories(user_id:str , email:str, message_id:str):
|
| 85 |
|
| 86 |
|
| 87 |
+
response = supabase.table("document_ai_entities").select("line_item_description").eq("user_id",user_id).eq("email",email).eq("message_id",message_id).execute()
|
| 88 |
print("printing response.data")
|
| 89 |
print(response.data)
|
| 90 |
|
| 91 |
items = response.data[0].get('line_item_description',None)
|
| 92 |
values = response.data[0].get('line_item_amount',None)
|
| 93 |
print("items",items)
|
| 94 |
+
# print("values",values)
|
| 95 |
+
# combined_json = combine_json_arrays(items,values)
|
| 96 |
+
# print(combined_json)
|
| 97 |
|
| 98 |
+
prompt = prompt_for_categorization(combined_json)
|
| 99 |
+
completion = client.chat.completions.create(
|
| 100 |
+
model="gpt-4o-mini",
|
| 101 |
+
messages=[
|
| 102 |
+
{
|
| 103 |
+
"role": "user",
|
| 104 |
+
"content": prompt
|
| 105 |
+
}
|
| 106 |
+
],
|
| 107 |
+
response_format={ "type": "json_object" }
|
| 108 |
+
)
|
| 109 |
+
print("Printing GPT response")
|
| 110 |
+
print(completion.choices[0].message)
|
| 111 |
# response = (
|
| 112 |
# supabase.table("document_ai_entities")
|
| 113 |
# .update({"categorised_data": completion.choices[0].message})
|