GHarshasri commited on
Commit
1d11345
Β·
verified Β·
1 Parent(s): 2419b2c

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +18 -36
src/streamlit_app.py CHANGED
@@ -7,12 +7,10 @@ from datetime import datetime
7
 
8
  # ====== Setup ======
9
  USERS = {}
10
- # Use /tmp directory for Hugging Face Spaces, which is writable
11
  UPLOAD_FOLDER = "/tmp/uploads"
12
  MEDIA_FOLDER = os.path.join(UPLOAD_FOLDER, "feedback_media")
13
  FEEDBACK_FILE = os.path.join(UPLOAD_FOLDER, "feedback.csv")
14
 
15
- # Create directories if they don't exist
16
  os.makedirs(UPLOAD_FOLDER, exist_ok=True)
17
  os.makedirs(MEDIA_FOLDER, exist_ok=True)
18
 
@@ -28,13 +26,13 @@ STATES = {
28
  "Andhra Pradesh": ["Visakhapatnam", "Vijayawada", "Guntur", "Tirupati", "Kurnool"],
29
  }
30
 
31
- # ====== Session State Initialization ======
32
  for key, default in {
33
  "logged_in": False,
34
  "email": "",
35
  "otp_sent_to": None,
36
  "otp_verified": False,
37
  "login_email": None,
 
38
  }.items():
39
  if key not in st.session_state:
40
  st.session_state[key] = default
@@ -56,7 +54,7 @@ def verify_otp(entered_otp):
56
  return False
57
 
58
  def logout():
59
- for key in ["logged_in", "email", "otp_sent_to", "otp_verified", "login_email"]:
60
  st.session_state[key] = False if isinstance(st.session_state.get(key), bool) else None
61
 
62
  def fetch_wikipedia_summary(title, lang="en"):
@@ -137,7 +135,6 @@ def main_app():
137
  logout()
138
  st.experimental_rerun()
139
 
140
- # Feedback inputs on left sidebar
141
  st.sidebar.markdown("---")
142
  st.sidebar.subheader("πŸ“ Give Feedback")
143
  feedback_text = st.sidebar.text_area("Your thoughts about this place", height=100)
@@ -145,7 +142,6 @@ def main_app():
145
  feedback_audio = st.sidebar.file_uploader("Upload audio", type=["mp3", "wav", "m4a"])
146
  feedback_video = st.sidebar.file_uploader("Upload video", type=["mp4", "mov", "avi"])
147
 
148
- # Preview uploaded feedback files
149
  if feedback_image:
150
  st.sidebar.image(feedback_image, caption="Your uploaded image", use_container_width=True)
151
  if feedback_audio:
@@ -153,7 +149,6 @@ def main_app():
153
  if feedback_video:
154
  st.sidebar.video(feedback_video)
155
 
156
- # Main content
157
  st.title("πŸ“š Gyana Vedika - Cultural Explorer")
158
 
159
  state = st.selectbox("Select State", list(STATES.keys()))
@@ -161,35 +156,22 @@ def main_app():
161
  st.subheader(f"Explore {district}, {state}")
162
 
163
  uploaded_image = st.file_uploader("Upload a cultural/historical place image", type=["png", "jpg", "jpeg"])
164
- place_to_search = None
165
  if uploaded_image:
166
- st.image(uploaded_image, caption="Uploaded Image", use_container_width=True)
167
- filename = uploaded_image.name.lower()
 
 
 
 
 
168
  keywords_map = {
169
- # Telangana Places
170
- "charminar": "Charminar",
171
- "golconda": "Golconda Fort",
172
- "qutubshahi": "Qutb Shahi Tombs",
173
- "birla": "Birla Mandir",
174
- "salarjung": "Salar Jung Museum",
175
- "warangal": "Warangal Fort",
176
- "ramappa": "Ramappa Temple",
177
- "bhadrakali": "Bhadra Kali Temple",
178
- "kakatiya": "Kakatiya Kala Thoranam",
179
- "pakhal": "Pakhal Lake",
180
- "medak": "Medak Cathedral",
181
- "nagarjuna": "Nagarjuna Sagar Dam",
182
- # Other famous places (existing)
183
- "taj": "Taj Mahal",
184
- "gateway": "Gateway of India",
185
- "qutub": "Qutub Minar",
186
- "mysore": "Mysore Palace",
187
- "hampi": "Hampi",
188
- "konark": "Konark Sun Temple",
189
- "varanasi": "Varanasi",
190
- "madurai": "Meenakshi Temple",
191
- "ajanta": "Ajanta Caves",
192
- "ellora": "Ellora Caves",
193
  }
194
  for kw, place in keywords_map.items():
195
  if kw in filename:
@@ -235,7 +217,6 @@ def main_app():
235
 
236
  # ====== UI Styling ======
237
  st.set_page_config(page_title="Gyana Vedika", layout="wide")
238
-
239
  st.markdown("""
240
  <style>
241
  .stButton>button {
@@ -250,6 +231,7 @@ h1, h2, h3, h4, h5, h6 {
250
  </style>
251
  """, unsafe_allow_html=True)
252
 
 
253
  if not st.session_state.logged_in:
254
  page = st.sidebar.radio("Choose Option", ["Signup", "Login"])
255
  if page == "Signup":
@@ -257,4 +239,4 @@ if not st.session_state.logged_in:
257
  elif page == "Login":
258
  login_page()
259
  else:
260
- main_app()
 
7
 
8
  # ====== Setup ======
9
  USERS = {}
 
10
  UPLOAD_FOLDER = "/tmp/uploads"
11
  MEDIA_FOLDER = os.path.join(UPLOAD_FOLDER, "feedback_media")
12
  FEEDBACK_FILE = os.path.join(UPLOAD_FOLDER, "feedback.csv")
13
 
 
14
  os.makedirs(UPLOAD_FOLDER, exist_ok=True)
15
  os.makedirs(MEDIA_FOLDER, exist_ok=True)
16
 
 
26
  "Andhra Pradesh": ["Visakhapatnam", "Vijayawada", "Guntur", "Tirupati", "Kurnool"],
27
  }
28
 
 
29
  for key, default in {
30
  "logged_in": False,
31
  "email": "",
32
  "otp_sent_to": None,
33
  "otp_verified": False,
34
  "login_email": None,
35
+ "place_image": None,
36
  }.items():
37
  if key not in st.session_state:
38
  st.session_state[key] = default
 
54
  return False
55
 
56
  def logout():
57
+ for key in ["logged_in", "email", "otp_sent_to", "otp_verified", "login_email", "place_image"]:
58
  st.session_state[key] = False if isinstance(st.session_state.get(key), bool) else None
59
 
60
  def fetch_wikipedia_summary(title, lang="en"):
 
135
  logout()
136
  st.experimental_rerun()
137
 
 
138
  st.sidebar.markdown("---")
139
  st.sidebar.subheader("πŸ“ Give Feedback")
140
  feedback_text = st.sidebar.text_area("Your thoughts about this place", height=100)
 
142
  feedback_audio = st.sidebar.file_uploader("Upload audio", type=["mp3", "wav", "m4a"])
143
  feedback_video = st.sidebar.file_uploader("Upload video", type=["mp4", "mov", "avi"])
144
 
 
145
  if feedback_image:
146
  st.sidebar.image(feedback_image, caption="Your uploaded image", use_container_width=True)
147
  if feedback_audio:
 
149
  if feedback_video:
150
  st.sidebar.video(feedback_video)
151
 
 
152
  st.title("πŸ“š Gyana Vedika - Cultural Explorer")
153
 
154
  state = st.selectbox("Select State", list(STATES.keys()))
 
156
  st.subheader(f"Explore {district}, {state}")
157
 
158
  uploaded_image = st.file_uploader("Upload a cultural/historical place image", type=["png", "jpg", "jpeg"])
 
159
  if uploaded_image:
160
+ st.session_state["place_image"] = uploaded_image
161
+
162
+ place_to_search = None
163
+
164
+ if st.session_state["place_image"]:
165
+ st.image(st.session_state["place_image"], caption="Uploaded Image", use_container_width=True)
166
+ filename = st.session_state["place_image"].name.lower()
167
  keywords_map = {
168
+ "charminar": "Charminar", "golconda": "Golconda Fort", "qutubshahi": "Qutb Shahi Tombs",
169
+ "birla": "Birla Mandir", "salarjung": "Salar Jung Museum", "warangal": "Warangal Fort",
170
+ "ramappa": "Ramappa Temple", "bhadrakali": "Bhadra Kali Temple", "kakatiya": "Kakatiya Kala Thoranam",
171
+ "pakhal": "Pakhal Lake", "medak": "Medak Cathedral", "nagarjuna": "Nagarjuna Sagar Dam",
172
+ "taj": "Taj Mahal", "gateway": "Gateway of India", "qutub": "Qutub Minar", "mysore": "Mysore Palace",
173
+ "hampi": "Hampi", "konark": "Konark Sun Temple", "varanasi": "Varanasi", "madurai": "Meenakshi Temple",
174
+ "ajanta": "Ajanta Caves", "ellora": "Ellora Caves",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
  }
176
  for kw, place in keywords_map.items():
177
  if kw in filename:
 
217
 
218
  # ====== UI Styling ======
219
  st.set_page_config(page_title="Gyana Vedika", layout="wide")
 
220
  st.markdown("""
221
  <style>
222
  .stButton>button {
 
231
  </style>
232
  """, unsafe_allow_html=True)
233
 
234
+ # ====== Main Routing ======
235
  if not st.session_state.logged_in:
236
  page = st.sidebar.radio("Choose Option", ["Signup", "Login"])
237
  if page == "Signup":
 
239
  elif page == "Login":
240
  login_page()
241
  else:
242
+ main_app()