Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -73,7 +73,7 @@ def get_download_link(file):
|
|
| 73 |
|
| 74 |
@st.cache_resource
|
| 75 |
def speech_synthesis_html(result):
|
| 76 |
-
# This old function
|
| 77 |
html_code = f"""
|
| 78 |
<html><body>
|
| 79 |
<script>
|
|
@@ -177,7 +177,7 @@ def search_arxiv(query):
|
|
| 177 |
st.markdown(r2)
|
| 178 |
return f"{r1}\n\n{r2}"
|
| 179 |
|
| 180 |
-
def perform_ai_lookup(q):
|
| 181 |
start = time.time()
|
| 182 |
client = Client("awacke1/Arxiv-Paper-Search-And-QA-RAG-Pattern")
|
| 183 |
# Perform a RAG-based search
|
|
@@ -189,31 +189,40 @@ def perform_ai_lookup(q):
|
|
| 189 |
|
| 190 |
st.markdown(result)
|
| 191 |
|
| 192 |
-
#
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 214 |
|
| 215 |
elapsed = time.time()-start
|
| 216 |
-
st.write(f"Elapsed
|
| 217 |
fn = generate_filename(q,"md")
|
| 218 |
create_file(fn,q,result)
|
| 219 |
return result
|
|
@@ -339,7 +348,7 @@ def main():
|
|
| 339 |
process_with_claude(user_input)
|
| 340 |
elif model_choice == "Arxiv":
|
| 341 |
st.subheader("Arxiv Only Results:")
|
| 342 |
-
perform_ai_lookup(user_input)
|
| 343 |
else:
|
| 344 |
col1,col2,col3=st.columns(3)
|
| 345 |
with col1:
|
|
@@ -353,12 +362,27 @@ def main():
|
|
| 353 |
with col3:
|
| 354 |
st.subheader("Arxiv + Mistral:")
|
| 355 |
try:
|
| 356 |
-
|
| 357 |
-
st.markdown(r)
|
| 358 |
except:
|
| 359 |
st.write("Arxiv error")
|
| 360 |
|
| 361 |
-
if tab_main == "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 362 |
st.subheader("π€ Voice Recognition")
|
| 363 |
user_text = st.text_area("Message:", height=100)
|
| 364 |
user_text = user_text.strip()
|
|
@@ -370,7 +394,7 @@ def main():
|
|
| 370 |
process_with_claude(user_text)
|
| 371 |
elif model_choice == "Arxiv":
|
| 372 |
st.subheader("Arxiv Only Results:")
|
| 373 |
-
perform_ai_lookup(user_text)
|
| 374 |
else:
|
| 375 |
col1,col2,col3=st.columns(3)
|
| 376 |
with col1:
|
|
@@ -381,7 +405,7 @@ def main():
|
|
| 381 |
process_with_claude(user_text)
|
| 382 |
with col3:
|
| 383 |
st.subheader("Arxiv & Mistral:")
|
| 384 |
-
res = perform_ai_lookup(user_text)
|
| 385 |
st.markdown(res)
|
| 386 |
st.subheader("π Chat History")
|
| 387 |
t1,t2=st.tabs(["Claude History","GPT-4o History"])
|
|
@@ -395,7 +419,6 @@ def main():
|
|
| 395 |
st.markdown(m["content"])
|
| 396 |
|
| 397 |
elif tab_main == "πΈ Media Gallery":
|
| 398 |
-
# Only show Images and Videos since Audio is now in sidebar
|
| 399 |
st.header("π¬ Media Gallery - Images and Videos")
|
| 400 |
tabs = st.tabs(["πΌοΈ Images", "π₯ Video"])
|
| 401 |
with tabs[0]:
|
|
@@ -423,14 +446,6 @@ def main():
|
|
| 423 |
else:
|
| 424 |
st.write("No videos found.")
|
| 425 |
|
| 426 |
-
elif tab_main == "π Search ArXiv":
|
| 427 |
-
q=st.text_input("Research query:")
|
| 428 |
-
if q:
|
| 429 |
-
q = q.strip()
|
| 430 |
-
if q:
|
| 431 |
-
r=search_arxiv(q)
|
| 432 |
-
st.markdown(r)
|
| 433 |
-
|
| 434 |
elif tab_main == "π File Editor":
|
| 435 |
if getattr(st.session_state,'current_file',None):
|
| 436 |
st.subheader(f"Editing: {st.session_state.current_file}")
|
|
@@ -444,6 +459,5 @@ def main():
|
|
| 444 |
|
| 445 |
display_file_manager()
|
| 446 |
|
| 447 |
-
|
| 448 |
if __name__=="__main__":
|
| 449 |
main()
|
|
|
|
| 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>
|
|
|
|
| 177 |
st.markdown(r2)
|
| 178 |
return f"{r1}\n\n{r2}"
|
| 179 |
|
| 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
|
|
|
|
| 189 |
|
| 190 |
st.markdown(result)
|
| 191 |
|
| 192 |
+
# Main Vocal Summary (Short Answer)
|
| 193 |
+
if vocal_summary:
|
| 194 |
+
start_main_part = time.time()
|
| 195 |
+
audio_file_main = speak_with_edge_tts(r2, voice="en-US-AriaNeural", rate=0, pitch=0)
|
| 196 |
+
st.write("### ποΈ Vocal Summary (Short Answer)")
|
| 197 |
+
play_and_download_audio(audio_file_main)
|
| 198 |
+
st.write(f"**Elapsed (Short Answer):** {time.time() - start_main_part:.2f} s")
|
| 199 |
+
|
| 200 |
+
# Extended References & Summaries (optional)
|
| 201 |
+
if extended_refs:
|
| 202 |
+
start_refs_part = time.time()
|
| 203 |
+
summaries_text = "Here are the summaries from the references: " + refs.replace('"','')
|
| 204 |
+
audio_file_refs = speak_with_edge_tts(summaries_text, voice="en-US-AriaNeural", rate=0, pitch=0)
|
| 205 |
+
st.write("### π Extended References & Summaries")
|
| 206 |
+
play_and_download_audio(audio_file_refs)
|
| 207 |
+
st.write(f"**Elapsed (Extended References):** {time.time() - start_refs_part:.2f} s")
|
| 208 |
+
|
| 209 |
+
# Paper Titles Only (short)
|
| 210 |
+
if titles_summary:
|
| 211 |
+
start_titles_part = time.time()
|
| 212 |
+
titles = []
|
| 213 |
+
for line in refs.split('\n'):
|
| 214 |
+
m = re.search(r"\[([^\]]+)\]", line)
|
| 215 |
+
if m:
|
| 216 |
+
titles.append(m.group(1))
|
| 217 |
+
if titles:
|
| 218 |
+
titles_text = "Here are the titles of the papers: " + ", ".join(titles)
|
| 219 |
+
audio_file_titles = speak_with_edge_tts(titles_text, voice="en-US-AriaNeural", rate=0, pitch=0)
|
| 220 |
+
st.write("### π Paper Titles")
|
| 221 |
+
play_and_download_audio(audio_file_titles)
|
| 222 |
+
st.write(f"**Elapsed (Titles):** {time.time() - start_titles_part:.2f} s")
|
| 223 |
|
| 224 |
elapsed = time.time()-start
|
| 225 |
+
st.write(f"**Total Elapsed:** {elapsed:.2f} s")
|
| 226 |
fn = generate_filename(q,"md")
|
| 227 |
create_file(fn,q,result)
|
| 228 |
return result
|
|
|
|
| 348 |
process_with_claude(user_input)
|
| 349 |
elif model_choice == "Arxiv":
|
| 350 |
st.subheader("Arxiv Only Results:")
|
| 351 |
+
perform_ai_lookup(user_input, vocal_summary=True, extended_refs=False, titles_summary=True)
|
| 352 |
else:
|
| 353 |
col1,col2,col3=st.columns(3)
|
| 354 |
with col1:
|
|
|
|
| 362 |
with col3:
|
| 363 |
st.subheader("Arxiv + Mistral:")
|
| 364 |
try:
|
| 365 |
+
perform_ai_lookup(user_input, vocal_summary=True, extended_refs=False, titles_summary=True)
|
|
|
|
| 366 |
except:
|
| 367 |
st.write("Arxiv error")
|
| 368 |
|
| 369 |
+
if tab_main == "π Search ArXiv":
|
| 370 |
+
st.subheader("π Search ArXiv")
|
| 371 |
+
q=st.text_input("Research query:")
|
| 372 |
+
|
| 373 |
+
# ποΈ Audio Generation Options
|
| 374 |
+
st.markdown("### ποΈ Audio Generation Options")
|
| 375 |
+
vocal_summary = st.checkbox("ποΈ Vocal Summary (Short Answer)", value=True)
|
| 376 |
+
extended_refs = st.checkbox("π Extended References & Summaries (Long)", value=False)
|
| 377 |
+
titles_summary = st.checkbox("π Paper Titles Only", value=True)
|
| 378 |
+
|
| 379 |
+
if q:
|
| 380 |
+
q = q.strip()
|
| 381 |
+
if q and st.button("Run ArXiv Query"):
|
| 382 |
+
r = perform_ai_lookup(q, vocal_summary=vocal_summary, extended_refs=extended_refs, titles_summary=titles_summary)
|
| 383 |
+
st.markdown(r)
|
| 384 |
+
|
| 385 |
+
elif tab_main == "π€ Voice Input":
|
| 386 |
st.subheader("π€ Voice Recognition")
|
| 387 |
user_text = st.text_area("Message:", height=100)
|
| 388 |
user_text = user_text.strip()
|
|
|
|
| 394 |
process_with_claude(user_text)
|
| 395 |
elif model_choice == "Arxiv":
|
| 396 |
st.subheader("Arxiv Only Results:")
|
| 397 |
+
perform_ai_lookup(user_text, vocal_summary=True, extended_refs=False, titles_summary=True)
|
| 398 |
else:
|
| 399 |
col1,col2,col3=st.columns(3)
|
| 400 |
with col1:
|
|
|
|
| 405 |
process_with_claude(user_text)
|
| 406 |
with col3:
|
| 407 |
st.subheader("Arxiv & Mistral:")
|
| 408 |
+
res = perform_ai_lookup(user_text, vocal_summary=True, extended_refs=False, titles_summary=True)
|
| 409 |
st.markdown(res)
|
| 410 |
st.subheader("π Chat History")
|
| 411 |
t1,t2=st.tabs(["Claude History","GPT-4o History"])
|
|
|
|
| 419 |
st.markdown(m["content"])
|
| 420 |
|
| 421 |
elif tab_main == "πΈ Media Gallery":
|
|
|
|
| 422 |
st.header("π¬ Media Gallery - Images and Videos")
|
| 423 |
tabs = st.tabs(["πΌοΈ Images", "π₯ Video"])
|
| 424 |
with tabs[0]:
|
|
|
|
| 446 |
else:
|
| 447 |
st.write("No videos found.")
|
| 448 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 449 |
elif tab_main == "π File Editor":
|
| 450 |
if getattr(st.session_state,'current_file',None):
|
| 451 |
st.subheader(f"Editing: {st.session_state.current_file}")
|
|
|
|
| 459 |
|
| 460 |
display_file_manager()
|
| 461 |
|
|
|
|
| 462 |
if __name__=="__main__":
|
| 463 |
main()
|