awacke1 commited on
Commit
e39eec6
1 Parent(s): a795c99

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +228 -161
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"
@@ -104,7 +104,7 @@ headers = {
104
  "Content-Type": "application/json"
105
  }
106
  key = os.getenv('OPENAI_API_KEY')
107
- prompt = f"Write instructions to teach anyone to write a discharge plan. List the entities, features and relationships to CCDA and FHIR objects in boldface."
108
  should_save = st.sidebar.checkbox("💾 Save", value=True, help="Save your session data.")
109
 
110
  # 2. Prompt label button demo for LLM
@@ -128,30 +128,30 @@ def add_witty_humor_buttons():
128
  col1, col2, col3 = st.columns([1, 1, 1], gap="small")
129
 
130
  # Add buttons to columns
131
- if col1.button("Generate Limericks 😂"):
132
  StreamLLMChatResponse(descriptions["Generate Limericks 😂"])
133
 
134
  if col2.button("Wise Quotes 🧙"):
135
  StreamLLMChatResponse(descriptions["Wise Quotes 🧙"])
136
 
137
- if col3.button("Funny Rhymes 🎤"):
138
- StreamLLMChatResponse(descriptions["Funny Rhymes 🎤"])
139
 
140
  col4, col5, col6 = st.columns([1, 1, 1], gap="small")
141
 
142
- if col4.button("Medical Jokes 💉"):
143
- StreamLLMChatResponse(descriptions["Medical Jokes 💉"])
144
 
145
  if col5.button("Minnesota Humor ❄️"):
146
  StreamLLMChatResponse(descriptions["Minnesota Humor ❄️"])
147
 
148
- if col6.button("Top Funny Stories 📖"):
149
- StreamLLMChatResponse(descriptions["Top Funny Stories 📖"])
150
 
151
  col7 = st.columns(1, gap="small")
152
 
153
- if col7[0].button("More Funny Rhymes 🎙️"):
154
- StreamLLMChatResponse(descriptions["More Funny Rhymes 🎙️"])
155
 
156
  def SpeechSynthesis(result):
157
  documentHTML5='''
@@ -180,7 +180,7 @@ def SpeechSynthesis(result):
180
  </html>
181
  '''
182
 
183
- components.html(documentHTML5, width=1280, height=1024)
184
  #return result
185
 
186
 
@@ -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,132 +583,156 @@ 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:
711
  os.remove(file)
712
  st.experimental_rerun()
@@ -762,36 +788,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"
 
104
  "Content-Type": "application/json"
105
  }
106
  key = os.getenv('OPENAI_API_KEY')
107
+ prompt = f"Write instructions to teach discharge planning along with guidelines and patient education. List entities, features and relationships to CCDA and FHIR objects in boldface."
108
  should_save = st.sidebar.checkbox("💾 Save", value=True, help="Save your session data.")
109
 
110
  # 2. Prompt label button demo for LLM
 
128
  col1, col2, col3 = st.columns([1, 1, 1], gap="small")
129
 
130
  # Add buttons to columns
131
+ if col1.button("Wise Limericks 😂"):
132
  StreamLLMChatResponse(descriptions["Generate Limericks 😂"])
133
 
134
  if col2.button("Wise Quotes 🧙"):
135
  StreamLLMChatResponse(descriptions["Wise Quotes 🧙"])
136
 
137
+ #if col3.button("Funny Rhymes 🎤"):
138
+ # StreamLLMChatResponse(descriptions["Funny Rhymes 🎤"])
139
 
140
  col4, col5, col6 = st.columns([1, 1, 1], gap="small")
141
 
142
+ if col4.button("Top Ten Funniest Clean Jokes 💉"):
143
+ StreamLLMChatResponse(descriptions["Top Ten Funniest Clean Jokes 💉"])
144
 
145
  if col5.button("Minnesota Humor ❄️"):
146
  StreamLLMChatResponse(descriptions["Minnesota Humor ❄️"])
147
 
148
+ if col6.button("Origins of Medical Science True Stories"):
149
+ StreamLLMChatResponse(descriptions["Origins of Medical Science True Stories"])
150
 
151
  col7 = st.columns(1, gap="small")
152
 
153
+ if col7[0].button("Top Ten Best Write a streamlit python program prompts to build AI programs. 🎙️"):
154
+ StreamLLMChatResponse(descriptions["Top Ten Best Write a streamlit python program prompts to build AI programs. 🎙️"])
155
 
156
  def SpeechSynthesis(result):
157
  documentHTML5='''
 
180
  </html>
181
  '''
182
 
183
+ components.html(documentHTML5, width=1280, height=500)
184
  #return result
185
 
186
 
 
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
 
587
+
588
+ def add_medical_exam_buttons():
589
+ # Medical exam terminology descriptions
590
+ descriptions = {
591
+ "White Blood Cells 🌊": "3 Q&A with emojis about types, facts, function, inputs and outputs of white blood cells 🎥",
592
+ "CT Imaging🦠": "3 Q&A with emojis on CT Imaging post surgery, how to, what to look for 💊",
593
+ "Hematoma 💉": "3 Q&A with emojis about hematoma and infection care and study including bacteria cultures and tests or labs💪",
594
+ "Post Surgery Wound Care 🍌": "3 Q&A with emojis on wound care, and good bedside manner 🩸",
595
+ "Healing and humor 💊": "3 Q&A with emojis on stories and humor about healing and caregiving 🚑",
596
+ "Psychology of bedside manner 🧬": "3 Q&A with emojis on bedside manner and how to make patients feel at ease🛠",
597
+ "CT scan 💊": "3 Q&A with analysis on infection using CT scan and packing for skin, cellulitus and fascia 🩺"
598
+ }
599
+
600
+ # Expander for medical topics
601
+ with st.expander("Medical Licensing Exam Topics 📚", expanded=False):
602
+ st.markdown("🩺 **Important**: Variety of topics for medical licensing exams.")
603
+
604
+ # Create buttons for each description with unique keys
605
+ for idx, (label, content) in enumerate(descriptions.items()):
606
+ button_key = f"button_{idx}"
607
+ if st.button(label, key=button_key):
608
+ st.write(f"Running {label}")
609
+ input='Create markdown outline for definition of topic ' + label + ' also short quiz with appropriate emojis and definitions for: ' + content
610
+ response=StreamLLMChatResponse(input)
611
+ filename = generate_filename(response, 'txt')
612
+ create_file(filename, input, response, should_save)
613
+
614
+ def add_medical_exam_buttons2():
615
+ with st.expander("Medical Licensing Exam Topics 📚", expanded=False):
616
+ st.markdown("🩺 **Important**: This section provides a variety of medical topics that are often encountered in medical licensing exams.")
617
+
618
+ # Define medical exam terminology descriptions
619
  descriptions = {
620
+ "White Blood Cells 🌊": "3 Questions and Answers with emojis about white blood cells 🎥",
621
+ "CT Imaging🦠": "3 Questions and Answers with emojis about CT Imaging of post surgery abscess, hematoma, and cerosanguiness fluid 💊",
622
+ "Hematoma 💉": "3 Questions and Answers with emojis about hematoma and infection and how heat helps white blood cells 💪",
623
+ "Post Surgery Wound Care 🍌": "3 Questions and Answers with emojis about wound care and how to help as a caregiver🩸",
624
+ "Healing and humor 💊": "3 Questions and Answers with emojis on the use of stories and humor to help patients and family 🚑",
625
+ "Psychology of bedside manner 🧬": "3 Questions and Answers with emojis about good bedside manner 🛠",
626
+ "CT scan 💊": "3 Questions and Answers with analysis of bacteria and understanding infection using cultures and CT scan 🩺"
 
627
  }
628
 
629
  # Create columns
630
  col1, col2, col3, col4 = st.columns([1, 1, 1, 1], gap="small")
631
 
632
  # Add buttons to columns
633
+ if col1.button("Ultrasound with Doppler 🌊"):
634
+ StreamLLMChatResponse(descriptions["Ultrasound with Doppler 🌊"])
 
635
 
636
+ if col2.button("Oseltamivir 🦠"):
637
+ StreamLLMChatResponse(descriptions["Oseltamivir 🦠"])
 
638
 
639
+ if col3.button("IM Epinephrine 💉"):
640
+ StreamLLMChatResponse(descriptions["IM Epinephrine 💉"])
 
641
 
642
+ if col4.button("Hypokalemia 🍌"):
643
+ StreamLLMChatResponse(descriptions["Hypokalemia 🍌"])
 
644
 
645
  col5, col6, col7, col8 = st.columns([1, 1, 1, 1], gap="small")
646
 
647
+ if col5.button("Succinylcholine 💊"):
648
+ StreamLLMChatResponse(descriptions["Succinylcholine 💊"])
 
649
 
650
+ if col6.button("Phosphoinositol System 🧬"):
651
+ StreamLLMChatResponse(descriptions["Phosphoinositol System 🧬"])
 
 
 
 
 
 
 
 
 
652
 
653
+ if col7.button("Ramipril 💊"):
654
+ StreamLLMChatResponse(descriptions["Ramipril 💊"])
655
+
656
+
657
 
658
  # 17. Main
659
  def main():
660
 
661
+ #st.title("GAIA - Medical License Exam Testing")
662
  prompt = f"Write ten funny jokes that are tweet length stories that make you laugh. Show as markdown outline with emojis for each."
663
 
664
  # Add Wit and Humor buttons
665
  # add_witty_humor_buttons()
666
+ add_medical_exam_buttons()
 
667
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
668
 
669
+ with st.expander("Prompts 📚", expanded=False):
670
+
671
+ example_input = st.text_input("Enter your prompt text for Llama:", value=prompt, help="Enter text to get a response from DromeLlama.")
672
+ if st.button("Run Prompt With Llama model", help="Click to run the prompt."):
673
+ try:
674
+ response=StreamLLMChatResponse(example_input)
675
+ create_file(filename, example_input, response, should_save)
676
+ except:
677
+ st.write('Llama model is asleep. Starting now on A10 GPU. Please wait one minute then retry. KEDA triggered.')
678
+
679
+ openai.api_key = os.getenv('OPENAI_API_KEY')
680
+ if openai.api_key == None: openai.api_key = st.secrets['OPENAI_API_KEY']
681
+
682
+ menu = ["txt", "htm", "xlsx", "csv", "md", "py"]
683
+ choice = st.sidebar.selectbox("Output File Type:", menu)
684
+
685
+ model_choice = st.sidebar.radio("Select Model:", ('gpt-3.5-turbo', 'gpt-3.5-turbo-0301'))
686
+
687
+ user_prompt = st.text_area("Enter prompts, instructions & questions:", '', height=100)
688
+ collength, colupload = st.columns([2,3]) # adjust the ratio as needed
689
+ with collength:
690
+ max_length = st.slider("File section length for large files", min_value=1000, max_value=128000, value=12000, step=1000)
691
+ with colupload:
692
+ uploaded_file = st.file_uploader("Add a file for context:", type=["pdf", "xml", "json", "xlsx", "csv", "html", "htm", "md", "txt"])
693
+ document_sections = deque()
694
+ document_responses = {}
695
+ if uploaded_file is not None:
696
+ file_content = read_file_content(uploaded_file, max_length)
697
+ document_sections.extend(divide_document(file_content, max_length))
698
+ if len(document_sections) > 0:
699
+ if st.button("👁️ View Upload"):
700
+ st.markdown("**Sections of the uploaded file:**")
701
+ for i, section in enumerate(list(document_sections)):
702
+ st.markdown(f"**Section {i+1}**\n{section}")
703
+ st.markdown("**Chat with the model:**")
704
+ for i, section in enumerate(list(document_sections)):
705
+ if i in document_responses:
706
+ st.markdown(f"**Section {i+1}**\n{document_responses[i]}")
707
+ else:
708
+ if st.button(f"Chat about Section {i+1}"):
709
+ st.write('Reasoning with your inputs...')
710
+ #response = chat_with_model(user_prompt, section, model_choice)
711
+ st.write('Response:')
712
+ st.write(response)
713
+ document_responses[i] = response
714
+ filename = generate_filename(f"{user_prompt}_section_{i+1}", choice)
715
+ create_file(filename, user_prompt, response, should_save)
716
+ st.sidebar.markdown(get_table_download_link(filename), unsafe_allow_html=True)
717
+ if st.button('💬 Chat'):
718
+ st.write('Reasoning with your inputs...')
719
+ user_prompt_sections = divide_prompt(user_prompt, max_length)
720
+ full_response = ''
721
+ for prompt_section in user_prompt_sections:
722
+ response = chat_with_model(prompt_section, ''.join(list(document_sections)), model_choice)
723
+ full_response += response + '\n' # Combine the responses
724
+ response = full_response
725
+ st.write('Response:')
726
+ st.write(response)
727
+ filename = generate_filename(user_prompt, choice)
728
+ create_file(filename, user_prompt, response, should_save)
729
+ #st.sidebar.markdown(get_table_download_link(filename), unsafe_allow_html=True)
730
+
731
+ # Compose a file sidebar of markdown md files:
732
+ all_files = glob.glob("*.md")
733
+ all_files = [file for file in all_files if len(os.path.splitext(file)[0]) >= 10] # exclude files with short names
734
  all_files.sort(key=lambda x: (os.path.splitext(x)[1], x), reverse=True) # sort by file type and file name in descending order
735
+ if st.sidebar.button("🗑 Delete All Text"):
736
  for file in all_files:
737
  os.remove(file)
738
  st.experimental_rerun()
 
788
 
789
  st.experimental_rerun()
790
 
791
+
792
+ # Function to encode file to base64
793
+ def get_base64_encoded_file(file_path):
794
+ with open(file_path, "rb") as file:
795
+ return base64.b64encode(file.read()).decode()
796
+
797
+ # Function to create a download link
798
+ def get_audio_download_link(file_path):
799
+ base64_file = get_base64_encoded_file(file_path)
800
+ return f'<a href="data:file/wav;base64,{base64_file}" download="{os.path.basename(file_path)}">⬇️ Download Audio</a>'
801
+
802
+ # Compose a file sidebar of past encounters
803
+ all_files = glob.glob("*.wav")
804
+ all_files = [file for file in all_files if len(os.path.splitext(file)[0]) >= 10] # exclude files with short names
805
+ all_files.sort(key=lambda x: (os.path.splitext(x)[1], x), reverse=True) # sort by file type and file name in descending order
806
+
807
+ filekey = 'delall'
808
+ if st.sidebar.button("🗑 Delete All Audio", key=filekey):
809
+ for file in all_files:
810
+ os.remove(file)
811
+ st.experimental_rerun()
812
+
813
+ for file in all_files:
814
+ col1, col2 = st.sidebar.columns([6, 1]) # adjust the ratio as needed
815
+ with col1:
816
+ st.markdown(file)
817
+ if st.button("🎵", key="play_" + file): # play emoji button
818
+ audio_file = open(file, 'rb')
819
+ audio_bytes = audio_file.read()
820
+ st.audio(audio_bytes, format='audio/wav')
821
+ #st.markdown(get_audio_download_link(file), unsafe_allow_html=True)
822
+ #st.text_input(label="", value=file)
823
+ with col2:
824
+ if st.button("🗑", key="delete_" + file):
825
+ os.remove(file)
826
+ st.experimental_rerun()
827
+
828
+
829
+
830
  # Feedback
831
  # Step: Give User a Way to Upvote or Downvote
832
+ with st.expander("Give your feedback 👍", expanded=False):
833
+
834
+ feedback = st.radio("Step 8: Give your feedback", ("👍 Upvote", "👎 Downvote"))
835
+ if feedback == "👍 Upvote":
836
+ st.write("You upvoted 👍. Thank you for your feedback!")
837
+ else:
838
+ st.write("You downvoted 👎. Thank you for your feedback!")
839
+
840
+ load_dotenv()
841
+ st.write(css, unsafe_allow_html=True)
842
+ st.header("Chat with documents :books:")
843
+ user_question = st.text_input("Ask a question about your documents:")
844
+ if user_question:
845
+ process_user_input(user_question)
846
+ with st.sidebar:
847
+ st.subheader("Your documents")
848
+ docs = st.file_uploader("import documents", accept_multiple_files=True)
849
+ with st.spinner("Processing"):
850
+ raw = pdf2txt(docs)
851
+ if len(raw) > 0:
852
+ length = str(len(raw))
853
+ text_chunks = txt2chunks(raw)
854
+ vectorstore = vector_store(text_chunks)
855
+ st.session_state.conversation = get_chain(vectorstore)
856
+ st.markdown('# AI Search Index of Length:' + length + ' Created.') # add timing
857
+ filename = generate_filename(raw, 'txt')
858
+ create_file(filename, raw, '', should_save)
859
 
860
  # 18. Run AI Pipeline
861
  if __name__ == "__main__":
862
  whisper_main()
863
  main()
864
+ #add_Med_Licensing_Exam_Dataset()