awacke1 commited on
Commit
a5f7338
1 Parent(s): 1b24bfb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +183 -149
app.py CHANGED
@@ -34,8 +34,8 @@ from xml.etree import ElementTree as ET
34
  import streamlit.components.v1 as components # Import Streamlit Components for HTML5
35
 
36
 
37
- st.set_page_config(page_title="🐪Llama🦙Whisperer", layout="wide")
38
- st.markdown('(Inference Endpoints)[https://ui.endpoints.huggingface.co/awacke1/endpoints]')
39
 
40
  def add_Med_Licensing_Exam_Dataset():
41
  import streamlit as st
@@ -92,9 +92,9 @@ def add_Med_Licensing_Exam_Dataset():
92
  # 1. Constants and Top Level UI Variables
93
 
94
  # My Inference API Copy
95
- API_URL = 'https://qe55p8afio98s0u3.us-east-1.aws.endpoints.huggingface.cloud' # Dr Llama
96
  # Original:
97
- #API_URL = "https://api-inference.huggingface.co/models/meta-llama/Llama-2-7b-chat-hf"
98
  API_KEY = os.getenv('API_KEY')
99
  MODEL1="meta-llama/Llama-2-7b-chat-hf"
100
  MODEL1URL="https://huggingface.co/meta-llama/Llama-2-7b-chat-hf"
@@ -239,7 +239,8 @@ def generate_filename(prompt, file_type):
239
  central = pytz.timezone('US/Central')
240
  safe_date_time = datetime.now(central).strftime("%m%d_%H%M")
241
  replaced_prompt = prompt.replace(" ", "_").replace("\n", "_")
242
- safe_prompt = "".join(x for x in replaced_prompt if x.isalnum() or x == "_")[:45]
 
243
  return f"{safe_date_time}_{safe_prompt}.{file_type}"
244
 
245
  # 6. Speech transcription via OpenAI service
@@ -326,6 +327,8 @@ def get_table_download_link(file_path):
326
  mime_type = 'text/html'
327
  elif ext == '.md':
328
  mime_type = 'text/markdown'
 
 
329
  else:
330
  mime_type = 'application/octet-stream' # general binary data type
331
  href = f'<a href="data:{mime_type};base64,{b64}" target="_blank" download="{file_name}">{file_name}</a>'
@@ -506,19 +509,17 @@ def get_zip_download_link(zip_file):
506
 
507
  # 14. Inference Endpoints for Whisper (best fastest STT) on NVIDIA T4 and Llama (best fastest AGI LLM) on NVIDIA A10
508
  # My Inference Endpoint
509
- #API_URL_IE = f'https://tonpixzfvq3791u9.us-east-1.aws.endpoints.huggingface.cloud'
510
  # Original
511
- #API_URL_IE = "https://api-inference.huggingface.co/models/openai/whisper-small.en"
512
- # A10 Inference Endpoint for whisper large tests
513
- API_URL_IE = "https://hifdvffh2em0wn50.us-east-1.aws.endpoints.huggingface.cloud"
514
-
515
  MODEL2 = "openai/whisper-small.en"
516
  MODEL2_URL = "https://huggingface.co/openai/whisper-small.en"
517
  #headers = {
518
  # "Authorization": "Bearer XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
519
  # "Content-Type": "audio/wav"
520
  #}
521
- HF_KEY = os.getenv('HF_KEY')
 
522
  headers = {
523
  "Authorization": f"Bearer {HF_KEY}",
524
  "Content-Type": "audio/wav"
@@ -553,27 +554,28 @@ def transcribe_audio(filename):
553
  output = query(filename)
554
  return output
555
 
556
-
557
  def whisper_main():
558
- st.title("1🐪Llama🦙Whisperer")
559
- st.write("Record your speech and get the text.")
560
 
561
  # Audio, transcribe, GPT:
562
  filename = save_and_play_audio(audio_recorder)
563
  if filename is not None:
564
  transcription = transcribe_audio(filename)
565
- #try:
566
-
567
- transcript = transcription['text']
568
- #except:
569
- #st.write('Whisper model is asleep. Starting up now on T4 GPU - please give 5 minutes then retry as it scales up from zero to activate running container(s).')
 
 
 
 
 
 
 
 
570
 
571
- st.write(transcript)
572
- response = StreamLLMChatResponse(transcript)
573
- # st.write(response) - redundant with streaming result?
574
- filename = generate_filename(transcript, ".txt")
575
- create_file(filename, transcript, response, should_save)
576
- #st.sidebar.markdown(get_table_download_link(filename), unsafe_allow_html=True)
577
 
578
  import streamlit as st
579
 
@@ -581,130 +583,121 @@ import streamlit as st
581
  def StreamMedChatResponse(topic):
582
  st.write(f"Showing resources or questions related to: {topic}")
583
 
584
- def add_multi_system_agent_topics():
585
- with st.expander("Multi-System Agent AI Topics 🤖", expanded=True):
586
- st.markdown("🤖 **Explore Multi-System Agent AI Topics**: This section provides a variety of topics related to multi-system agent AI systems.")
587
 
588
- # Define multi-system agent AI topics and descriptions
589
  descriptions = {
590
- "Reinforcement Learning 🎮": "Questions related to reinforcement learning algorithms and applications 🕹️",
591
- "Natural Language Processing 🗣️": "Questions about natural language processing techniques and chatbot development 🗨️",
592
- "Multi-Agent Systems 🤝": "Questions pertaining to multi-agent systems and cooperative AI interactions 🤖",
593
- "Conversational AI 🗨️": "Questions on building conversational AI agents and chatbots for various platforms 💬",
594
- "Distributed AI Systems 🌐": "Questions about distributed AI systems and their implementation in networked environments 🌐",
595
- "AI Ethics and Bias 🤔": "Questions related to ethics and bias considerations in AI systems and decision-making 🧠",
596
- "AI in Healthcare 🏥": "Questions about the application of AI in healthcare and medical diagnosis 🩺",
597
- "AI in Autonomous Vehicles 🚗": "Questions on the use of AI in autonomous vehicles and self-driving technology 🚗"
598
  }
599
 
600
  # Create columns
601
  col1, col2, col3, col4 = st.columns([1, 1, 1, 1], gap="small")
602
 
603
  # Add buttons to columns
604
- if col1.button("Reinforcement Learning 🎮"):
605
- st.write(descriptions["Reinforcement Learning 🎮"])
606
- StreamLLMChatResponse(descriptions["Reinforcement Learning 🎮"])
607
 
608
- if col2.button("Natural Language Processing 🗣️"):
609
- st.write(descriptions["Natural Language Processing 🗣️"])
610
- StreamLLMChatResponse(descriptions["Natural Language Processing 🗣️"])
611
 
612
- if col3.button("Multi-Agent Systems 🤝"):
613
- st.write(descriptions["Multi-Agent Systems 🤝"])
614
- StreamLLMChatResponse(descriptions["Multi-Agent Systems 🤝"])
615
 
616
- if col4.button("Conversational AI 🗨️"):
617
- st.write(descriptions["Conversational AI 🗨️"])
618
- StreamLLMChatResponse(descriptions["Conversational AI 🗨️"])
619
 
620
  col5, col6, col7, col8 = st.columns([1, 1, 1, 1], gap="small")
621
 
622
- if col5.button("Distributed AI Systems 🌐"):
623
- st.write(descriptions["Distributed AI Systems 🌐"])
624
- StreamLLMChatResponse(descriptions["Distributed AI Systems 🌐"])
625
-
626
- if col6.button("AI Ethics and Bias 🤔"):
627
- st.write(descriptions["AI Ethics and Bias 🤔"])
628
- StreamLLMChatResponse(descriptions["AI Ethics and Bias 🤔"])
629
-
630
- if col7.button("AI in Healthcare 🏥"):
631
- st.write(descriptions["AI in Healthcare 🏥"])
632
- StreamLLMChatResponse(descriptions["AI in Healthcare 🏥"])
633
 
634
- if col8.button("AI in Autonomous Vehicles 🚗"):
635
- st.write(descriptions["AI in Autonomous Vehicles 🚗"])
636
- StreamLLMChatResponse(descriptions["AI in Autonomous Vehicles 🚗"])
637
 
 
 
 
 
638
 
639
  # 17. Main
640
  def main():
641
 
642
- st.title("Try Some Topics:")
643
  prompt = f"Write ten funny jokes that are tweet length stories that make you laugh. Show as markdown outline with emojis for each."
644
 
645
  # Add Wit and Humor buttons
646
  # add_witty_humor_buttons()
647
- # Calling the function to add the multi-system agent AI topics buttons
648
- add_multi_system_agent_topics()
649
 
650
- example_input = st.text_input("Enter your example text:", value=prompt, help="Enter text to get a response from DromeLlama.")
651
- if st.button("Run Prompt With DromeLlama", help="Click to run the prompt."):
652
- try:
653
- StreamLLMChatResponse(example_input)
654
- except:
655
- st.write('DromeLlama is asleep. Starting up now on A10 - please give 5 minutes then retry as KEDA scales up from zero to activate running container(s).')
656
-
657
- openai.api_key = os.getenv('OPENAI_KEY')
658
- menu = ["txt", "htm", "xlsx", "csv", "md", "py"]
659
- choice = st.sidebar.selectbox("Output File Type:", menu)
660
- model_choice = st.sidebar.radio("Select Model:", ('gpt-3.5-turbo', 'gpt-3.5-turbo-0301'))
661
- user_prompt = st.text_area("Enter prompts, instructions & questions:", '', height=100)
662
- collength, colupload = st.columns([2,3]) # adjust the ratio as needed
663
- with collength:
664
- max_length = st.slider("File section length for large files", min_value=1000, max_value=128000, value=12000, step=1000)
665
- with colupload:
666
- uploaded_file = st.file_uploader("Add a file for context:", type=["pdf", "xml", "json", "xlsx", "csv", "html", "htm", "md", "txt"])
667
- document_sections = deque()
668
- document_responses = {}
669
- if uploaded_file is not None:
670
- file_content = read_file_content(uploaded_file, max_length)
671
- document_sections.extend(divide_document(file_content, max_length))
672
- if len(document_sections) > 0:
673
- if st.button("👁️ View Upload"):
674
- st.markdown("**Sections of the uploaded file:**")
675
- for i, section in enumerate(list(document_sections)):
676
- st.markdown(f"**Section {i+1}**\n{section}")
677
- st.markdown("**Chat with the model:**")
678
- for i, section in enumerate(list(document_sections)):
679
- if i in document_responses:
680
- st.markdown(f"**Section {i+1}**\n{document_responses[i]}")
681
- else:
682
- if st.button(f"Chat about Section {i+1}"):
683
- st.write('Reasoning with your inputs...')
684
- response = chat_with_model(user_prompt, section, model_choice)
685
- st.write('Response:')
686
- st.write(response)
687
- document_responses[i] = response
688
- filename = generate_filename(f"{user_prompt}_section_{i+1}", choice)
689
- create_file(filename, user_prompt, response, should_save)
690
- st.sidebar.markdown(get_table_download_link(filename), unsafe_allow_html=True)
691
- if st.button('💬 Chat'):
692
- st.write('Reasoning with your inputs...')
693
- user_prompt_sections = divide_prompt(user_prompt, max_length)
694
- full_response = ''
695
- for prompt_section in user_prompt_sections:
696
- response = chat_with_model(prompt_section, ''.join(list(document_sections)), model_choice)
697
- full_response += response + '\n' # Combine the responses
698
- response = full_response
699
- st.write('Response:')
700
- st.write(response)
701
- filename = generate_filename(user_prompt, choice)
702
- create_file(filename, user_prompt, response, should_save)
703
- st.sidebar.markdown(get_table_download_link(filename), unsafe_allow_html=True)
704
 
705
- # Compose a file sidebar of past encounters
706
- all_files = glob.glob("*.*")
707
- all_files = [file for file in all_files if len(os.path.splitext(file)[0]) >= 20] # exclude files with short names
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
708
  all_files.sort(key=lambda x: (os.path.splitext(x)[1], x), reverse=True) # sort by file type and file name in descending order
709
  if st.sidebar.button("🗑 Delete All"):
710
  for file in all_files:
@@ -762,36 +755,77 @@ def main():
762
 
763
  st.experimental_rerun()
764
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
765
  # Feedback
766
  # Step: Give User a Way to Upvote or Downvote
767
- feedback = st.radio("Step 8: Give your feedback", ("👍 Upvote", "👎 Downvote"))
768
- if feedback == "👍 Upvote":
769
- st.write("You upvoted 👍. Thank you for your feedback!")
770
- else:
771
- st.write("You downvoted 👎. Thank you for your feedback!")
772
-
773
- load_dotenv()
774
- st.write(css, unsafe_allow_html=True)
775
- st.header("Chat with documents :books:")
776
- user_question = st.text_input("Ask a question about your documents:")
777
- if user_question:
778
- process_user_input(user_question)
779
- with st.sidebar:
780
- st.subheader("Your documents")
781
- docs = st.file_uploader("import documents", accept_multiple_files=True)
782
- with st.spinner("Processing"):
783
- raw = pdf2txt(docs)
784
- if len(raw) > 0:
785
- length = str(len(raw))
786
- text_chunks = txt2chunks(raw)
787
- vectorstore = vector_store(text_chunks)
788
- st.session_state.conversation = get_chain(vectorstore)
789
- st.markdown('# AI Search Index of Length:' + length + ' Created.') # add timing
790
- filename = generate_filename(raw, 'txt')
791
- create_file(filename, raw, '', should_save)
 
 
792
 
793
  # 18. Run AI Pipeline
794
  if __name__ == "__main__":
795
  whisper_main()
796
  main()
797
- add_Med_Licensing_Exam_Dataset()
 
34
  import streamlit.components.v1 as components # Import Streamlit Components for HTML5
35
 
36
 
37
+ st.set_page_config(page_title="🐪Llama Whisperer🦙 Voice Chat🌟", layout="wide")
38
+
39
 
40
  def add_Med_Licensing_Exam_Dataset():
41
  import streamlit as st
 
92
  # 1. Constants and Top Level UI Variables
93
 
94
  # My Inference API Copy
95
+ # API_URL = 'https://qe55p8afio98s0u3.us-east-1.aws.endpoints.huggingface.cloud' # Dr Llama
96
  # Original:
97
+ API_URL = "https://api-inference.huggingface.co/models/meta-llama/Llama-2-7b-chat-hf"
98
  API_KEY = os.getenv('API_KEY')
99
  MODEL1="meta-llama/Llama-2-7b-chat-hf"
100
  MODEL1URL="https://huggingface.co/meta-llama/Llama-2-7b-chat-hf"
 
239
  central = pytz.timezone('US/Central')
240
  safe_date_time = datetime.now(central).strftime("%m%d_%H%M")
241
  replaced_prompt = prompt.replace(" ", "_").replace("\n", "_")
242
+ safe_prompt = "".join(x for x in replaced_prompt if x.isalnum() or x == "_")[:255] # 255 is linux max, 260 is windows max
243
+ #safe_prompt = "".join(x for x in replaced_prompt if x.isalnum() or x == "_")[:45]
244
  return f"{safe_date_time}_{safe_prompt}.{file_type}"
245
 
246
  # 6. Speech transcription via OpenAI service
 
327
  mime_type = 'text/html'
328
  elif ext == '.md':
329
  mime_type = 'text/markdown'
330
+ elif ext == '.wav':
331
+ mime_type = 'audio/wav'
332
  else:
333
  mime_type = 'application/octet-stream' # general binary data type
334
  href = f'<a href="data:{mime_type};base64,{b64}" target="_blank" download="{file_name}">{file_name}</a>'
 
509
 
510
  # 14. Inference Endpoints for Whisper (best fastest STT) on NVIDIA T4 and Llama (best fastest AGI LLM) on NVIDIA A10
511
  # My Inference Endpoint
512
+ API_URL_IE = f'https://tonpixzfvq3791u9.us-east-1.aws.endpoints.huggingface.cloud'
513
  # Original
514
+ API_URL_IE = "https://api-inference.huggingface.co/models/openai/whisper-small.en"
 
 
 
515
  MODEL2 = "openai/whisper-small.en"
516
  MODEL2_URL = "https://huggingface.co/openai/whisper-small.en"
517
  #headers = {
518
  # "Authorization": "Bearer XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
519
  # "Content-Type": "audio/wav"
520
  #}
521
+ # HF_KEY = os.getenv('HF_KEY')
522
+ HF_KEY = st.secrets['HF_KEY']
523
  headers = {
524
  "Authorization": f"Bearer {HF_KEY}",
525
  "Content-Type": "audio/wav"
 
554
  output = query(filename)
555
  return output
556
 
 
557
  def whisper_main():
558
+ #st.title("Speech to Text")
559
+ #st.write("Record your speech and get the text.")
560
 
561
  # Audio, transcribe, GPT:
562
  filename = save_and_play_audio(audio_recorder)
563
  if filename is not None:
564
  transcription = transcribe_audio(filename)
565
+ try:
566
+ transcript = transcription['text']
567
+ st.write(transcript)
568
+ response = StreamLLMChatResponse(transcript)
569
+ filename_txt = generate_filename(transcript, ".txt")
570
+ create_file(filename_txt, transcript, response, should_save)
571
+ filename_wav = filename_txt.replace('.txt', '.wav')
572
+ import shutil
573
+ shutil.copyfile(filename, filename_wav)
574
+ if os.path.exists(filename):
575
+ os.remove(filename)
576
+ except:
577
+ st.write('Starting Whisper Model on GPU. Please retry in 30 seconds.')
578
 
 
 
 
 
 
 
579
 
580
  import streamlit as st
581
 
 
583
  def StreamMedChatResponse(topic):
584
  st.write(f"Showing resources or questions related to: {topic}")
585
 
586
+ def add_medical_exam_buttons():
587
+ with st.expander("Medical Licensing Exam Topics 📚", expanded=False):
588
+ st.markdown("🩺 **Important**: This section provides a variety of medical topics that are often encountered in medical licensing exams.")
589
 
590
+ # Define medical exam terminology descriptions
591
  descriptions = {
592
+ "Ultrasound with Doppler 🌊": "3 Questions and Answers with emojis about Doppler Ultrasound imaging techniques 🎥",
593
+ "Oseltamivir 🦠": "3 Questions and Answers with emojis about the antiviral medication Oseltamivir 💊",
594
+ "IM Epinephrine 💉": "3 Questions and Answers with emojis about intramuscular administration of epinephrine 💪",
595
+ "Hypokalemia 🍌": "3 Questions and Answers with emojis about low potassium levels in blood 🩸",
596
+ "Succinylcholine 💊": "3 Questions and Answers with emojis on the use and side-effects of Succinylcholine 🚑",
597
+ "Phosphoinositol System 🧬": "3 Questions and Answers with emojis about the Phosphoinositol signalling system 🛠",
598
+ "Ramipril 💊": "3 Questions and Answers with emojis related to the ACE inhibitor Ramipril 🩺"
 
599
  }
600
 
601
  # Create columns
602
  col1, col2, col3, col4 = st.columns([1, 1, 1, 1], gap="small")
603
 
604
  # Add buttons to columns
605
+ if col1.button("Ultrasound with Doppler 🌊"):
606
+ StreamLLMChatResponse(descriptions["Ultrasound with Doppler 🌊"])
 
607
 
608
+ if col2.button("Oseltamivir 🦠"):
609
+ StreamLLMChatResponse(descriptions["Oseltamivir 🦠"])
 
610
 
611
+ if col3.button("IM Epinephrine 💉"):
612
+ StreamLLMChatResponse(descriptions["IM Epinephrine 💉"])
 
613
 
614
+ if col4.button("Hypokalemia 🍌"):
615
+ StreamLLMChatResponse(descriptions["Hypokalemia 🍌"])
 
616
 
617
  col5, col6, col7, col8 = st.columns([1, 1, 1, 1], gap="small")
618
 
619
+ if col5.button("Succinylcholine 💊"):
620
+ StreamLLMChatResponse(descriptions["Succinylcholine 💊"])
 
 
 
 
 
 
 
 
 
621
 
622
+ if col6.button("Phosphoinositol System 🧬"):
623
+ StreamLLMChatResponse(descriptions["Phosphoinositol System 🧬"])
 
624
 
625
+ if col7.button("Ramipril 💊"):
626
+ StreamLLMChatResponse(descriptions["Ramipril 💊"])
627
+
628
+
629
 
630
  # 17. Main
631
  def main():
632
 
633
+ #st.title("GAIA - Medical License Exam Testing")
634
  prompt = f"Write ten funny jokes that are tweet length stories that make you laugh. Show as markdown outline with emojis for each."
635
 
636
  # Add Wit and Humor buttons
637
  # add_witty_humor_buttons()
638
+ add_medical_exam_buttons()
 
639
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
640
 
641
+ with st.expander("Prompts 📚", expanded=False):
642
+
643
+ example_input = st.text_input("Enter your example text:", value=prompt, help="Enter text to get a response from DromeLlama.")
644
+ if st.button("Run Prompt With DromeLlama", help="Click to run the prompt."):
645
+ try:
646
+ StreamLLMChatResponse(example_input)
647
+ except:
648
+ st.write('DromeLlama is asleep. Starting up now on A10 - please give 5 minutes then retry as KEDA scales up from zero to activate running container(s).')
649
+
650
+ openai.api_key = os.getenv('OPENAI_KEY')
651
+ menu = ["txt", "htm", "xlsx", "csv", "md", "py"]
652
+ choice = st.sidebar.selectbox("Output File Type:", menu)
653
+ model_choice = st.sidebar.radio("Select Model:", ('gpt-3.5-turbo', 'gpt-3.5-turbo-0301'))
654
+ user_prompt = st.text_area("Enter prompts, instructions & questions:", '', height=100)
655
+ collength, colupload = st.columns([2,3]) # adjust the ratio as needed
656
+ with collength:
657
+ max_length = st.slider("File section length for large files", min_value=1000, max_value=128000, value=12000, step=1000)
658
+ with colupload:
659
+ uploaded_file = st.file_uploader("Add a file for context:", type=["pdf", "xml", "json", "xlsx", "csv", "html", "htm", "md", "txt"])
660
+ document_sections = deque()
661
+ document_responses = {}
662
+ if uploaded_file is not None:
663
+ file_content = read_file_content(uploaded_file, max_length)
664
+ document_sections.extend(divide_document(file_content, max_length))
665
+ if len(document_sections) > 0:
666
+ if st.button("👁️ View Upload"):
667
+ st.markdown("**Sections of the uploaded file:**")
668
+ for i, section in enumerate(list(document_sections)):
669
+ st.markdown(f"**Section {i+1}**\n{section}")
670
+ st.markdown("**Chat with the model:**")
671
+ for i, section in enumerate(list(document_sections)):
672
+ if i in document_responses:
673
+ st.markdown(f"**Section {i+1}**\n{document_responses[i]}")
674
+ else:
675
+ if st.button(f"Chat about Section {i+1}"):
676
+ st.write('Reasoning with your inputs...')
677
+ response = chat_with_model(user_prompt, section, model_choice)
678
+ st.write('Response:')
679
+ st.write(response)
680
+ document_responses[i] = response
681
+ filename = generate_filename(f"{user_prompt}_section_{i+1}", choice)
682
+ create_file(filename, user_prompt, response, should_save)
683
+ st.sidebar.markdown(get_table_download_link(filename), unsafe_allow_html=True)
684
+ if st.button('💬 Chat'):
685
+ st.write('Reasoning with your inputs...')
686
+ user_prompt_sections = divide_prompt(user_prompt, max_length)
687
+ full_response = ''
688
+ for prompt_section in user_prompt_sections:
689
+ response = chat_with_model(prompt_section, ''.join(list(document_sections)), model_choice)
690
+ full_response += response + '\n' # Combine the responses
691
+ response = full_response
692
+ st.write('Response:')
693
+ st.write(response)
694
+ filename = generate_filename(user_prompt, choice)
695
+ create_file(filename, user_prompt, response, should_save)
696
+ st.sidebar.markdown(get_table_download_link(filename), unsafe_allow_html=True)
697
+
698
+ # Compose a file sidebar of markdown md files:
699
+ all_files = glob.glob("*.md")
700
+ all_files = [file for file in all_files if len(os.path.splitext(file)[0]) >= 10] # exclude files with short names
701
  all_files.sort(key=lambda x: (os.path.splitext(x)[1], x), reverse=True) # sort by file type and file name in descending order
702
  if st.sidebar.button("🗑 Delete All"):
703
  for file in all_files:
 
755
 
756
  st.experimental_rerun()
757
 
758
+
759
+ # Function to encode file to base64
760
+ def get_base64_encoded_file(file_path):
761
+ with open(file_path, "rb") as file:
762
+ return base64.b64encode(file.read()).decode()
763
+
764
+ # Function to create a download link
765
+ def get_audio_download_link(file_path):
766
+ base64_file = get_base64_encoded_file(file_path)
767
+ return f'<a href="data:file/wav;base64,{base64_file}" download="{os.path.basename(file_path)}">⬇️ Download Audio</a>'
768
+
769
+ # Compose a file sidebar of past encounters
770
+ all_files = glob.glob("*.wav")
771
+ all_files = [file for file in all_files if len(os.path.splitext(file)[0]) >= 10] # exclude files with short names
772
+ all_files.sort(key=lambda x: (os.path.splitext(x)[1], x), reverse=True) # sort by file type and file name in descending order
773
+
774
+ filekey = 'del' + str(file)
775
+ if st.sidebar.button("🗑 Delete All", key=filekey):
776
+ for file in all_files:
777
+ os.remove(file)
778
+ st.experimental_rerun()
779
+
780
+ for file in all_files:
781
+ col1, col2 = st.sidebar.columns([6, 1]) # adjust the ratio as needed
782
+ with col1:
783
+ st.markdown(file)
784
+ if st.button("🎵", key="play_" + file): # play emoji button
785
+ audio_file = open(file, 'rb')
786
+ audio_bytes = audio_file.read()
787
+ st.audio(audio_bytes, format='audio/wav')
788
+ #st.markdown(get_audio_download_link(file), unsafe_allow_html=True)
789
+ #st.text_input(label="", value=file)
790
+ with col2:
791
+ if st.button("🗑", key="delete_" + file):
792
+ os.remove(file)
793
+ st.experimental_rerun()
794
+
795
+
796
+
797
  # Feedback
798
  # Step: Give User a Way to Upvote or Downvote
799
+ with st.expander("Give your feedback 👍", expanded=False):
800
+
801
+ feedback = st.radio("Step 8: Give your feedback", ("👍 Upvote", "👎 Downvote"))
802
+ if feedback == "👍 Upvote":
803
+ st.write("You upvoted 👍. Thank you for your feedback!")
804
+ else:
805
+ st.write("You downvoted 👎. Thank you for your feedback!")
806
+
807
+ load_dotenv()
808
+ st.write(css, unsafe_allow_html=True)
809
+ st.header("Chat with documents :books:")
810
+ user_question = st.text_input("Ask a question about your documents:")
811
+ if user_question:
812
+ process_user_input(user_question)
813
+ with st.sidebar:
814
+ st.subheader("Your documents")
815
+ docs = st.file_uploader("import documents", accept_multiple_files=True)
816
+ with st.spinner("Processing"):
817
+ raw = pdf2txt(docs)
818
+ if len(raw) > 0:
819
+ length = str(len(raw))
820
+ text_chunks = txt2chunks(raw)
821
+ vectorstore = vector_store(text_chunks)
822
+ st.session_state.conversation = get_chain(vectorstore)
823
+ st.markdown('# AI Search Index of Length:' + length + ' Created.') # add timing
824
+ filename = generate_filename(raw, 'txt')
825
+ create_file(filename, raw, '', should_save)
826
 
827
  # 18. Run AI Pipeline
828
  if __name__ == "__main__":
829
  whisper_main()
830
  main()
831
+ #add_Med_Licensing_Exam_Dataset()