Spaces:
Running
Running
Commit
·
7a3eff7
1
Parent(s):
66ff8f7
added
Browse files
app.py
CHANGED
@@ -97,7 +97,7 @@ def extract_products(text):
|
|
97 |
|
98 |
def extract_with_perplexity_llm(ocr_text):
|
99 |
prompt = f"""
|
100 |
-
Extract the following fields from this receipt text and return them as a single flat JSON object:
|
101 |
- name (customer name)
|
102 |
- product (main product name)
|
103 |
- price (main product price)
|
@@ -221,16 +221,16 @@ def main():
|
|
221 |
with st.spinner("Extracting structured data with Perplexity LLM..."):
|
222 |
llm_result = extract_with_perplexity_llm(pytesseract.image_to_string(Image.open(temp_path)))
|
223 |
st.subheader("Structured Data (Perplexity LLM)")
|
224 |
-
st.
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
|
235 |
# Merge results
|
236 |
final_data = merge_extractions(fields, llm_data)
|
|
|
97 |
|
98 |
def extract_with_perplexity_llm(ocr_text):
|
99 |
prompt = f"""
|
100 |
+
Extract the following fields from this receipt text and return them as a single flat JSON object (not a list or nested object):
|
101 |
- name (customer name)
|
102 |
- product (main product name)
|
103 |
- price (main product price)
|
|
|
221 |
with st.spinner("Extracting structured data with Perplexity LLM..."):
|
222 |
llm_result = extract_with_perplexity_llm(pytesseract.image_to_string(Image.open(temp_path)))
|
223 |
st.subheader("Structured Data (Perplexity LLM)")
|
224 |
+
st.json(llm_result)
|
225 |
+
|
226 |
+
# Try to parse the JSON from the LLM output
|
227 |
+
llm_data = {}
|
228 |
+
try:
|
229 |
+
llm_json = extract_json_from_llm_output(llm_result)
|
230 |
+
if llm_json:
|
231 |
+
llm_data = json.loads(llm_json)
|
232 |
+
except Exception as e:
|
233 |
+
st.error(f"Failed to parse LLM output as JSON: {e}")
|
234 |
|
235 |
# Merge results
|
236 |
final_data = merge_extractions(fields, llm_data)
|