srisurya
commited on
Commit
·
1f4ca33
1
Parent(s):
724259f
Adding Sidebar
Browse files
app.py
CHANGED
|
@@ -22,10 +22,16 @@ def get_text(image_file, _model, _tokenizer):
|
|
| 22 |
|
| 23 |
@st.cache_data
|
| 24 |
def extract_text_easyocr(_image):
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
@st.cache_resource
|
| 31 |
def model():
|
|
@@ -58,6 +64,16 @@ def generate_unique_colors(n):
|
|
| 58 |
colors.append(color)
|
| 59 |
return colors
|
| 60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
st.title("A Web-Based Text Extraction and Retrieval System")
|
| 62 |
|
| 63 |
language = st.selectbox("Select a language:", ["English", "Hindi"])
|
|
|
|
| 22 |
|
| 23 |
@st.cache_data
|
| 24 |
def extract_text_easyocr(_image):
|
| 25 |
+
try:
|
| 26 |
+
reader = easyocr.Reader(['hi'], gpu=False)
|
| 27 |
+
if reader is None:
|
| 28 |
+
raise ValueError("Failed to create EasyOCR reader.")
|
| 29 |
+
results = reader.readtext(np.array(_image))
|
| 30 |
+
return " ".join([result[1] for result in results])
|
| 31 |
+
except Exception as e:
|
| 32 |
+
st.error(f"Error extracting text: {e}")
|
| 33 |
+
return ""
|
| 34 |
+
|
| 35 |
|
| 36 |
@st.cache_resource
|
| 37 |
def model():
|
|
|
|
| 64 |
colors.append(color)
|
| 65 |
return colors
|
| 66 |
|
| 67 |
+
|
| 68 |
+
with st.sidebar:
|
| 69 |
+
st.title("Instructions")
|
| 70 |
+
|
| 71 |
+
st.write("1. Choose a language(English or Hindi)")
|
| 72 |
+
st.write("2. Upload an image in JPG, PNG, or JPEG format.")
|
| 73 |
+
st.write("3. The app will extract text from the image using OCR.")
|
| 74 |
+
st.write("4. Enter keywords to search within the extracted text.")
|
| 75 |
+
st.write("5. If needed, click 'Reset' to upload a new image/change language.")
|
| 76 |
+
|
| 77 |
st.title("A Web-Based Text Extraction and Retrieval System")
|
| 78 |
|
| 79 |
language = st.selectbox("Select a language:", ["English", "Hindi"])
|