Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,5 @@
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
from ocr_cpu import extract_text_got, clean_text_with_ai # Import OCR and AI cleaning functions
|
3 |
import json
|
@@ -45,20 +47,25 @@ if uploaded_file is not None:
|
|
45 |
extracted_text = extract_text_got(uploaded_file) # Use GOT OCR to extract text
|
46 |
if not extracted_text.strip():
|
47 |
st.warning("No text extracted from the image.")
|
|
|
48 |
else:
|
49 |
# Clean the extracted text using AI
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
52 |
except Exception as e:
|
53 |
st.error(f"Error during text extraction: {str(e)}")
|
54 |
extracted_text = cleaned_text = ""
|
55 |
|
56 |
# Display cleaned text
|
57 |
-
|
58 |
-
|
|
|
59 |
|
60 |
-
|
61 |
-
if cleaned_text:
|
62 |
with open("extracted_text.json", "w") as json_file:
|
63 |
json.dump({"text": cleaned_text}, json_file)
|
64 |
|
|
|
1 |
+
# app.py
|
2 |
+
|
3 |
import streamlit as st
|
4 |
from ocr_cpu import extract_text_got, clean_text_with_ai # Import OCR and AI cleaning functions
|
5 |
import json
|
|
|
47 |
extracted_text = extract_text_got(uploaded_file) # Use GOT OCR to extract text
|
48 |
if not extracted_text.strip():
|
49 |
st.warning("No text extracted from the image.")
|
50 |
+
cleaned_text = ""
|
51 |
else:
|
52 |
# Clean the extracted text using AI
|
53 |
+
with st.spinner("Cleaning the extracted text using AI..."):
|
54 |
+
cleaned_text = clean_text_with_ai(extracted_text)
|
55 |
+
if cleaned_text.startswith("Error"):
|
56 |
+
st.error(cleaned_text)
|
57 |
+
else:
|
58 |
+
st.success("Text extraction and cleaning successful.")
|
59 |
except Exception as e:
|
60 |
st.error(f"Error during text extraction: {str(e)}")
|
61 |
extracted_text = cleaned_text = ""
|
62 |
|
63 |
# Display cleaned text
|
64 |
+
if cleaned_text and not cleaned_text.startswith("Error"):
|
65 |
+
st.subheader("Cleaned Extracted Text")
|
66 |
+
st.text_area("Cleaned Text", cleaned_text, height=250)
|
67 |
|
68 |
+
# Save cleaned text for search
|
|
|
69 |
with open("extracted_text.json", "w") as json_file:
|
70 |
json.dump({"text": cleaned_text}, json_file)
|
71 |
|