Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -114,7 +114,6 @@ def play_and_download_audio(file_path):
|
|
114 |
st.markdown(get_download_link(file_path), unsafe_allow_html=True)
|
115 |
#---------------------------
|
116 |
|
117 |
-
|
118 |
def process_image(image_path, user_prompt):
|
119 |
with open(image_path, "rb") as imgf:
|
120 |
image_data = imgf.read()
|
@@ -188,11 +187,6 @@ def perform_ai_lookup(q):
|
|
188 |
r2 = client.predict(q,"mistralai/Mixtral-8x7B-Instruct-v0.1",True,api_name="/ask_llm")
|
189 |
result = f"### π {q}\n\n{r2}\n\n{refs}"
|
190 |
|
191 |
-
#---------------------------------------------------------------
|
192 |
-
# Speak results
|
193 |
-
#speech_synthesis_html(r2)
|
194 |
-
|
195 |
-
# Instead of speech_synthesis_html, use EdgeTTS now:
|
196 |
st.markdown(result)
|
197 |
|
198 |
# Speak main result
|
@@ -200,7 +194,6 @@ def perform_ai_lookup(q):
|
|
200 |
st.write("### Audio Output for Main Result")
|
201 |
play_and_download_audio(audio_file_main)
|
202 |
|
203 |
-
|
204 |
# Speak references summaries
|
205 |
summaries_text = "Here are the summaries from the references: " + refs.replace('"','')
|
206 |
audio_file_refs = speak_with_edge_tts(summaries_text, voice="en-US-AriaNeural", rate=0, pitch=0)
|
@@ -218,10 +211,7 @@ def perform_ai_lookup(q):
|
|
218 |
audio_file_titles = speak_with_edge_tts(titles_text, voice="en-US-AriaNeural", rate=0, pitch=0)
|
219 |
st.write("### Audio Output for Paper Titles")
|
220 |
play_and_download_audio(audio_file_titles)
|
221 |
-
# --------------------------------------------
|
222 |
-
|
223 |
|
224 |
-
st.markdown(result)
|
225 |
elapsed = time.time()-start
|
226 |
st.write(f"Elapsed: {elapsed:.2f} s")
|
227 |
fn = generate_filename(q,"md")
|
@@ -261,10 +251,15 @@ def process_with_claude(text):
|
|
261 |
st.session_state.chat_history.append({"user":text,"claude":ans})
|
262 |
return ans
|
263 |
|
264 |
-
def create_zip_of_files(
|
|
|
|
|
|
|
|
|
265 |
zip_name = "all_files.zip"
|
266 |
with zipfile.ZipFile(zip_name,'w') as z:
|
267 |
-
for f in
|
|
|
268 |
return zip_name
|
269 |
|
270 |
def get_media_html(p,typ="video",w="100%"):
|
@@ -274,63 +269,58 @@ def get_media_html(p,typ="video",w="100%"):
|
|
274 |
else:
|
275 |
return f'<audio controls style="width:{w};"><source src="data:audio/mpeg;base64,{d}" type="audio/mpeg"></audio>'
|
276 |
|
277 |
-
def
|
278 |
-
st.
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
for a in auds:
|
294 |
-
with st.expander(f"π΅ {os.path.basename(a)}"):
|
295 |
-
st.markdown(get_media_html(a,"audio"),unsafe_allow_html=True)
|
296 |
-
if st.button(f"Transcribe {os.path.basename(a)}"):
|
297 |
t = process_audio(a)
|
298 |
-
st.write(
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
with st.expander(f"π₯ {os.path.basename(v)}"):
|
303 |
-
st.markdown(get_media_html(v,"video"),unsafe_allow_html=True)
|
304 |
-
if st.button(f"Analyze {os.path.basename(v)}"):
|
305 |
-
a = process_video_with_gpt(v,"Describe video.")
|
306 |
-
st.markdown(a)
|
307 |
|
308 |
-
|
309 |
-
st.sidebar.
|
310 |
-
files = sorted(glob.glob("*.md"),reverse=True)
|
311 |
-
if st.sidebar.button("π Delete All"):
|
312 |
for f in files: os.remove(f)
|
313 |
-
st.
|
314 |
-
|
315 |
-
|
|
|
316 |
st.sidebar.markdown(get_download_link(z),unsafe_allow_html=True)
|
|
|
317 |
for f in files:
|
318 |
-
col1,col2,col3,col4 = st.sidebar.columns([1,3,1,1])
|
319 |
with col1:
|
320 |
-
if st.button("π",key="v"+f):
|
321 |
-
st.session_state.current_file=f
|
322 |
-
c=open(f,'r',encoding='utf-8').read()
|
|
|
323 |
st.write(c)
|
324 |
with col2:
|
325 |
-
st.markdown(get_download_link(f),unsafe_allow_html=True)
|
326 |
with col3:
|
327 |
-
if st.button("π",key="e"+f):
|
328 |
-
st.session_state.current_file=f
|
329 |
-
st.session_state.file_content=open(f,'r',encoding='utf-8').read()
|
330 |
with col4:
|
331 |
-
if st.button("π",key="d"+f):
|
332 |
os.remove(f)
|
333 |
st.experimental_rerun()
|
|
|
334 |
def main():
|
335 |
st.sidebar.markdown("### π²BikeAIπ Multi-Agent Research AI")
|
336 |
tab_main = st.radio("Action:",["π€ Voice Input","πΈ Media Gallery","π Search ArXiv","π File Editor"],horizontal=True)
|
@@ -341,7 +331,6 @@ def main():
|
|
341 |
mycomponent = components.declare_component("mycomponent", path="mycomponent")
|
342 |
val = mycomponent(my_input_value="Hello")
|
343 |
if val:
|
344 |
-
# Strip whitespace and newlines from the end of the user input
|
345 |
user_input = val.strip()
|
346 |
if user_input:
|
347 |
if model_choice == "GPT-4o":
|
@@ -372,7 +361,6 @@ def main():
|
|
372 |
if tab_main == "π€ Voice Input":
|
373 |
st.subheader("π€ Voice Recognition")
|
374 |
user_text = st.text_area("Message:", height=100)
|
375 |
-
# Strip whitespace and newlines
|
376 |
user_text = user_text.strip()
|
377 |
if st.button("Send π¨"):
|
378 |
if user_text:
|
@@ -407,12 +395,38 @@ def main():
|
|
407 |
st.markdown(m["content"])
|
408 |
|
409 |
elif tab_main == "πΈ Media Gallery":
|
410 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
411 |
|
412 |
elif tab_main == "π Search ArXiv":
|
413 |
q=st.text_input("Research query:")
|
414 |
if q:
|
415 |
-
q = q.strip()
|
416 |
if q:
|
417 |
r=search_arxiv(q)
|
418 |
st.markdown(r)
|
@@ -421,14 +435,15 @@ def main():
|
|
421 |
if getattr(st.session_state,'current_file',None):
|
422 |
st.subheader(f"Editing: {st.session_state.current_file}")
|
423 |
new_text = st.text_area("Content:", st.session_state.file_content, height=300)
|
424 |
-
# Here also you can strip if needed, but usually for file editing you might not want to.
|
425 |
if st.button("Save"):
|
426 |
with open(st.session_state.current_file,'w',encoding='utf-8') as f:
|
427 |
f.write(new_text)
|
428 |
st.success("Updated!")
|
|
|
|
|
429 |
|
430 |
display_file_manager()
|
431 |
|
432 |
|
433 |
if __name__=="__main__":
|
434 |
-
main()
|
|
|
114 |
st.markdown(get_download_link(file_path), unsafe_allow_html=True)
|
115 |
#---------------------------
|
116 |
|
|
|
117 |
def process_image(image_path, user_prompt):
|
118 |
with open(image_path, "rb") as imgf:
|
119 |
image_data = imgf.read()
|
|
|
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 |
|
|
|
|
|
|
|
|
|
|
|
190 |
st.markdown(result)
|
191 |
|
192 |
# Speak main result
|
|
|
194 |
st.write("### Audio Output for Main Result")
|
195 |
play_and_download_audio(audio_file_main)
|
196 |
|
|
|
197 |
# Speak references summaries
|
198 |
summaries_text = "Here are the summaries from the references: " + refs.replace('"','')
|
199 |
audio_file_refs = speak_with_edge_tts(summaries_text, voice="en-US-AriaNeural", rate=0, pitch=0)
|
|
|
211 |
audio_file_titles = speak_with_edge_tts(titles_text, voice="en-US-AriaNeural", rate=0, pitch=0)
|
212 |
st.write("### Audio Output for Paper Titles")
|
213 |
play_and_download_audio(audio_file_titles)
|
|
|
|
|
214 |
|
|
|
215 |
elapsed = time.time()-start
|
216 |
st.write(f"Elapsed: {elapsed:.2f} s")
|
217 |
fn = generate_filename(q,"md")
|
|
|
251 |
st.session_state.chat_history.append({"user":text,"claude":ans})
|
252 |
return ans
|
253 |
|
254 |
+
def create_zip_of_files():
|
255 |
+
# Include all .md and .mp3 files in the zip
|
256 |
+
md_files = glob.glob("*.md")
|
257 |
+
mp3_files = glob.glob("*.mp3")
|
258 |
+
all_files = md_files + mp3_files
|
259 |
zip_name = "all_files.zip"
|
260 |
with zipfile.ZipFile(zip_name,'w') as z:
|
261 |
+
for f in all_files:
|
262 |
+
z.write(f)
|
263 |
return zip_name
|
264 |
|
265 |
def get_media_html(p,typ="video",w="100%"):
|
|
|
269 |
else:
|
270 |
return f'<audio controls style="width:{w};"><source src="data:audio/mpeg;base64,{d}" type="audio/mpeg"></audio>'
|
271 |
|
272 |
+
def display_file_manager():
|
273 |
+
st.sidebar.title("π΅ Audio Files & Documents")
|
274 |
+
st.sidebar.markdown("Here you can find all recorded `.mp3` files and `.md` notes.")
|
275 |
+
|
276 |
+
# Display .mp3 files in the sidebar
|
277 |
+
mp3_files = sorted(glob.glob("*.mp3"), reverse=True)
|
278 |
+
if mp3_files:
|
279 |
+
st.sidebar.subheader("MP3 Files:")
|
280 |
+
for a in mp3_files:
|
281 |
+
with st.sidebar.expander(f"{os.path.basename(a)}"):
|
282 |
+
# Show audio player
|
283 |
+
st.sidebar.markdown(get_media_html(a,"audio"),unsafe_allow_html=True)
|
284 |
+
# Download link for the MP3 file
|
285 |
+
st.sidebar.markdown(get_download_link(a), unsafe_allow_html=True)
|
286 |
+
# Button to transcribe this file
|
287 |
+
if st.sidebar.button(f"Transcribe {os.path.basename(a)}"):
|
|
|
|
|
|
|
|
|
288 |
t = process_audio(a)
|
289 |
+
st.sidebar.write("Transcription:")
|
290 |
+
st.sidebar.write(t)
|
291 |
+
else:
|
292 |
+
st.sidebar.write("No MP3 files found.")
|
|
|
|
|
|
|
|
|
|
|
293 |
|
294 |
+
# Display .md files in the sidebar
|
295 |
+
st.sidebar.subheader("MD Files:")
|
296 |
+
files = sorted(glob.glob("*.md"), reverse=True)
|
297 |
+
if st.sidebar.button("π Delete All MD"):
|
298 |
for f in files: os.remove(f)
|
299 |
+
st.experimental_rerun()
|
300 |
+
# Download all as zip (including .mp3 and .md)
|
301 |
+
if st.sidebar.button("β¬οΈ Download All (.md and .mp3)"):
|
302 |
+
z = create_zip_of_files()
|
303 |
st.sidebar.markdown(get_download_link(z),unsafe_allow_html=True)
|
304 |
+
|
305 |
for f in files:
|
306 |
+
col1, col2, col3, col4 = st.sidebar.columns([1,3,1,1])
|
307 |
with col1:
|
308 |
+
if st.sidebar.button("π", key="v"+f):
|
309 |
+
st.session_state.current_file = f
|
310 |
+
c = open(f,'r',encoding='utf-8').read()
|
311 |
+
st.write("**Viewing file content:**")
|
312 |
st.write(c)
|
313 |
with col2:
|
314 |
+
st.sidebar.markdown(get_download_link(f),unsafe_allow_html=True)
|
315 |
with col3:
|
316 |
+
if st.sidebar.button("π", key="e"+f):
|
317 |
+
st.session_state.current_file = f
|
318 |
+
st.session_state.file_content = open(f,'r',encoding='utf-8').read()
|
319 |
with col4:
|
320 |
+
if st.sidebar.button("π", key="d"+f):
|
321 |
os.remove(f)
|
322 |
st.experimental_rerun()
|
323 |
+
|
324 |
def main():
|
325 |
st.sidebar.markdown("### π²BikeAIπ Multi-Agent Research AI")
|
326 |
tab_main = st.radio("Action:",["π€ Voice Input","πΈ Media Gallery","π Search ArXiv","π File Editor"],horizontal=True)
|
|
|
331 |
mycomponent = components.declare_component("mycomponent", path="mycomponent")
|
332 |
val = mycomponent(my_input_value="Hello")
|
333 |
if val:
|
|
|
334 |
user_input = val.strip()
|
335 |
if user_input:
|
336 |
if model_choice == "GPT-4o":
|
|
|
361 |
if tab_main == "π€ Voice Input":
|
362 |
st.subheader("π€ Voice Recognition")
|
363 |
user_text = st.text_area("Message:", height=100)
|
|
|
364 |
user_text = user_text.strip()
|
365 |
if st.button("Send π¨"):
|
366 |
if user_text:
|
|
|
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]:
|
402 |
+
imgs = glob.glob("*.png")+glob.glob("*.jpg")
|
403 |
+
if imgs:
|
404 |
+
c = st.slider("Cols",1,5,3)
|
405 |
+
cols = st.columns(c)
|
406 |
+
for i,f in enumerate(imgs):
|
407 |
+
with cols[i%c]:
|
408 |
+
st.image(Image.open(f),use_container_width=True)
|
409 |
+
if st.button(f"π Analyze {os.path.basename(f)}"):
|
410 |
+
a = process_image(f,"Describe this image.")
|
411 |
+
st.markdown(a)
|
412 |
+
else:
|
413 |
+
st.write("No images found.")
|
414 |
+
with tabs[1]:
|
415 |
+
vids = glob.glob("*.mp4")
|
416 |
+
if vids:
|
417 |
+
for v in vids:
|
418 |
+
with st.expander(f"π₯ {os.path.basename(v)}"):
|
419 |
+
st.markdown(get_media_html(v,"video"),unsafe_allow_html=True)
|
420 |
+
if st.button(f"Analyze {os.path.basename(v)}"):
|
421 |
+
a = process_video_with_gpt(v,"Describe video.")
|
422 |
+
st.markdown(a)
|
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)
|
|
|
435 |
if getattr(st.session_state,'current_file',None):
|
436 |
st.subheader(f"Editing: {st.session_state.current_file}")
|
437 |
new_text = st.text_area("Content:", st.session_state.file_content, height=300)
|
|
|
438 |
if st.button("Save"):
|
439 |
with open(st.session_state.current_file,'w',encoding='utf-8') as f:
|
440 |
f.write(new_text)
|
441 |
st.success("Updated!")
|
442 |
+
else:
|
443 |
+
st.write("Select a file from the sidebar to edit.")
|
444 |
|
445 |
display_file_manager()
|
446 |
|
447 |
|
448 |
if __name__=="__main__":
|
449 |
+
main()
|