Spaces:
Runtime error
Runtime error
RufusRubin777
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -53,24 +53,26 @@ def ocr_and_search(image, keyword):
|
|
53 |
|
54 |
# Save extracted text to JSON
|
55 |
output_json = {"query": text_query, "extracted_text": extracted_text}
|
56 |
-
json_output = json.dumps(output_json, ensure_ascii=False, indent=4)
|
57 |
|
58 |
# Perform keyword search
|
59 |
keyword_lower = keyword.lower()
|
60 |
sentences = extracted_text.split('. ')
|
61 |
matched_sentences = [sentence for sentence in sentences if keyword_lower in sentence.lower()]
|
62 |
|
63 |
-
return extracted_text, matched_sentences
|
64 |
|
65 |
|
66 |
# Gradio App
|
67 |
def app(image, keyword):
|
68 |
|
69 |
-
extracted_text, search_results, json_output = ocr_and_search(image, keyword)
|
|
|
|
|
70 |
|
71 |
search_results_str = "\n".join(search_results) if search_results else "No matches found."
|
72 |
|
73 |
-
return extracted_text, search_results_str
|
74 |
|
75 |
# Gradio Interface
|
76 |
iface = gr.Interface(
|
@@ -82,7 +84,7 @@ iface = gr.Interface(
|
|
82 |
outputs=[
|
83 |
gr.Textbox(label="Extracted Text"),
|
84 |
gr.Textbox(label="Search Results"),
|
85 |
-
gr.JSON(label="JSON Output")
|
86 |
],
|
87 |
title="OCR and Keyword Search in Images",
|
88 |
)
|
|
|
53 |
|
54 |
# Save extracted text to JSON
|
55 |
output_json = {"query": text_query, "extracted_text": extracted_text}
|
56 |
+
# json_output = json.dumps(output_json, ensure_ascii=False, indent=4)
|
57 |
|
58 |
# Perform keyword search
|
59 |
keyword_lower = keyword.lower()
|
60 |
sentences = extracted_text.split('. ')
|
61 |
matched_sentences = [sentence for sentence in sentences if keyword_lower in sentence.lower()]
|
62 |
|
63 |
+
return extracted_text, matched_sentences #, json_output
|
64 |
|
65 |
|
66 |
# Gradio App
|
67 |
def app(image, keyword):
|
68 |
|
69 |
+
# extracted_text, search_results, json_output = ocr_and_search(image, keyword)
|
70 |
+
|
71 |
+
extracted_text, search_results = ocr_and_search(image, keyword)
|
72 |
|
73 |
search_results_str = "\n".join(search_results) if search_results else "No matches found."
|
74 |
|
75 |
+
return extracted_text, search_results_str #, json_output
|
76 |
|
77 |
# Gradio Interface
|
78 |
iface = gr.Interface(
|
|
|
84 |
outputs=[
|
85 |
gr.Textbox(label="Extracted Text"),
|
86 |
gr.Textbox(label="Search Results"),
|
87 |
+
# gr.JSON(label="JSON Output")
|
88 |
],
|
89 |
title="OCR and Keyword Search in Images",
|
90 |
)
|