GHarshasri commited on
Commit
b9b85bf
Β·
verified Β·
1 Parent(s): f90c777

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +87 -17
src/streamlit_app.py CHANGED
@@ -6,18 +6,14 @@ import csv
6
  from datetime import datetime
7
 
8
  # ====== Setup ======
9
- if "_temp_dir" not in st.session_state:
10
- st.session_state["_temp_dir"] = "/tmp"
11
-
12
- UPLOAD_FOLDER = os.path.join(st.session_state["_temp_dir"], "uploads")
13
  MEDIA_FOLDER = os.path.join(UPLOAD_FOLDER, "feedback_media")
14
  FEEDBACK_FILE = os.path.join(UPLOAD_FOLDER, "feedback.csv")
15
 
16
- # Ensure folders exist
17
  os.makedirs(MEDIA_FOLDER, exist_ok=True)
18
 
19
- USERS = {}
20
-
21
  STATES = {
22
  "Telangana": ["Hyderabad", "Warangal", "Nizamabad", "Karimnagar", "Khammam"],
23
  "Maharashtra": ["Mumbai", "Pune", "Nagpur", "Nashik", "Aurangabad"],
@@ -42,6 +38,7 @@ for key, default in {
42
  st.session_state[key] = default
43
 
44
  # ====== Helper Functions ======
 
45
  def send_otp(email):
46
  st.session_state.otp_sent_to = email
47
  st.session_state.otp_verified = False
@@ -88,6 +85,7 @@ def save_feedback(email, place, state, district, text, img_path="", audio_path="
88
  "user_email", "place_name", "state", "district", "feedback_text",
89
  "image_file", "audio_file", "video_file", "timestamp"
90
  ])
 
91
  with open(FEEDBACK_FILE, 'a', newline='', encoding='utf-8') as f:
92
  writer = csv.writer(f)
93
  writer.writerow([
@@ -96,6 +94,7 @@ def save_feedback(email, place, state, district, text, img_path="", audio_path="
96
  ])
97
 
98
  # ====== Pages ======
 
99
  def signup_page():
100
  st.header("πŸš€ Signup")
101
  name = st.text_input("Name")
@@ -136,7 +135,7 @@ def main_app():
136
  logout()
137
  st.experimental_rerun()
138
 
139
- # Feedback Form
140
  st.sidebar.markdown("---")
141
  st.sidebar.subheader("πŸ“ Give Feedback")
142
  feedback_text = st.sidebar.text_area("Your thoughts about this place", height=100)
@@ -144,6 +143,7 @@ def main_app():
144
  feedback_audio = st.sidebar.file_uploader("Upload audio", type=["mp3", "wav", "m4a"])
145
  feedback_video = st.sidebar.file_uploader("Upload video", type=["mp4", "mov", "avi"])
146
 
 
147
  if feedback_image:
148
  st.sidebar.image(feedback_image, caption="Your uploaded image", use_container_width=True)
149
  if feedback_audio:
@@ -151,6 +151,7 @@ def main_app():
151
  if feedback_video:
152
  st.sidebar.video(feedback_video)
153
 
 
154
  st.title("πŸ“š Gyana Vedika - Cultural Explorer")
155
 
156
  state = st.selectbox("Select State", list(STATES.keys()))
@@ -159,18 +160,34 @@ def main_app():
159
 
160
  uploaded_image = st.file_uploader("Upload a cultural/historical place image", type=["png", "jpg", "jpeg"])
161
  place_to_search = None
162
-
163
  if uploaded_image:
164
  st.image(uploaded_image, caption="Uploaded Image", use_container_width=True)
165
  filename = uploaded_image.name.lower()
166
  keywords_map = {
167
- "charminar": "Charminar", "golconda": "Golconda Fort", "qutubshahi": "Qutb Shahi Tombs",
168
- "birla": "Birla Mandir", "salarjung": "Salar Jung Museum", "warangal": "Warangal Fort",
169
- "ramappa": "Ramappa Temple", "bhadrakali": "Bhadra Kali Temple", "kakatiya": "Kakatiya Kala Thoranam",
170
- "pakhal": "Pakhal Lake", "medak": "Medak Cathedral", "nagarjuna": "Nagarjuna Sagar Dam",
171
- "taj": "Taj Mahal", "gateway": "Gateway of India", "qutub": "Qutub Minar",
172
- "mysore": "Mysore Palace", "hampi": "Hampi", "konark": "Konark Sun Temple",
173
- "varanasi": "Varanasi", "madurai": "Meenakshi Temple", "ajanta": "Ajanta Caves", "ellora": "Ellora Caves",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
174
  }
175
  for kw, place in keywords_map.items():
176
  if kw in filename:
@@ -185,4 +202,57 @@ def main_app():
185
  place_to_search = manual_place.strip()
186
 
187
  if place_to_search:
188
- language = st.selectbox("Select Wikipedia summary language", ["English", "Hindi", "Telugu", "Tamil
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  from datetime import datetime
7
 
8
  # ====== Setup ======
9
+ USERS = {}
10
+ UPLOAD_FOLDER = "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
 
 
 
17
  STATES = {
18
  "Telangana": ["Hyderabad", "Warangal", "Nizamabad", "Karimnagar", "Khammam"],
19
  "Maharashtra": ["Mumbai", "Pune", "Nagpur", "Nashik", "Aurangabad"],
 
38
  st.session_state[key] = default
39
 
40
  # ====== Helper Functions ======
41
+
42
  def send_otp(email):
43
  st.session_state.otp_sent_to = email
44
  st.session_state.otp_verified = False
 
85
  "user_email", "place_name", "state", "district", "feedback_text",
86
  "image_file", "audio_file", "video_file", "timestamp"
87
  ])
88
+
89
  with open(FEEDBACK_FILE, 'a', newline='', encoding='utf-8') as f:
90
  writer = csv.writer(f)
91
  writer.writerow([
 
94
  ])
95
 
96
  # ====== Pages ======
97
+
98
  def signup_page():
99
  st.header("πŸš€ Signup")
100
  name = st.text_input("Name")
 
135
  logout()
136
  st.experimental_rerun()
137
 
138
+ # Feedback inputs on left sidebar
139
  st.sidebar.markdown("---")
140
  st.sidebar.subheader("πŸ“ Give Feedback")
141
  feedback_text = st.sidebar.text_area("Your thoughts about this place", height=100)
 
143
  feedback_audio = st.sidebar.file_uploader("Upload audio", type=["mp3", "wav", "m4a"])
144
  feedback_video = st.sidebar.file_uploader("Upload video", type=["mp4", "mov", "avi"])
145
 
146
+ # Preview uploaded feedback files
147
  if feedback_image:
148
  st.sidebar.image(feedback_image, caption="Your uploaded image", use_container_width=True)
149
  if feedback_audio:
 
151
  if feedback_video:
152
  st.sidebar.video(feedback_video)
153
 
154
+ # Main content
155
  st.title("πŸ“š Gyana Vedika - Cultural Explorer")
156
 
157
  state = st.selectbox("Select State", list(STATES.keys()))
 
160
 
161
  uploaded_image = st.file_uploader("Upload a cultural/historical place image", type=["png", "jpg", "jpeg"])
162
  place_to_search = None
 
163
  if uploaded_image:
164
  st.image(uploaded_image, caption="Uploaded Image", use_container_width=True)
165
  filename = uploaded_image.name.lower()
166
  keywords_map = {
167
+ # Telangana Places
168
+ "charminar": "Charminar",
169
+ "golconda": "Golconda Fort",
170
+ "qutubshahi": "Qutb Shahi Tombs",
171
+ "birla": "Birla Mandir",
172
+ "salarjung": "Salar Jung Museum",
173
+ "warangal": "Warangal Fort",
174
+ "ramappa": "Ramappa Temple",
175
+ "bhadrakali": "Bhadra Kali Temple",
176
+ "kakatiya": "Kakatiya Kala Thoranam",
177
+ "pakhal": "Pakhal Lake",
178
+ "medak": "Medak Cathedral",
179
+ "nagarjuna": "Nagarjuna Sagar Dam",
180
+ # Other famous places (existing)
181
+ "taj": "Taj Mahal",
182
+ "gateway": "Gateway of India",
183
+ "qutub": "Qutub Minar",
184
+ "mysore": "Mysore Palace",
185
+ "hampi": "Hampi",
186
+ "konark": "Konark Sun Temple",
187
+ "varanasi": "Varanasi",
188
+ "madurai": "Meenakshi Temple",
189
+ "ajanta": "Ajanta Caves",
190
+ "ellora": "Ellora Caves",
191
  }
192
  for kw, place in keywords_map.items():
193
  if kw in filename:
 
202
  place_to_search = manual_place.strip()
203
 
204
  if place_to_search:
205
+ language = st.selectbox("Select Wikipedia summary language", ["English", "Hindi", "Telugu", "Tamil", "Marathi", "Bengali"])
206
+ lang_codes = {"English": "en", "Hindi": "hi", "Telugu": "te", "Tamil": "ta", "Marathi": "mr", "Bengali": "bn"}
207
+ lang_code = lang_codes.get(language, "en")
208
+ if st.button(f"Get info about {place_to_search}"):
209
+ with st.spinner(f"Fetching Wikipedia summary for {place_to_search}..."):
210
+ summary = fetch_wikipedia_summary(place_to_search, lang=lang_code)
211
+ st.markdown(f"### Summary of {place_to_search}")
212
+ st.write(summary)
213
+
214
+ if st.sidebar.button("Submit Feedback"):
215
+ if feedback_text.strip():
216
+ img_path = save_temp_file(feedback_image, "img")
217
+ audio_path = save_temp_file(feedback_audio, "audio")
218
+ video_path = save_temp_file(feedback_video, "video")
219
+
220
+ save_feedback(
221
+ email=st.session_state.email,
222
+ place=place_to_search or "Unknown",
223
+ state=state,
224
+ district=district,
225
+ text=feedback_text.strip(),
226
+ img_path=img_path,
227
+ audio_path=audio_path,
228
+ video_path=video_path
229
+ )
230
+ st.sidebar.success("Thank you! Feedback submitted.")
231
+ else:
232
+ st.sidebar.warning("Please enter your feedback text.")
233
+
234
+ # ====== UI Styling ======
235
+ st.set_page_config(page_title="Gyana Vedika", layout="wide")
236
+
237
+ st.markdown("""
238
+ <style>
239
+ .stButton>button {
240
+ background-color: #008080; color: white; font-weight: bold; border-radius: 10px;
241
+ }
242
+ .stTextInput>div>input, .stSelectbox>div>div>select, .stTextArea>div>textarea {
243
+ border: 2px solid #008080 !important; border-radius: 8px !important;
244
+ }
245
+ h1, h2, h3, h4, h5, h6 {
246
+ color: #004d4d;
247
+ }
248
+ </style>
249
+ """, unsafe_allow_html=True)
250
+
251
+ if not st.session_state.logged_in:
252
+ page = st.sidebar.radio("Choose Option", ["Signup", "Login"])
253
+ if page == "Signup":
254
+ signup_page()
255
+ elif page == "Login":
256
+ login_page()
257
+ else:
258
+ main_app()