awacke1 commited on
Commit
6e8578b
·
verified ·
1 Parent(s): a7ab48f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -9
app.py CHANGED
@@ -131,7 +131,6 @@ def process_text(text_input):
131
  filename = generate_filename(text_input, "md")
132
  create_and_save_file(response, "md", text_input, should_save=should_save)
133
  st.session_state.messages.append({"role": "assistant", "content": response})
134
- st.rerun()
135
 
136
  # Image Processing
137
  def process_image(image_input, user_prompt):
@@ -154,7 +153,6 @@ def process_image(image_input, user_prompt):
154
  image_response = response.choices[0].message.content
155
  filename = generate_filename(user_prompt, "md", original_name)
156
  create_and_save_file(image_response, "md", user_prompt, original_name, should_save=should_save)
157
- st.rerun()
158
  return image_response
159
 
160
  # Audio Processing
@@ -188,7 +186,6 @@ def process_audio(audio_input, text_input=''):
188
  filename = generate_filename(transcription, "md")
189
  create_and_save_file(response, "md", text_input, should_save=should_save)
190
  st.session_state.messages.append({"role": "assistant", "content": response})
191
- st.rerun()
192
  except openai.BadRequestError as e:
193
  st.error(f"Audio processing error: {str(e)}")
194
 
@@ -257,7 +254,6 @@ def process_audio_and_video(video_input):
257
  st.markdown(result)
258
  filename = generate_filename(transcript, "md")
259
  create_and_save_file(result, "md", "Video summary", should_save=should_save)
260
- st.rerun()
261
  except openai.BadRequestError as e:
262
  st.error(f"Video audio processing error: {str(e)}")
263
  else:
@@ -277,7 +273,6 @@ def search_arxiv(query):
277
  filename = generate_filename(query, "md")
278
  create_and_save_file(result, "md", query, should_save=should_save)
279
  st.session_state.messages.append({"role": "assistant", "content": result})
280
- st.rerun()
281
  return result
282
 
283
  # RAG PDF Gallery
@@ -471,8 +466,16 @@ def main():
471
 
472
  if option == "Text":
473
  default_text = "emojis in markdown. Maybe a buckeyball feature rating comparing them against each other in markdown emoji outline or tables."
474
- text_input = st.text_input("Enter your text:", value=default_text)
475
- if text_input:
 
 
 
 
 
 
 
 
476
  with st.spinner("Processing..."):
477
  process_text(text_input)
478
 
@@ -494,6 +497,7 @@ def main():
494
  image_response = process_image(image_input, text_input)
495
  with st.chat_message("ai", avatar="🦖"):
496
  st.markdown(image_response)
 
497
 
498
  elif option == "Audio":
499
  text_input = st.text_input("Audio Prompt:", value="Summarize this audio transcription in Markdown.")
@@ -502,10 +506,13 @@ def main():
502
  if audio_bytes:
503
  with open("recorded_audio.wav", "wb") as f:
504
  f.write(audio_bytes)
505
- process_audio(audio_bytes, text_input)
 
 
506
  elif audio_input and text_input:
507
  with st.spinner("Processing..."):
508
  process_audio(audio_input, text_input)
 
509
 
510
  elif option == "Video":
511
  text_input = st.text_input("Video Prompt:", value="Summarize this video and its transcription in Markdown.")
@@ -516,6 +523,7 @@ def main():
516
  else:
517
  with st.spinner("Processing..."):
518
  process_audio_and_video(video_input)
 
519
 
520
  elif option == "ArXiv Search":
521
  query = st.text_input("AI Search ArXiv Scholarly Articles:")
@@ -523,6 +531,7 @@ def main():
523
  with st.spinner("Searching ArXiv..."):
524
  result = search_arxiv(query)
525
  st.markdown(result)
 
526
 
527
  elif option == "RAG PDF Gallery":
528
  rag_pdf_gallery()
@@ -533,7 +542,9 @@ for message in st.session_state.messages:
533
  st.markdown(message["content"])
534
 
535
  if prompt := st.chat_input("GPT-4o Multimodal ChatBot - What can I help you with?"):
536
- process_text(prompt)
 
 
537
 
538
  FileSidebar()
539
  main()
 
131
  filename = generate_filename(text_input, "md")
132
  create_and_save_file(response, "md", text_input, should_save=should_save)
133
  st.session_state.messages.append({"role": "assistant", "content": response})
 
134
 
135
  # Image Processing
136
  def process_image(image_input, user_prompt):
 
153
  image_response = response.choices[0].message.content
154
  filename = generate_filename(user_prompt, "md", original_name)
155
  create_and_save_file(image_response, "md", user_prompt, original_name, should_save=should_save)
 
156
  return image_response
157
 
158
  # Audio Processing
 
186
  filename = generate_filename(transcription, "md")
187
  create_and_save_file(response, "md", text_input, should_save=should_save)
188
  st.session_state.messages.append({"role": "assistant", "content": response})
 
189
  except openai.BadRequestError as e:
190
  st.error(f"Audio processing error: {str(e)}")
191
 
 
254
  st.markdown(result)
255
  filename = generate_filename(transcript, "md")
256
  create_and_save_file(result, "md", "Video summary", should_save=should_save)
 
257
  except openai.BadRequestError as e:
258
  st.error(f"Video audio processing error: {str(e)}")
259
  else:
 
273
  filename = generate_filename(query, "md")
274
  create_and_save_file(result, "md", query, should_save=should_save)
275
  st.session_state.messages.append({"role": "assistant", "content": result})
 
276
  return result
277
 
278
  # RAG PDF Gallery
 
466
 
467
  if option == "Text":
468
  default_text = "emojis in markdown. Maybe a buckeyball feature rating comparing them against each other in markdown emoji outline or tables."
469
+ col1, col2 = st.columns([1, 5])
470
+ with col1:
471
+ if st.button("📝 MD", key="md_button"):
472
+ st.session_state["text_input"] = default_text
473
+ with st.spinner("Processing..."):
474
+ process_text(default_text)
475
+ st.rerun()
476
+ with col2:
477
+ text_input = st.text_input("Enter your text:", value=st.session_state.get("text_input", ""), key="text_input_field")
478
+ if text_input and text_input != st.session_state.get("text_input", ""): # Only process if changed
479
  with st.spinner("Processing..."):
480
  process_text(text_input)
481
 
 
497
  image_response = process_image(image_input, text_input)
498
  with st.chat_message("ai", avatar="🦖"):
499
  st.markdown(image_response)
500
+ st.rerun()
501
 
502
  elif option == "Audio":
503
  text_input = st.text_input("Audio Prompt:", value="Summarize this audio transcription in Markdown.")
 
506
  if audio_bytes:
507
  with open("recorded_audio.wav", "wb") as f:
508
  f.write(audio_bytes)
509
+ with st.spinner("Processing..."):
510
+ process_audio(audio_bytes, text_input)
511
+ st.rerun()
512
  elif audio_input and text_input:
513
  with st.spinner("Processing..."):
514
  process_audio(audio_input, text_input)
515
+ st.rerun()
516
 
517
  elif option == "Video":
518
  text_input = st.text_input("Video Prompt:", value="Summarize this video and its transcription in Markdown.")
 
523
  else:
524
  with st.spinner("Processing..."):
525
  process_audio_and_video(video_input)
526
+ st.rerun()
527
 
528
  elif option == "ArXiv Search":
529
  query = st.text_input("AI Search ArXiv Scholarly Articles:")
 
531
  with st.spinner("Searching ArXiv..."):
532
  result = search_arxiv(query)
533
  st.markdown(result)
534
+ st.rerun()
535
 
536
  elif option == "RAG PDF Gallery":
537
  rag_pdf_gallery()
 
542
  st.markdown(message["content"])
543
 
544
  if prompt := st.chat_input("GPT-4o Multimodal ChatBot - What can I help you with?"):
545
+ with st.spinner("Processing..."):
546
+ process_text(prompt)
547
+ st.rerun()
548
 
549
  FileSidebar()
550
  main()