Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -167,6 +167,7 @@ roleplaying_glossary = {
|
|
167 |
|
168 |
|
169 |
# HTML5 based Speech Synthesis (Text to Speech in Browser)
|
|
|
170 |
def SpeechSynthesis(result):
|
171 |
documentHTML5='''
|
172 |
<!DOCTYPE html>
|
@@ -316,6 +317,7 @@ FileSidebar()
|
|
316 |
|
317 |
|
318 |
# ---- Art Card Sidebar with Random Selection of image:
|
|
|
319 |
def get_image_as_base64(url):
|
320 |
response = requests.get(url)
|
321 |
if response.status_code == 200:
|
@@ -324,6 +326,7 @@ def get_image_as_base64(url):
|
|
324 |
else:
|
325 |
return None
|
326 |
|
|
|
327 |
def create_download_link(filename, base64_str):
|
328 |
href = f'<a href="data:file/png;base64,{base64_str}" download="{filename}">Download Image</a>'
|
329 |
return href
|
@@ -502,6 +505,7 @@ topic_emojis = {
|
|
502 |
}
|
503 |
|
504 |
# Adjusted display_buttons_with_scores function
|
|
|
505 |
def display_buttons_with_scores():
|
506 |
for category, games in roleplaying_glossary.items():
|
507 |
category_emoji = topic_emojis.get(category, "🔍") # Default to search icon if no match
|
@@ -546,6 +550,7 @@ def create_search_url_ai(keyword):
|
|
546 |
base_url = "https://huggingface.co/spaces/awacke1/GraphicAINovel?q="
|
547 |
return base_url + keyword.replace(' ', '+')
|
548 |
|
|
|
549 |
def display_videos_and_links():
|
550 |
video_files = [f for f in os.listdir('.') if f.endswith('.mp4')]
|
551 |
if not video_files:
|
@@ -595,7 +600,7 @@ def display_videos_and_links():
|
|
595 |
#st.markdown(links_md)
|
596 |
#col_index += 1
|
597 |
|
598 |
-
|
599 |
def display_images_and_wikipedia_summaries():
|
600 |
image_files = [f for f in os.listdir('.') if f.endswith('.png')]
|
601 |
if not image_files:
|
@@ -656,6 +661,7 @@ def clear_query_params():
|
|
656 |
|
657 |
|
658 |
# Function to display content or image based on a query
|
|
|
659 |
def display_content_or_image(query):
|
660 |
# Check if the query matches any glossary term
|
661 |
for category, terms in transhuman_glossary.items():
|
@@ -677,63 +683,6 @@ def display_content_or_image(query):
|
|
677 |
return False
|
678 |
|
679 |
|
680 |
-
|
681 |
-
|
682 |
-
|
683 |
-
# ------------------------------------
|
684 |
-
|
685 |
-
def add_Med_Licensing_Exam_Dataset():
|
686 |
-
import streamlit as st
|
687 |
-
from datasets import load_dataset
|
688 |
-
dataset = load_dataset("augtoma/usmle_step_1")['test'] # Using 'test' split
|
689 |
-
st.title("USMLE Step 1 Dataset Viewer")
|
690 |
-
if len(dataset) == 0:
|
691 |
-
st.write("😢 The dataset is empty.")
|
692 |
-
else:
|
693 |
-
st.write("""
|
694 |
-
🔍 Use the search box to filter questions or use the grid to scroll through the dataset.
|
695 |
-
""")
|
696 |
-
|
697 |
-
# 👩🔬 Search Box
|
698 |
-
search_term = st.text_input("Search for a specific question:", "")
|
699 |
-
|
700 |
-
# 🎛 Pagination
|
701 |
-
records_per_page = 100
|
702 |
-
num_records = len(dataset)
|
703 |
-
num_pages = max(int(num_records / records_per_page), 1)
|
704 |
-
|
705 |
-
# Skip generating the slider if num_pages is 1 (i.e., all records fit in one page)
|
706 |
-
if num_pages > 1:
|
707 |
-
page_number = st.select_slider("Select page:", options=list(range(1, num_pages + 1)))
|
708 |
-
else:
|
709 |
-
page_number = 1 # Only one page
|
710 |
-
|
711 |
-
# 📊 Display Data
|
712 |
-
start_idx = (page_number - 1) * records_per_page
|
713 |
-
end_idx = start_idx + records_per_page
|
714 |
-
|
715 |
-
# 🧪 Apply the Search Filter
|
716 |
-
filtered_data = []
|
717 |
-
for record in dataset[start_idx:end_idx]:
|
718 |
-
if isinstance(record, dict) and 'text' in record and 'id' in record:
|
719 |
-
if search_term:
|
720 |
-
if search_term.lower() in record['text'].lower():
|
721 |
-
st.markdown(record)
|
722 |
-
filtered_data.append(record)
|
723 |
-
else:
|
724 |
-
filtered_data.append(record)
|
725 |
-
|
726 |
-
# 🌐 Render the Grid
|
727 |
-
for record in filtered_data:
|
728 |
-
st.write(f"## Question ID: {record['id']}")
|
729 |
-
st.write(f"### Question:")
|
730 |
-
st.write(f"{record['text']}")
|
731 |
-
st.write(f"### Answer:")
|
732 |
-
st.write(f"{record['answer']}")
|
733 |
-
st.write("---")
|
734 |
-
|
735 |
-
st.write(f"😊 Total Records: {num_records} | 📄 Displaying {start_idx+1} to {min(end_idx, num_records)}")
|
736 |
-
|
737 |
# 1. Constants and Top Level UI Variables
|
738 |
|
739 |
# My Inference API Copy
|
@@ -752,52 +701,6 @@ key = os.getenv('OPENAI_API_KEY')
|
|
752 |
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."
|
753 |
should_save = st.sidebar.checkbox("💾 Save", value=True, help="Save your session data.")
|
754 |
|
755 |
-
# 2. Prompt label button demo for LLM
|
756 |
-
def add_witty_humor_buttons():
|
757 |
-
with st.expander("Wit and Humor 🤣", expanded=True):
|
758 |
-
# Tip about the Dromedary family
|
759 |
-
st.markdown("🔬 **Fun Fact**: Dromedaries, part of the camel family, have a single hump and are adapted to arid environments. Their 'superpowers' include the ability to survive without water for up to 7 days, thanks to their specialized blood cells and water storage in their hump.")
|
760 |
-
|
761 |
-
# Define button descriptions
|
762 |
-
descriptions = {
|
763 |
-
"Generate Limericks 😂": "Write ten random adult limericks based on quotes that are tweet length and make you laugh 🎭",
|
764 |
-
"Wise Quotes 🧙": "Generate ten wise quotes that are tweet length 🦉",
|
765 |
-
"Funny Rhymes 🎤": "Create ten funny rhymes that are tweet length 🎶",
|
766 |
-
"Medical Jokes 💉": "Create ten medical jokes that are tweet length 🏥",
|
767 |
-
"Minnesota Humor ❄️": "Create ten jokes about Minnesota that are tweet length 🌨️",
|
768 |
-
"Top Funny Stories 📖": "Create ten funny stories that are tweet length 📚",
|
769 |
-
"More Funny Rhymes 🎙️": "Create ten more funny rhymes that are tweet length 🎵"
|
770 |
-
}
|
771 |
-
|
772 |
-
# Create columns
|
773 |
-
col1, col2, col3 = st.columns([1, 1, 1], gap="small")
|
774 |
-
|
775 |
-
# Add buttons to columns
|
776 |
-
if col1.button("Wise Limericks 😂"):
|
777 |
-
StreamLLMChatResponse(descriptions["Generate Limericks 😂"])
|
778 |
-
|
779 |
-
if col2.button("Wise Quotes 🧙"):
|
780 |
-
StreamLLMChatResponse(descriptions["Wise Quotes 🧙"])
|
781 |
-
|
782 |
-
#if col3.button("Funny Rhymes 🎤"):
|
783 |
-
# StreamLLMChatResponse(descriptions["Funny Rhymes 🎤"])
|
784 |
-
|
785 |
-
col4, col5, col6 = st.columns([1, 1, 1], gap="small")
|
786 |
-
|
787 |
-
if col4.button("Top Ten Funniest Clean Jokes 💉"):
|
788 |
-
StreamLLMChatResponse(descriptions["Top Ten Funniest Clean Jokes 💉"])
|
789 |
-
|
790 |
-
if col5.button("Minnesota Humor ❄️"):
|
791 |
-
StreamLLMChatResponse(descriptions["Minnesota Humor ❄️"])
|
792 |
-
|
793 |
-
if col6.button("Origins of Medical Science True Stories"):
|
794 |
-
StreamLLMChatResponse(descriptions["Origins of Medical Science True Stories"])
|
795 |
-
|
796 |
-
col7 = st.columns(1, gap="small")
|
797 |
-
|
798 |
-
if col7[0].button("Top Ten Best Write a streamlit python program prompts to build AI programs. 🎙️"):
|
799 |
-
StreamLLMChatResponse(descriptions["Top Ten Best Write a streamlit python program prompts to build AI programs. 🎙️"])
|
800 |
-
|
801 |
|
802 |
|
803 |
# 3. Stream Llama Response
|
@@ -844,10 +747,13 @@ def StreamLLMChatResponse(prompt):
|
|
844 |
st.write('Llama model is asleep. Starting up now on A10 - please give 5 minutes then retry as KEDA scales up from zero to activate running container(s).')
|
845 |
|
846 |
# 4. Run query with payload
|
|
|
847 |
def query(payload):
|
848 |
response = requests.post(API_URL, headers=headers, json=payload)
|
849 |
st.markdown(response.json())
|
850 |
return response.json()
|
|
|
|
|
851 |
def get_output(prompt):
|
852 |
return query({"inputs": prompt})
|
853 |
|
@@ -857,7 +763,6 @@ def generate_filename(prompt, file_type):
|
|
857 |
safe_date_time = datetime.now(central).strftime("%m%d_%H%M")
|
858 |
replaced_prompt = prompt.replace(" ", "_").replace("\n", "_")
|
859 |
safe_prompt = "".join(x for x in replaced_prompt if x.isalnum() or x == "_")[:255] # 255 is linux max, 260 is windows max
|
860 |
-
#safe_prompt = "".join(x for x in replaced_prompt if x.isalnum() or x == "_")[:45]
|
861 |
return f"{safe_date_time}_{safe_prompt}.{file_type}"
|
862 |
|
863 |
# 6. Speech transcription via OpenAI service
|
@@ -897,6 +802,7 @@ def save_and_play_audio(audio_recorder):
|
|
897 |
return None
|
898 |
|
899 |
# 8. File creator that interprets type and creates output file for text, markdown and code
|
|
|
900 |
def create_file(filename, prompt, response, should_save=True):
|
901 |
if not should_save:
|
902 |
return
|
|
|
167 |
|
168 |
|
169 |
# HTML5 based Speech Synthesis (Text to Speech in Browser)
|
170 |
+
@st.cache_resource
|
171 |
def SpeechSynthesis(result):
|
172 |
documentHTML5='''
|
173 |
<!DOCTYPE html>
|
|
|
317 |
|
318 |
|
319 |
# ---- Art Card Sidebar with Random Selection of image:
|
320 |
+
@st.cache_resource
|
321 |
def get_image_as_base64(url):
|
322 |
response = requests.get(url)
|
323 |
if response.status_code == 200:
|
|
|
326 |
else:
|
327 |
return None
|
328 |
|
329 |
+
@st.cache_resource
|
330 |
def create_download_link(filename, base64_str):
|
331 |
href = f'<a href="data:file/png;base64,{base64_str}" download="{filename}">Download Image</a>'
|
332 |
return href
|
|
|
505 |
}
|
506 |
|
507 |
# Adjusted display_buttons_with_scores function
|
508 |
+
@st.cache_resource
|
509 |
def display_buttons_with_scores():
|
510 |
for category, games in roleplaying_glossary.items():
|
511 |
category_emoji = topic_emojis.get(category, "🔍") # Default to search icon if no match
|
|
|
550 |
base_url = "https://huggingface.co/spaces/awacke1/GraphicAINovel?q="
|
551 |
return base_url + keyword.replace(' ', '+')
|
552 |
|
553 |
+
@st.cache_resource
|
554 |
def display_videos_and_links():
|
555 |
video_files = [f for f in os.listdir('.') if f.endswith('.mp4')]
|
556 |
if not video_files:
|
|
|
600 |
#st.markdown(links_md)
|
601 |
#col_index += 1
|
602 |
|
603 |
+
@st.cache_resource
|
604 |
def display_images_and_wikipedia_summaries():
|
605 |
image_files = [f for f in os.listdir('.') if f.endswith('.png')]
|
606 |
if not image_files:
|
|
|
661 |
|
662 |
|
663 |
# Function to display content or image based on a query
|
664 |
+
@st.cache_resource
|
665 |
def display_content_or_image(query):
|
666 |
# Check if the query matches any glossary term
|
667 |
for category, terms in transhuman_glossary.items():
|
|
|
683 |
return False
|
684 |
|
685 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
686 |
# 1. Constants and Top Level UI Variables
|
687 |
|
688 |
# My Inference API Copy
|
|
|
701 |
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."
|
702 |
should_save = st.sidebar.checkbox("💾 Save", value=True, help="Save your session data.")
|
703 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
704 |
|
705 |
|
706 |
# 3. Stream Llama Response
|
|
|
747 |
st.write('Llama model is asleep. Starting up now on A10 - please give 5 minutes then retry as KEDA scales up from zero to activate running container(s).')
|
748 |
|
749 |
# 4. Run query with payload
|
750 |
+
@st.cache_resource
|
751 |
def query(payload):
|
752 |
response = requests.post(API_URL, headers=headers, json=payload)
|
753 |
st.markdown(response.json())
|
754 |
return response.json()
|
755 |
+
|
756 |
+
|
757 |
def get_output(prompt):
|
758 |
return query({"inputs": prompt})
|
759 |
|
|
|
763 |
safe_date_time = datetime.now(central).strftime("%m%d_%H%M")
|
764 |
replaced_prompt = prompt.replace(" ", "_").replace("\n", "_")
|
765 |
safe_prompt = "".join(x for x in replaced_prompt if x.isalnum() or x == "_")[:255] # 255 is linux max, 260 is windows max
|
|
|
766 |
return f"{safe_date_time}_{safe_prompt}.{file_type}"
|
767 |
|
768 |
# 6. Speech transcription via OpenAI service
|
|
|
802 |
return None
|
803 |
|
804 |
# 8. File creator that interprets type and creates output file for text, markdown and code
|
805 |
+
@st.cache_resource
|
806 |
def create_file(filename, prompt, response, should_save=True):
|
807 |
if not should_save:
|
808 |
return
|