gskdsrikrishna commited on
Commit
5a545b9
·
verified ·
1 Parent(s): a0a52a5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +68 -0
app.py CHANGED
@@ -13,6 +13,7 @@ import json
13
  import pandas as pd
14
  import altair as alt
15
  from datetime import date
 
16
 
17
  # Set up YouTube API
18
  API_KEY_YOUTUBE = os.getenv("YT") # Replace with your YouTube Data API v3 key
@@ -154,9 +155,52 @@ def display_news(articles):
154
  else:
155
  st.error("No news articles found.")
156
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
  def main():
158
  st.set_page_config(page_title="Multi-Search Application", layout="wide")
159
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
  # Initialize chat history if not present
161
  if "chat_history" not in st.session_state:
162
  st.session_state.chat_history = []
@@ -164,6 +208,30 @@ def main():
164
  # Sidebar options
165
  st.sidebar.title("Options")
166
  search_type = st.sidebar.radio("Select Search Type", ("Wikipedia", "Google", "YouTube", "News", "Chat"))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167
 
168
  if st.sidebar.button("Voice Search"):
169
  query = voice_search()
 
13
  import pandas as pd
14
  import altair as alt
15
  from datetime import date
16
+ import pickle
17
 
18
  # Set up YouTube API
19
  API_KEY_YOUTUBE = os.getenv("YT") # Replace with your YouTube Data API v3 key
 
155
  else:
156
  st.error("No news articles found.")
157
 
158
+ # File to store shortcut data
159
+ DATA_FILE = "shortcuts_data.pkl"
160
+
161
+ def load_shortcuts():
162
+ if os.path.exists(DATA_FILE):
163
+ with open(DATA_FILE, "rb") as f:
164
+ return pickle.load(f)
165
+ return []
166
+
167
+ def save_shortcuts(shortcuts):
168
+ with open(DATA_FILE, "wb") as f:
169
+ pickle.dump(shortcuts, f)
170
+
171
+ if "shortcuts" not in st.session_state:
172
+ st.session_state["shortcuts"] = load_shortcuts()
173
+
174
+
175
  def main():
176
  st.set_page_config(page_title="Multi-Search Application", layout="wide")
177
 
178
+ # **Show Saved Shortcuts**
179
+ st.header("My Shortcuts")
180
+ with st.expander("Click to View Shortcuts"):
181
+ if st.session_state.shortcuts:
182
+ num_columns = 4
183
+ cols = st.columns(num_columns)
184
+ for i, (name, link, icon_data, user_password) in enumerate(st.session_state.shortcuts):
185
+ col = cols[i % num_columns]
186
+ with col:
187
+ st.image(icon_data, width=100)
188
+ st.markdown(f"[{name}]({link})", unsafe_allow_html=True)
189
+
190
+ password_input_delete = st.text_input("Enter Password to Delete", type="password", key=f"delete_password_{i}")
191
+
192
+ if password_input_delete == user_password:
193
+ if st.button(f"Delete {name}", key=f"delete_{i}"):
194
+ st.session_state.shortcuts.pop(i)
195
+ save_shortcuts(st.session_state.shortcuts)
196
+ st.experimental_rerun()
197
+ elif password_input_delete:
198
+ st.warning("Incorrect password. You cannot delete this shortcut.")
199
+ else:
200
+ st.write("No shortcuts added yet.")
201
+
202
+ st.markdown("Note: Add best web links for student education purposes.")
203
+
204
  # Initialize chat history if not present
205
  if "chat_history" not in st.session_state:
206
  st.session_state.chat_history = []
 
208
  # Sidebar options
209
  st.sidebar.title("Options")
210
  search_type = st.sidebar.radio("Select Search Type", ("Wikipedia", "Google", "YouTube", "News", "Chat"))
211
+
212
+ # **Add this block after st.sidebar.title("Options")**
213
+ st.sidebar.header("Only Add Best Web Links")
214
+ name = st.sidebar.text_input("Shortcut Name")
215
+ link = st.sidebar.text_input("Website Link (https://...)")
216
+ icon_file = st.sidebar.file_uploader("Upload an Icon", type=["png", "jpg", "jpeg"])
217
+ password_input_add = st.sidebar.text_input("Enter Password to Add Shortcut", type="password")
218
+
219
+ if st.sidebar.button("Add Shortcut"):
220
+ if password_input_add:
221
+ if name and link and icon_file:
222
+ existing_links = [shortcut[1] for shortcut in st.session_state.shortcuts]
223
+ if link in existing_links:
224
+ st.sidebar.warning("This website already exists.")
225
+ else:
226
+ st.session_state.shortcuts.append((name, link, icon_file.getvalue(), password_input_add))
227
+ save_shortcuts(st.session_state.shortcuts)
228
+ st.sidebar.success(f"Shortcut '{name}' added!")
229
+ else:
230
+ st.sidebar.warning("Please enter all details including an icon.")
231
+ else:
232
+ st.sidebar.warning("Please enter a password to add the shortcut.")
233
+
234
+
235
 
236
  if st.sidebar.button("Voice Search"):
237
  query = voice_search()