awacke1 commited on
Commit
4f757ca
Β·
verified Β·
1 Parent(s): 688cdbe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -25
app.py CHANGED
@@ -1,11 +1,8 @@
1
  import streamlit as st
2
  import pandas as pd
3
- import numpy as np
4
- import json
5
  import os
6
  import glob
7
  import random
8
- from pathlib import Path
9
  from datetime import datetime
10
  import edge_tts
11
  import asyncio
@@ -52,8 +49,7 @@ SESSION_VARS = {
52
  'voice_text': None,
53
  'user_name': random.choice(USER_NAMES),
54
  'max_items': 100,
55
- 'global_voice': "en-US-AriaNeural",
56
- 'last_arxiv_input': None
57
  }
58
 
59
  for var, default in SESSION_VARS.items():
@@ -188,8 +184,6 @@ def simple_dataset_search(query, df):
188
  return pd.DataFrame(matches)
189
  return pd.DataFrame()
190
 
191
- from datasets import load_dataset
192
-
193
  @st.cache_data
194
  def load_dataset_page(dataset_id, token, page, rows_per_page):
195
  try:
@@ -213,7 +207,6 @@ class SimpleDatasetSearcher:
213
  return load_dataset_page(self.dataset_id, self.token, page, ROWS_PER_PAGE)
214
 
215
  def concatenate_mp3(files, output_file):
216
- # Naive binary concatenation of MP3 files
217
  with open(output_file, 'wb') as outfile:
218
  for f in files:
219
  with open(f, 'rb') as infile:
@@ -222,11 +215,8 @@ def concatenate_mp3(files, output_file):
222
  def main():
223
  st.title("πŸŽ™οΈ Voice Chat & Search")
224
 
225
- # Sidebar
226
  with st.sidebar:
227
- # Editable user name
228
  st.session_state['user_name'] = st.selectbox("Current User:", USER_NAMES, index=0)
229
-
230
  st.session_state['max_items'] = st.number_input("Max Items per search iteration:", min_value=1, max_value=1000, value=st.session_state['max_items'])
231
 
232
  st.subheader("πŸ“ Saved Inputs & Responses")
@@ -236,14 +226,11 @@ def main():
236
  fname = os.path.basename(fpath)
237
  st.write(f"- {fname} (User: {user})")
238
 
239
- # Create voice component for input
240
  voice_component = create_voice_component()
241
  voice_val = voice_component(my_input_value="Start speaking...")
242
 
243
- # Tabs
244
  tab1, tab2, tab3, tab4 = st.tabs(["πŸ—£οΈ Voice Chat History", "πŸ“š ArXiv Search", "πŸ“Š Dataset Search", "βš™οΈ Settings"])
245
 
246
- # ------------------ Voice Chat History -------------------------
247
  with tab1:
248
  st.subheader("Voice Chat History")
249
  files = list_saved_inputs()
@@ -252,20 +239,16 @@ def main():
252
  user, ts, content = parse_md_file(fpath)
253
  conversation.append((user, ts, content, fpath))
254
 
255
- # Enumerate to ensure unique keys
256
  for i, (user, ts, content, fpath) in enumerate(reversed(conversation), start=1):
257
  with st.expander(f"{ts} - {user}", expanded=False):
258
  st.write(content)
259
- # Make button key unique by including i
260
  if st.button(f"πŸ”Š Read Aloud {ts}-{user}", key=f"read_{i}_{fpath}"):
261
  voice = USER_VOICES.get(user, "en-US-AriaNeural")
262
  audio_file = speak_with_edge_tts(content, voice=voice)
263
  if audio_file:
264
  play_and_download_audio(audio_file)
265
 
266
- # Read entire conversation
267
  if st.button("πŸ“œ Read Conversation", key="read_conversation_all"):
268
- # conversation is currently reversed, re-reverse to get chronological
269
  conversation_chrono = list(reversed(conversation))
270
  mp3_files = []
271
  for user, ts, content, fpath in conversation_chrono:
@@ -282,7 +265,6 @@ def main():
282
  st.write("**Full Conversation Audio:**")
283
  play_and_download_audio(combined_file)
284
 
285
- # ------------------ ArXiv Search -------------------------
286
  with tab2:
287
  st.subheader("ArXiv Search")
288
  edited_input = st.text_area("Enter or Edit Search Query:", value=(voice_val.strip() if voice_val else ""), height=100)
@@ -296,9 +278,8 @@ def main():
296
  if run_arxiv and edited_input.strip():
297
  should_run_arxiv = True
298
 
299
- if should_run_arxiv and st.session_state['last_arxiv_input'] != edited_input:
300
  st.session_state['old_val'] = edited_input
301
- st.session_state['last_arxiv_input'] = edited_input
302
  save_input_as_md(st.session_state['user_name'], edited_input, prefix="input")
303
  with st.spinner("Searching ArXiv..."):
304
  results = arxiv_search(edited_input)
@@ -306,7 +287,6 @@ def main():
306
  summary = summarize_arxiv_results(results)
307
  save_response_as_md(st.session_state['user_name'], summary, prefix="response")
308
  st.write(summary)
309
- # Play summary aloud
310
  voice = USER_VOICES.get(st.session_state['user_name'], "en-US-AriaNeural")
311
  audio_file = speak_with_edge_tts(summary, voice=voice)
312
  if audio_file:
@@ -314,7 +294,6 @@ def main():
314
  else:
315
  st.warning("No results found on ArXiv.")
316
 
317
- # ------------------ Dataset Search -------------------------
318
  with tab3:
319
  st.subheader("Dataset Search")
320
  ds_searcher = SimpleDatasetSearcher()
@@ -339,11 +318,9 @@ def main():
339
  else:
340
  st.warning("No matching results found.")
341
 
342
- # ------------------ Settings Tab -------------------------
343
  with tab4:
344
  st.subheader("Settings")
345
  if st.button("πŸ—‘οΈ Clear Search History", key="clear_history"):
346
- # Delete all files
347
  for fpath in list_saved_inputs():
348
  os.remove(fpath)
349
  st.session_state['search_history'] = []
 
1
  import streamlit as st
2
  import pandas as pd
 
 
3
  import os
4
  import glob
5
  import random
 
6
  from datetime import datetime
7
  import edge_tts
8
  import asyncio
 
49
  'voice_text': None,
50
  'user_name': random.choice(USER_NAMES),
51
  'max_items': 100,
52
+ 'global_voice': "en-US-AriaNeural"
 
53
  }
54
 
55
  for var, default in SESSION_VARS.items():
 
184
  return pd.DataFrame(matches)
185
  return pd.DataFrame()
186
 
 
 
187
  @st.cache_data
188
  def load_dataset_page(dataset_id, token, page, rows_per_page):
189
  try:
 
207
  return load_dataset_page(self.dataset_id, self.token, page, ROWS_PER_PAGE)
208
 
209
  def concatenate_mp3(files, output_file):
 
210
  with open(output_file, 'wb') as outfile:
211
  for f in files:
212
  with open(f, 'rb') as infile:
 
215
  def main():
216
  st.title("πŸŽ™οΈ Voice Chat & Search")
217
 
 
218
  with st.sidebar:
 
219
  st.session_state['user_name'] = st.selectbox("Current User:", USER_NAMES, index=0)
 
220
  st.session_state['max_items'] = st.number_input("Max Items per search iteration:", min_value=1, max_value=1000, value=st.session_state['max_items'])
221
 
222
  st.subheader("πŸ“ Saved Inputs & Responses")
 
226
  fname = os.path.basename(fpath)
227
  st.write(f"- {fname} (User: {user})")
228
 
 
229
  voice_component = create_voice_component()
230
  voice_val = voice_component(my_input_value="Start speaking...")
231
 
 
232
  tab1, tab2, tab3, tab4 = st.tabs(["πŸ—£οΈ Voice Chat History", "πŸ“š ArXiv Search", "πŸ“Š Dataset Search", "βš™οΈ Settings"])
233
 
 
234
  with tab1:
235
  st.subheader("Voice Chat History")
236
  files = list_saved_inputs()
 
239
  user, ts, content = parse_md_file(fpath)
240
  conversation.append((user, ts, content, fpath))
241
 
 
242
  for i, (user, ts, content, fpath) in enumerate(reversed(conversation), start=1):
243
  with st.expander(f"{ts} - {user}", expanded=False):
244
  st.write(content)
 
245
  if st.button(f"πŸ”Š Read Aloud {ts}-{user}", key=f"read_{i}_{fpath}"):
246
  voice = USER_VOICES.get(user, "en-US-AriaNeural")
247
  audio_file = speak_with_edge_tts(content, voice=voice)
248
  if audio_file:
249
  play_and_download_audio(audio_file)
250
 
 
251
  if st.button("πŸ“œ Read Conversation", key="read_conversation_all"):
 
252
  conversation_chrono = list(reversed(conversation))
253
  mp3_files = []
254
  for user, ts, content, fpath in conversation_chrono:
 
265
  st.write("**Full Conversation Audio:**")
266
  play_and_download_audio(combined_file)
267
 
 
268
  with tab2:
269
  st.subheader("ArXiv Search")
270
  edited_input = st.text_area("Enter or Edit Search Query:", value=(voice_val.strip() if voice_val else ""), height=100)
 
278
  if run_arxiv and edited_input.strip():
279
  should_run_arxiv = True
280
 
281
+ if should_run_arxiv:
282
  st.session_state['old_val'] = edited_input
 
283
  save_input_as_md(st.session_state['user_name'], edited_input, prefix="input")
284
  with st.spinner("Searching ArXiv..."):
285
  results = arxiv_search(edited_input)
 
287
  summary = summarize_arxiv_results(results)
288
  save_response_as_md(st.session_state['user_name'], summary, prefix="response")
289
  st.write(summary)
 
290
  voice = USER_VOICES.get(st.session_state['user_name'], "en-US-AriaNeural")
291
  audio_file = speak_with_edge_tts(summary, voice=voice)
292
  if audio_file:
 
294
  else:
295
  st.warning("No results found on ArXiv.")
296
 
 
297
  with tab3:
298
  st.subheader("Dataset Search")
299
  ds_searcher = SimpleDatasetSearcher()
 
318
  else:
319
  st.warning("No matching results found.")
320
 
 
321
  with tab4:
322
  st.subheader("Settings")
323
  if st.button("πŸ—‘οΈ Clear Search History", key="clear_history"):
 
324
  for fpath in list_saved_inputs():
325
  os.remove(fpath)
326
  st.session_state['search_history'] = []