Rohanharsh163 commited on
Commit
91b376c
Β·
verified Β·
1 Parent(s): 3de4779

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +34 -11
src/streamlit_app.py CHANGED
@@ -1,6 +1,8 @@
1
  import streamlit as st
2
  from PIL import Image
3
  import requests
 
 
4
 
5
  st.set_page_config(page_title="WikiExplorer AR", layout="centered")
6
  st.title("πŸ“· WikiExplorer AR (Streamlit Edition)")
@@ -19,13 +21,38 @@ lang = st.selectbox(
19
 
20
  lang_code = lang[1]
21
 
22
- # --- Place name input ---
23
- st.markdown("**πŸ“ Enter a place or person name to learn more:**")
 
 
 
 
 
 
 
24
  place_name = st.text_input("πŸ›οΈ For example: Charminar, Taj Mahal, Shah Jahan")
25
 
26
  # --- Camera input ---
27
  img_file_buffer = st.camera_input("πŸ“Έ Take a picture (optional)")
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  # --- Translation helpers ---
30
  def translate_text(text, target_lang):
31
  try:
@@ -117,17 +144,13 @@ if place_name.strip():
117
  else:
118
  st.warning("No images found on Wikimedia Commons.")
119
 
120
- # --- Show captured image ---
121
- if img_file_buffer is not None:
122
- st.markdown("### πŸ“· Captured Image")
123
- st.image(img_file_buffer, caption="Uploaded via camera", use_column_width=True)
124
-
125
  # --- Footer ---
126
  st.markdown("""
127
  ---
128
  - πŸ“Œ Supports text search and camera input.
129
- - 🌐 Multilingual summaries using Wikipedia REST API with fallback + sentence-level translation.
130
- - πŸ–ΌοΈ Relevant Commons image gallery.
 
131
  - βœ… Ready for Hugging Face deployment.
132
- - πŸ› οΈ Built entirely with Streamlit, no backend needed.
133
- """)
 
1
  import streamlit as st
2
  from PIL import Image
3
  import requests
4
+ import easyocr
5
+ from io import BytesIO
6
 
7
  st.set_page_config(page_title="WikiExplorer AR", layout="centered")
8
  st.title("πŸ“· WikiExplorer AR (Streamlit Edition)")
 
21
 
22
  lang_code = lang[1]
23
 
24
+ # --- Load OCR Model ---
25
+ @st.cache_resource
26
+ def load_ocr_model():
27
+ return easyocr.Reader(['en']) # You can add 'hi', 'te', 'ta' for multilingual OCR
28
+
29
+ ocr_reader = load_ocr_model()
30
+
31
+ # --- Place name input (optional if image is provided) ---
32
+ st.markdown("**πŸ“ Enter a place or person name to learn more (or capture it):**")
33
  place_name = st.text_input("πŸ›οΈ For example: Charminar, Taj Mahal, Shah Jahan")
34
 
35
  # --- Camera input ---
36
  img_file_buffer = st.camera_input("πŸ“Έ Take a picture (optional)")
37
 
38
+ # --- OCR from camera image ---
39
+ if img_file_buffer is not None:
40
+ st.markdown("### πŸ“· Captured Image")
41
+ st.image(img_file_buffer, caption="Uploaded via camera", use_column_width=True)
42
+
43
+ image_bytes = BytesIO(img_file_buffer.getvalue())
44
+ result = ocr_reader.readtext(image_bytes)
45
+
46
+ if result:
47
+ detected_texts = [item[1] for item in result if item[1].strip()]
48
+ if detected_texts:
49
+ place_name = detected_texts[0] # Top detected phrase
50
+ st.success(f"🧠 OCR detected: **{place_name}**")
51
+ else:
52
+ st.warning("OCR ran but could not extract any meaningful text.")
53
+ else:
54
+ st.warning("Could not detect text in the image.")
55
+
56
  # --- Translation helpers ---
57
  def translate_text(text, target_lang):
58
  try:
 
144
  else:
145
  st.warning("No images found on Wikimedia Commons.")
146
 
 
 
 
 
 
147
  # --- Footer ---
148
  st.markdown("""
149
  ---
150
  - πŸ“Œ Supports text search and camera input.
151
+ - 🧠 OCR auto-detects place name from image.
152
+ - 🌐 Wikipedia multilingual summary with fallback + sentence-level translation.
153
+ - πŸ–ΌοΈ Commons image gallery integration.
154
  - βœ… Ready for Hugging Face deployment.
155
+ - πŸ› οΈ Streamlit only β€” no backend needed.
156
+ """)