GHarshasri commited on
Commit
7259cb7
Β·
verified Β·
1 Parent(s): 1569d36

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +191 -13
src/streamlit_app.py CHANGED
@@ -1,3 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  def main_app():
2
  st.sidebar.success(f"Logged in as {st.session_state.email}")
3
  if st.sidebar.button("Logout"):
@@ -8,10 +139,11 @@ def main_app():
8
  st.sidebar.markdown("---")
9
  st.sidebar.subheader("πŸ“ Give Feedback")
10
  feedback_text = st.sidebar.text_area("Your thoughts about this place", height=100)
11
- feedback_image = st.sidebar.file_uploader("Upload an image", type=["jpg", "jpeg", "png"], key="image_upload")
12
- feedback_audio = st.sidebar.file_uploader("Upload audio", type=["mp3", "wav", "m4a"], key="audio_upload")
13
- feedback_video = st.sidebar.file_uploader("Upload video", type=["mp4", "mov", "avi"], key="video_upload")
14
 
 
15
  if feedback_image:
16
  st.sidebar.image(feedback_image, caption="Your uploaded image", use_container_width=True)
17
  if feedback_audio:
@@ -19,24 +151,43 @@ def main_app():
19
  if feedback_video:
20
  st.sidebar.video(feedback_video)
21
 
 
22
  st.title("πŸ“š Gyana Vedika - Cultural Explorer")
 
23
  state = st.selectbox("Select State", list(STATES.keys()))
24
  district = st.selectbox("Select District", STATES[state])
25
  st.subheader(f"Explore {district}, {state}")
26
 
27
- uploaded_image = st.file_uploader("Upload a cultural/historical place image", type=["png", "jpg", "jpeg"], key="place_image")
28
  place_to_search = None
29
  if uploaded_image:
30
  st.image(uploaded_image, caption="Uploaded Image", use_container_width=True)
31
  filename = uploaded_image.name.lower()
32
  keywords_map = {
33
- "charminar": "Charminar", "golconda": "Golconda Fort", "qutubshahi": "Qutb Shahi Tombs",
34
- "birla": "Birla Mandir", "salarjung": "Salar Jung Museum", "warangal": "Warangal Fort",
35
- "ramappa": "Ramappa Temple", "bhadrakali": "Bhadra Kali Temple", "kakatiya": "Kakatiya Kala Thoranam",
36
- "pakhal": "Pakhal Lake", "medak": "Medak Cathedral", "nagarjuna": "Nagarjuna Sagar Dam",
37
- "taj": "Taj Mahal", "gateway": "Gateway of India", "qutub": "Qutub Minar",
38
- "mysore": "Mysore Palace", "hampi": "Hampi", "konark": "Konark Sun Temple",
39
- "varanasi": "Varanasi", "madurai": "Meenakshi Temple", "ajanta": "Ajanta Caves", "ellora": "Ellora Caves"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  }
41
  for kw, place in keywords_map.items():
42
  if kw in filename:
@@ -61,10 +212,11 @@ def main_app():
61
  st.write(summary)
62
 
63
  if st.sidebar.button("Submit Feedback"):
64
- if feedback_text.strip() or feedback_image or feedback_audio or feedback_video:
65
  img_path = save_temp_file(feedback_image, "img")
66
  audio_path = save_temp_file(feedback_audio, "audio")
67
  video_path = save_temp_file(feedback_video, "video")
 
68
  save_feedback(
69
  email=st.session_state.email,
70
  place=place_to_search or "Unknown",
@@ -77,4 +229,30 @@ def main_app():
77
  )
78
  st.sidebar.success("Thank you! Feedback submitted.")
79
  else:
80
- st.sidebar.warning("Please provide feedback text or upload a file.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from PIL import Image
3
+ import os
4
+ import wikipedia
5
+ import csv
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"],
20
+ "Tamil Nadu": ["Chennai", "Coimbatore", "Madurai", "Tiruchirappalli", "Salem"],
21
+ "Karnataka": ["Bangalore", "Mysore", "Mangalore", "Hubli", "Belgaum"],
22
+ "Uttar Pradesh": ["Lucknow", "Varanasi", "Agra", "Kanpur", "Allahabad"],
23
+ "West Bengal": ["Kolkata", "Darjeeling", "Durgapur", "Siliguri", "Asansol"],
24
+ "Rajasthan": ["Jaipur", "Udaipur", "Jodhpur", "Bikaner", "Ajmer"],
25
+ "Gujarat": ["Ahmedabad", "Surat", "Vadodara", "Rajkot", "Bhavnagar"],
26
+ "Andhra Pradesh": ["Visakhapatnam", "Vijayawada", "Guntur", "Tirupati", "Kurnool"],
27
+ }
28
+
29
+ # ====== Session State Initialization ======
30
+ for key, default in {
31
+ "logged_in": False,
32
+ "email": "",
33
+ "otp_sent_to": None,
34
+ "otp_verified": False,
35
+ "login_email": None,
36
+ }.items():
37
+ if key not in st.session_state:
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
45
+ return "1234"
46
+
47
+ def verify_otp(entered_otp):
48
+ if st.session_state.otp_sent_to and entered_otp == "1234":
49
+ st.session_state.logged_in = True
50
+ st.session_state.email = st.session_state.otp_sent_to
51
+ st.session_state.otp_verified = True
52
+ st.session_state.login_email = None
53
+ return True
54
+ return False
55
+
56
+ def logout():
57
+ for key in ["logged_in", "email", "otp_sent_to", "otp_verified", "login_email"]:
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"):
61
+ try:
62
+ wikipedia.set_lang(lang)
63
+ return wikipedia.summary(title, sentences=4)
64
+ except wikipedia.exceptions.DisambiguationError as e:
65
+ return f"Multiple results found for '{title}': {e.options}"
66
+ except wikipedia.exceptions.PageError:
67
+ return f"No Wikipedia page found for '{title}' in selected language."
68
+ except Exception as e:
69
+ return f"Error fetching summary: {str(e)}"
70
+
71
+ def save_temp_file(uploaded_file, filetype):
72
+ if uploaded_file:
73
+ filename = f"{filetype}_{datetime.now().strftime('%Y%m%d%H%M%S')}_{uploaded_file.name}"
74
+ filepath = os.path.join(MEDIA_FOLDER, filename)
75
+ with open(filepath, "wb") as f:
76
+ f.write(uploaded_file.read())
77
+ return filepath
78
+ return ""
79
+
80
+ def save_feedback(email, place, state, district, text, img_path="", audio_path="", video_path=""):
81
+ if not os.path.exists(FEEDBACK_FILE):
82
+ with open(FEEDBACK_FILE, 'w', newline='', encoding='utf-8') as f:
83
+ writer = csv.writer(f)
84
+ writer.writerow([
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([
92
+ email, place, state, district, text,
93
+ img_path, audio_path, video_path, datetime.now().isoformat()
94
+ ])
95
+
96
+ # ====== Pages ======
97
+
98
+ def signup_page():
99
+ st.header("πŸš€ Signup")
100
+ name = st.text_input("Name")
101
+ email = st.text_input("Email (Gmail)")
102
+ contact = st.text_input("Contact Number")
103
+ if st.button("Sign Up"):
104
+ if email in USERS:
105
+ st.error("User already exists, please login.")
106
+ elif not email or not name:
107
+ st.error("Please enter name and email.")
108
+ else:
109
+ USERS[email] = {"name": name, "email": email, "contact": contact}
110
+ send_otp(email)
111
+ st.success(f"User {name} registered! OTP sent to {email} (simulated). Please verify OTP on Login page.")
112
+ st.session_state.login_email = email
113
+
114
+ def login_page():
115
+ st.header("πŸ” Login")
116
+ email = st.text_input("Email", key="login_email_input")
117
+ if st.button("Send OTP"):
118
+ if email in USERS:
119
+ send_otp(email)
120
+ st.success(f"OTP sent to {email} (simulated). Please enter OTP below.")
121
+ st.session_state.login_email = email
122
+ else:
123
+ st.error("Email not found. Please sign up first.")
124
+ if st.session_state.login_email == email:
125
+ otp = st.text_input("Enter OTP (use 1234 for demo)", type="password")
126
+ if st.button("Verify OTP"):
127
+ if verify_otp(otp):
128
+ st.success("OTP verified! Logged in successfully.")
129
+ else:
130
+ st.error("Incorrect OTP or no OTP sent.")
131
+
132
  def main_app():
133
  st.sidebar.success(f"Logged in as {st.session_state.email}")
134
  if st.sidebar.button("Logout"):
 
139
  st.sidebar.markdown("---")
140
  st.sidebar.subheader("πŸ“ Give Feedback")
141
  feedback_text = st.sidebar.text_area("Your thoughts about this place", height=100)
142
+ feedback_image = st.sidebar.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
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()))
158
  district = st.selectbox("Select District", STATES[state])
159
  st.subheader(f"Explore {district}, {state}")
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:
 
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",
 
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()