awacke1 commited on
Commit
6cf3eb8
Β·
verified Β·
1 Parent(s): 18489bd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -45
app.py CHANGED
@@ -73,7 +73,6 @@ def get_download_link(file):
73
 
74
  @st.cache_resource
75
  def speech_synthesis_html(result):
76
- # This old function remains for fallback, unused after integrating EdgeTTS.
77
  html_code = f"""
78
  <html><body>
79
  <script>
@@ -87,9 +86,6 @@ def speech_synthesis_html(result):
87
  #------------add EdgeTTS
88
  # --- NEW FUNCTIONS FOR EDGE TTS ---
89
  async def edge_tts_generate_audio(text, voice="en-US-AriaNeural", rate=0, pitch=0):
90
- """
91
- Generate audio from text using Edge TTS and return the path to the MP3 file.
92
- """
93
  if not text.strip():
94
  return None
95
  rate_str = f"{rate:+d}%"
@@ -100,15 +96,9 @@ async def edge_tts_generate_audio(text, voice="en-US-AriaNeural", rate=0, pitch=
100
  return out_fn
101
 
102
  def speak_with_edge_tts(text, voice="en-US-AriaNeural", rate=0, pitch=0):
103
- """
104
- Synchronous wrapper to call the async TTS generation and return the file path.
105
- """
106
  return asyncio.run(edge_tts_generate_audio(text, voice, rate, pitch))
107
 
108
  def play_and_download_audio(file_path):
109
- """
110
- Display an audio player and a download link for the generated MP3 file.
111
- """
112
  if file_path and os.path.exists(file_path):
113
  st.audio(file_path)
114
  st.markdown(get_download_link(file_path), unsafe_allow_html=True)
@@ -180,10 +170,8 @@ def search_arxiv(query):
180
  def perform_ai_lookup(q, vocal_summary=True, extended_refs=False, titles_summary=True):
181
  start = time.time()
182
  client = Client("awacke1/Arxiv-Paper-Search-And-QA-RAG-Pattern")
183
- # Perform a RAG-based search
184
  r = client.predict(q,20,"Semantic Search","mistralai/Mixtral-8x7B-Instruct-v0.1",api_name="/update_with_rag_md")
185
  refs = r[0]
186
- # Ask model for answer
187
  r2 = client.predict(q,"mistralai/Mixtral-8x7B-Instruct-v0.1",True,api_name="/ask_llm")
188
  result = f"### πŸ”Ž {q}\n\n{r2}\n\n{refs}"
189
 
@@ -261,7 +249,6 @@ def process_with_claude(text):
261
  return ans
262
 
263
  def create_zip_of_files():
264
- # Include all .md and .mp3 files in the zip
265
  md_files = glob.glob("*.md")
266
  mp3_files = glob.glob("*.mp3")
267
  all_files = md_files + mp3_files
@@ -286,17 +273,32 @@ def display_file_manager():
286
  mp3_files = sorted(glob.glob("*.mp3"), reverse=True)
287
  if mp3_files:
288
  st.sidebar.subheader("MP3 Files:")
 
 
 
 
289
  for a in mp3_files:
290
- with st.sidebar.expander(f"{os.path.basename(a)}"):
 
291
  # Show audio player
292
- st.sidebar.markdown(get_media_html(a,"audio"),unsafe_allow_html=True)
293
- # Download link for the MP3 file
294
- st.sidebar.markdown(get_download_link(a), unsafe_allow_html=True)
295
- # Button to transcribe this file
296
- if st.sidebar.button(f"Transcribe {os.path.basename(a)}"):
297
- t = process_audio(a)
298
- st.sidebar.write("Transcription:")
299
- st.sidebar.write(t)
 
 
 
 
 
 
 
 
 
 
300
  else:
301
  st.sidebar.write("No MP3 files found.")
302
 
@@ -304,31 +306,38 @@ def display_file_manager():
304
  st.sidebar.subheader("MD Files:")
305
  files = sorted(glob.glob("*.md"), reverse=True)
306
  if st.sidebar.button("πŸ—‘ Delete All MD"):
307
- for f in files: os.remove(f)
 
308
  st.experimental_rerun()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
309
  # Download all as zip (including .mp3 and .md)
310
- if st.sidebar.button("⬇️ Download All (.md and .mp3)"):
311
- z = create_zip_of_files()
312
- st.sidebar.markdown(get_download_link(z),unsafe_allow_html=True)
313
-
314
- for f in files:
315
- col1, col2, col3, col4 = st.sidebar.columns([1,3,1,1])
316
- with col1:
317
- if st.sidebar.button("🌐", key="v"+f):
318
- st.session_state.current_file = f
319
- c = open(f,'r',encoding='utf-8').read()
320
- st.write("**Viewing file content:**")
321
- st.write(c)
322
- with col2:
323
- st.sidebar.markdown(get_download_link(f),unsafe_allow_html=True)
324
- with col3:
325
- if st.sidebar.button("πŸ“‚", key="e"+f):
326
- st.session_state.current_file = f
327
- st.session_state.file_content = open(f,'r',encoding='utf-8').read()
328
- with col4:
329
- if st.sidebar.button("πŸ—‘", key="d"+f):
330
- os.remove(f)
331
- st.experimental_rerun()
332
 
333
  def main():
334
  st.sidebar.markdown("### 🚲BikeAIπŸ† Multi-Agent Research AI")
 
73
 
74
  @st.cache_resource
75
  def speech_synthesis_html(result):
 
76
  html_code = f"""
77
  <html><body>
78
  <script>
 
86
  #------------add EdgeTTS
87
  # --- NEW FUNCTIONS FOR EDGE TTS ---
88
  async def edge_tts_generate_audio(text, voice="en-US-AriaNeural", rate=0, pitch=0):
 
 
 
89
  if not text.strip():
90
  return None
91
  rate_str = f"{rate:+d}%"
 
96
  return out_fn
97
 
98
  def speak_with_edge_tts(text, voice="en-US-AriaNeural", rate=0, pitch=0):
 
 
 
99
  return asyncio.run(edge_tts_generate_audio(text, voice, rate, pitch))
100
 
101
  def play_and_download_audio(file_path):
 
 
 
102
  if file_path and os.path.exists(file_path):
103
  st.audio(file_path)
104
  st.markdown(get_download_link(file_path), unsafe_allow_html=True)
 
170
  def perform_ai_lookup(q, vocal_summary=True, extended_refs=False, titles_summary=True):
171
  start = time.time()
172
  client = Client("awacke1/Arxiv-Paper-Search-And-QA-RAG-Pattern")
 
173
  r = client.predict(q,20,"Semantic Search","mistralai/Mixtral-8x7B-Instruct-v0.1",api_name="/update_with_rag_md")
174
  refs = r[0]
 
175
  r2 = client.predict(q,"mistralai/Mixtral-8x7B-Instruct-v0.1",True,api_name="/ask_llm")
176
  result = f"### πŸ”Ž {q}\n\n{r2}\n\n{refs}"
177
 
 
249
  return ans
250
 
251
  def create_zip_of_files():
 
252
  md_files = glob.glob("*.md")
253
  mp3_files = glob.glob("*.mp3")
254
  all_files = md_files + mp3_files
 
273
  mp3_files = sorted(glob.glob("*.mp3"), reverse=True)
274
  if mp3_files:
275
  st.sidebar.subheader("MP3 Files:")
276
+ if st.sidebar.button("πŸ—‘ Delete All MP3"):
277
+ for a in mp3_files:
278
+ os.remove(a)
279
+ st.experimental_rerun()
280
  for a in mp3_files:
281
+ exp = st.sidebar.expander(os.path.basename(a))
282
+ with exp:
283
  # Show audio player
284
+ st.markdown(get_media_html(a,"audio"),unsafe_allow_html=True)
285
+
286
+ # Actions row
287
+ c1, c2, c3 = st.columns([3,3,1])
288
+ with c1:
289
+ # Download link for the MP3 file
290
+ st.markdown(get_download_link(a), unsafe_allow_html=True)
291
+ with c2:
292
+ # Button to transcribe this file
293
+ if st.button(f"Transcribe {os.path.basename(a)}", key="transcribe_"+a):
294
+ t = process_audio(a)
295
+ st.write("Transcription:")
296
+ st.write(t)
297
+ with c3:
298
+ # Delete button for mp3
299
+ if st.button("πŸ—‘", key="del_mp3_"+a):
300
+ os.remove(a)
301
+ st.experimental_rerun()
302
  else:
303
  st.sidebar.write("No MP3 files found.")
304
 
 
306
  st.sidebar.subheader("MD Files:")
307
  files = sorted(glob.glob("*.md"), reverse=True)
308
  if st.sidebar.button("πŸ—‘ Delete All MD"):
309
+ for f in files:
310
+ os.remove(f)
311
  st.experimental_rerun()
312
+
313
+ if files:
314
+ for f in files:
315
+ col1, col2, col3, col4 = st.sidebar.columns([1,3,1,1])
316
+ with col1:
317
+ if st.button("🌐", key="v"+f):
318
+ st.session_state.current_file = f
319
+ c = open(f,'r',encoding='utf-8').read()
320
+ st.write("**Viewing file content:**")
321
+ st.write(c)
322
+ with col2:
323
+ st.markdown(get_download_link(f),unsafe_allow_html=True)
324
+ with col3:
325
+ if st.button("πŸ“‚", key="e"+f):
326
+ st.session_state.current_file = f
327
+ st.session_state.file_content = open(f,'r',encoding='utf-8').read()
328
+ with col4:
329
+ if st.button("πŸ—‘", key="d"+f):
330
+ os.remove(f)
331
+ st.experimental_rerun()
332
+ else:
333
+ st.sidebar.write("No MD files found.")
334
+
335
  # Download all as zip (including .mp3 and .md)
336
+ if len(files) > 0 or len(mp3_files) > 0:
337
+ if st.sidebar.button("⬇️ Download All (.md and .mp3)"):
338
+ z = create_zip_of_files()
339
+ st.sidebar.markdown(get_download_link(z),unsafe_allow_html=True)
340
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
341
 
342
  def main():
343
  st.sidebar.markdown("### 🚲BikeAIπŸ† Multi-Agent Research AI")