Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,33 @@ import os
|
|
3 |
import json
|
4 |
from PIL import Image
|
5 |
from urllib.parse import quote # Ensure this import is included
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
# Set page configuration with a title and favicon
|
8 |
st.set_page_config(
|
@@ -17,6 +44,95 @@ st.set_page_config(
|
|
17 |
}
|
18 |
)
|
19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
# Ensure the directory for storing scores exists
|
21 |
score_dir = "scores"
|
22 |
os.makedirs(score_dir, exist_ok=True)
|
@@ -51,61 +167,9 @@ def load_score(key):
|
|
51 |
return score_data["score"]
|
52 |
return 0
|
53 |
|
54 |
-
roleplaying_glossary = {
|
55 |
-
"🎴 Traditional Card Games": {
|
56 |
-
"Bridge": ["Trick-taking", "Bidding and partnership", "Complex scoring"],
|
57 |
-
"Poker": ["Betting/Card ranking", "Bluffing and hand management", "Various play styles"],
|
58 |
-
"Hearts": ["Trick-avoidance", "Passing cards strategy", "Shooting the moon"],
|
59 |
-
"Spades": ["Trick-taking", "Partnership and bidding", "Blind bidding"],
|
60 |
-
"Rummy": ["Matching", "Set and run formation", "Point scoring"],
|
61 |
-
},
|
62 |
-
"🔮 Collectible Card Games (CCGs)": {
|
63 |
-
"Magic: The Gathering": ["Deck building", "Resource management", "Strategic play"],
|
64 |
-
"Yu-Gi-Oh!": ["Dueling", "Summoning strategies", "Trap and spell cards"],
|
65 |
-
"Pokémon TCG": ["Collectible", "Type advantages", "Energy management"],
|
66 |
-
"KeyForge": ["Unique deck", "No deck building", "Chain system"],
|
67 |
-
"Legend of the Five Rings": ["Living Card Game", "Honor and conflict", "Clan loyalty"],
|
68 |
-
},
|
69 |
-
"🕹️ Digital Card Games": {
|
70 |
-
"Hearthstone": ["Digital CCG", "Hero powers", "Expansive card sets"],
|
71 |
-
"Gwent": ["Strategic depth", "Row-based play", "Witcher universe"],
|
72 |
-
"Slay the Spire": ["Roguelike deck-builder", "Card drafting", "Relic synergies"],
|
73 |
-
"Eternal Card Game": ["Digital CCG", "Cross-platform", "Drafting and events"],
|
74 |
-
},
|
75 |
-
"💻 Card Battler Video Games": {
|
76 |
-
"Yu-Gi-Oh! Duel Links": ["Speed Duel format", "Mobile and PC", "Competitive ladder"],
|
77 |
-
"Magic: The Gathering Arena": ["Digital adaptation", "Regular updates", "Esports"],
|
78 |
-
"Monster Train": ["Roguelike", "Multi-tiered defense", "Clan synergies"],
|
79 |
-
"Legends of Runeterra": ["League of Legends universe", "Dynamic combat", "Champion leveling"],
|
80 |
-
},
|
81 |
-
"🧠 Game Design and Dynamics": {
|
82 |
-
"Deck Building Strategies": ["Card synergy", "Mana curve", "Meta considerations"],
|
83 |
-
"Gameplay Mechanics": ["Turn-based", "Resource management", "Combat dynamics"],
|
84 |
-
"Player Engagement": ["Replayability", "Strategic depth", "Social play"],
|
85 |
-
},
|
86 |
-
"📚 Lore & Background": {
|
87 |
-
"Magic: The Gathering": ["Rich lore", "Multiverse settings", "Planeswalker stories"],
|
88 |
-
"Yu-Gi-Oh!": ["Anime-based", "Duel Monsters", "Egyptian mythology"],
|
89 |
-
"Legends of Runeterra": ["Expansive lore", "Champion backstories", "Faction conflicts"],
|
90 |
-
},
|
91 |
-
"🛠️ Digital Tools & Platforms": {
|
92 |
-
"Online Play": ["Remote gameplay", "Digital tournaments", "Community events"],
|
93 |
-
"Deck Building Tools": ["Card database access", "Deck testing", "Community sharing"],
|
94 |
-
"Strategy Guides": ["Meta analysis", "Deck guides", "Tournament reports"],
|
95 |
-
},
|
96 |
-
"🎖️ Competitive Scene": {
|
97 |
-
"Tournaments": ["Local game stores", "Regional competitions", "World championships"],
|
98 |
-
"Ranking Systems": ["Elo ratings", "Ladder rankings", "Seasonal rewards"],
|
99 |
-
"Esports": ["Live-streamed events", "Professional teams", "Sponsorships"],
|
100 |
-
},
|
101 |
-
}
|
102 |
|
103 |
|
104 |
def search_glossary(query):
|
105 |
-
for category, terms in roleplaying_glossary.items():
|
106 |
-
if query.lower() in (term.lower() for term in terms):
|
107 |
-
st.markdown(f"#### {category}")
|
108 |
-
st.write(f"- {query}")
|
109 |
|
110 |
st.write('## ' + query)
|
111 |
|
@@ -144,17 +208,17 @@ def display_glossary(glossary, area):
|
|
144 |
|
145 |
|
146 |
# Function to display the entire glossary in a grid format with links
|
147 |
-
def display_glossary_grid(
|
148 |
search_urls = {
|
149 |
"📖": lambda k: f"https://en.wikipedia.org/wiki/{quote(k)}",
|
150 |
"🔍": lambda k: f"https://www.google.com/search?q={quote(k)}",
|
151 |
"▶️": lambda k: f"https://www.youtube.com/results?search_query={quote(k)}",
|
152 |
"🔎": lambda k: f"https://www.bing.com/search?q={quote(k)}",
|
153 |
-
"🎲": lambda k: f"https://huggingface.co/spaces/awacke1/
|
154 |
|
155 |
}
|
156 |
|
157 |
-
for category, details in
|
158 |
st.write(f"### {category}")
|
159 |
cols = st.columns(len(details)) # Create dynamic columns based on the number of games
|
160 |
for idx, (game, terms) in enumerate(details.items()):
|
@@ -190,7 +254,7 @@ topic_emojis = {
|
|
190 |
|
191 |
# Adjusted display_buttons_with_scores function
|
192 |
def display_buttons_with_scores():
|
193 |
-
for category, games in
|
194 |
category_emoji = topic_emojis.get(category, "🔍") # Default to search icon if no match
|
195 |
st.markdown(f"## {category_emoji} {category}")
|
196 |
for game, terms in games.items():
|
@@ -205,7 +269,7 @@ def display_buttons_with_scores():
|
|
205 |
# -----------------------------------------------------------------
|
206 |
# query_body = f"Create a detailed outline for **{term}** with subpoints highlighting key aspects, using emojis for visual engagement. Include step-by-step rules and boldface important entities and ruleset elements."
|
207 |
query_body = f"Create a streamlit python app.py that produces a detailed markdown outline and CSV dataset user interface with an outline for **{term}** with subpoints highlighting key aspects, using emojis for visual engagement. Include step-by-step rules and boldface important entities and ruleset elements."
|
208 |
-
response = search_glossary(query_prefix + query_body,
|
209 |
|
210 |
|
211 |
def fetch_wikipedia_summary(keyword):
|
@@ -291,95 +355,6 @@ def display_content_or_image(query):
|
|
291 |
|
292 |
|
293 |
|
294 |
-
|
295 |
-
# Imports
|
296 |
-
import base64
|
297 |
-
import glob
|
298 |
-
import json
|
299 |
-
import math
|
300 |
-
import openai
|
301 |
-
import os
|
302 |
-
import pytz
|
303 |
-
import re
|
304 |
-
import requests
|
305 |
-
import streamlit as st
|
306 |
-
import textract
|
307 |
-
import time
|
308 |
-
import zipfile
|
309 |
-
import huggingface_hub
|
310 |
-
import dotenv
|
311 |
-
from audio_recorder_streamlit import audio_recorder
|
312 |
-
from bs4 import BeautifulSoup
|
313 |
-
from collections import deque
|
314 |
-
from datetime import datetime
|
315 |
-
from dotenv import load_dotenv
|
316 |
-
from huggingface_hub import InferenceClient
|
317 |
-
from io import BytesIO
|
318 |
-
from langchain.chat_models import ChatOpenAI
|
319 |
-
from langchain.chains import ConversationalRetrievalChain
|
320 |
-
from langchain.embeddings import OpenAIEmbeddings
|
321 |
-
from langchain.memory import ConversationBufferMemory
|
322 |
-
from langchain.text_splitter import CharacterTextSplitter
|
323 |
-
from langchain.vectorstores import FAISS
|
324 |
-
from openai import ChatCompletion
|
325 |
-
from PyPDF2 import PdfReader
|
326 |
-
from templates import bot_template, css, user_template
|
327 |
-
from xml.etree import ElementTree as ET
|
328 |
-
import streamlit.components.v1 as components # Import Streamlit Components for HTML5
|
329 |
-
|
330 |
-
|
331 |
-
def add_Med_Licensing_Exam_Dataset():
|
332 |
-
import streamlit as st
|
333 |
-
from datasets import load_dataset
|
334 |
-
dataset = load_dataset("augtoma/usmle_step_1")['test'] # Using 'test' split
|
335 |
-
st.title("USMLE Step 1 Dataset Viewer")
|
336 |
-
if len(dataset) == 0:
|
337 |
-
st.write("😢 The dataset is empty.")
|
338 |
-
else:
|
339 |
-
st.write("""
|
340 |
-
🔍 Use the search box to filter questions or use the grid to scroll through the dataset.
|
341 |
-
""")
|
342 |
-
|
343 |
-
# 👩🔬 Search Box
|
344 |
-
search_term = st.text_input("Search for a specific question:", "")
|
345 |
-
|
346 |
-
# 🎛 Pagination
|
347 |
-
records_per_page = 100
|
348 |
-
num_records = len(dataset)
|
349 |
-
num_pages = max(int(num_records / records_per_page), 1)
|
350 |
-
|
351 |
-
# Skip generating the slider if num_pages is 1 (i.e., all records fit in one page)
|
352 |
-
if num_pages > 1:
|
353 |
-
page_number = st.select_slider("Select page:", options=list(range(1, num_pages + 1)))
|
354 |
-
else:
|
355 |
-
page_number = 1 # Only one page
|
356 |
-
|
357 |
-
# 📊 Display Data
|
358 |
-
start_idx = (page_number - 1) * records_per_page
|
359 |
-
end_idx = start_idx + records_per_page
|
360 |
-
|
361 |
-
# 🧪 Apply the Search Filter
|
362 |
-
filtered_data = []
|
363 |
-
for record in dataset[start_idx:end_idx]:
|
364 |
-
if isinstance(record, dict) and 'text' in record and 'id' in record:
|
365 |
-
if search_term:
|
366 |
-
if search_term.lower() in record['text'].lower():
|
367 |
-
st.markdown(record)
|
368 |
-
filtered_data.append(record)
|
369 |
-
else:
|
370 |
-
filtered_data.append(record)
|
371 |
-
|
372 |
-
# 🌐 Render the Grid
|
373 |
-
for record in filtered_data:
|
374 |
-
st.write(f"## Question ID: {record['id']}")
|
375 |
-
st.write(f"### Question:")
|
376 |
-
st.write(f"{record['text']}")
|
377 |
-
st.write(f"### Answer:")
|
378 |
-
st.write(f"{record['answer']}")
|
379 |
-
st.write("---")
|
380 |
-
|
381 |
-
st.write(f"😊 Total Records: {num_records} | 📄 Displaying {start_idx+1} to {min(end_idx, num_records)}")
|
382 |
-
|
383 |
# 1. Constants and Top Level UI Variables
|
384 |
|
385 |
# My Inference API Copy
|
@@ -398,52 +373,6 @@ key = os.getenv('OPENAI_API_KEY')
|
|
398 |
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."
|
399 |
should_save = st.sidebar.checkbox("💾 Save", value=True, help="Save your session data.")
|
400 |
|
401 |
-
# 2. Prompt label button demo for LLM
|
402 |
-
def add_witty_humor_buttons():
|
403 |
-
with st.expander("Wit and Humor 🤣", expanded=True):
|
404 |
-
# Tip about the Dromedary family
|
405 |
-
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.")
|
406 |
-
|
407 |
-
# Define button descriptions
|
408 |
-
descriptions = {
|
409 |
-
"Generate Limericks 😂": "Write ten random adult limericks based on quotes that are tweet length and make you laugh 🎭",
|
410 |
-
"Wise Quotes 🧙": "Generate ten wise quotes that are tweet length 🦉",
|
411 |
-
"Funny Rhymes 🎤": "Create ten funny rhymes that are tweet length 🎶",
|
412 |
-
"Medical Jokes 💉": "Create ten medical jokes that are tweet length 🏥",
|
413 |
-
"Minnesota Humor ❄️": "Create ten jokes about Minnesota that are tweet length 🌨️",
|
414 |
-
"Top Funny Stories 📖": "Create ten funny stories that are tweet length 📚",
|
415 |
-
"More Funny Rhymes 🎙️": "Create ten more funny rhymes that are tweet length 🎵"
|
416 |
-
}
|
417 |
-
|
418 |
-
# Create columns
|
419 |
-
col1, col2, col3 = st.columns([1, 1, 1], gap="small")
|
420 |
-
|
421 |
-
# Add buttons to columns
|
422 |
-
if col1.button("Wise Limericks 😂"):
|
423 |
-
StreamLLMChatResponse(descriptions["Generate Limericks 😂"])
|
424 |
-
|
425 |
-
if col2.button("Wise Quotes 🧙"):
|
426 |
-
StreamLLMChatResponse(descriptions["Wise Quotes 🧙"])
|
427 |
-
|
428 |
-
#if col3.button("Funny Rhymes 🎤"):
|
429 |
-
# StreamLLMChatResponse(descriptions["Funny Rhymes 🎤"])
|
430 |
-
|
431 |
-
col4, col5, col6 = st.columns([1, 1, 1], gap="small")
|
432 |
-
|
433 |
-
if col4.button("Top Ten Funniest Clean Jokes 💉"):
|
434 |
-
StreamLLMChatResponse(descriptions["Top Ten Funniest Clean Jokes 💉"])
|
435 |
-
|
436 |
-
if col5.button("Minnesota Humor ❄️"):
|
437 |
-
StreamLLMChatResponse(descriptions["Minnesota Humor ❄️"])
|
438 |
-
|
439 |
-
if col6.button("Origins of Medical Science True Stories"):
|
440 |
-
StreamLLMChatResponse(descriptions["Origins of Medical Science True Stories"])
|
441 |
-
|
442 |
-
col7 = st.columns(1, gap="small")
|
443 |
-
|
444 |
-
if col7[0].button("Top Ten Best Write a streamlit python program prompts to build AI programs. 🎙️"):
|
445 |
-
StreamLLMChatResponse(descriptions["Top Ten Best Write a streamlit python program prompts to build AI programs. 🎙️"])
|
446 |
-
|
447 |
def SpeechSynthesis(result):
|
448 |
documentHTML5='''
|
449 |
<!DOCTYPE html>
|
@@ -658,7 +587,7 @@ def read_file_content(file,max_length):
|
|
658 |
else:
|
659 |
return ""
|
660 |
|
661 |
-
# 11. Chat with GPT - Caution on quota
|
662 |
@st.cache_resource
|
663 |
def chat_with_model(prompt, document_section='', model_choice='gpt-3.5-turbo'):
|
664 |
model = model_choice
|
@@ -690,16 +619,6 @@ def chat_with_model(prompt, document_section='', model_choice='gpt-3.5-turbo'):
|
|
690 |
st.write(time.time() - start_time)
|
691 |
return full_reply_content
|
692 |
|
693 |
-
# 12. Embedding VectorDB for LLM query of documents to text to compress inputs and prompt together as Chat memory using Langchain
|
694 |
-
@st.cache_resource
|
695 |
-
def chat_with_file_contents(prompt, file_content, model_choice='gpt-3.5-turbo'):
|
696 |
-
conversation = [{'role': 'system', 'content': 'You are a helpful assistant.'}]
|
697 |
-
conversation.append({'role': 'user', 'content': prompt})
|
698 |
-
if len(file_content)>0:
|
699 |
-
conversation.append({'role': 'assistant', 'content': file_content})
|
700 |
-
response = openai.ChatCompletion.create(model=model_choice, messages=conversation)
|
701 |
-
return response['choices'][0]['message']['content']
|
702 |
-
|
703 |
def extract_mime_type(file):
|
704 |
if isinstance(file, str):
|
705 |
pattern = r"type='(.*?)'"
|
@@ -904,77 +823,6 @@ def StreamMedChatResponse(topic):
|
|
904 |
st.write(f"Showing resources or questions related to: {topic}")
|
905 |
|
906 |
|
907 |
-
|
908 |
-
def add_medical_exam_buttons():
|
909 |
-
# Medical exam terminology descriptions
|
910 |
-
descriptions = {
|
911 |
-
"White Blood Cells 🌊": "3 Q&A with emojis about types, facts, function, inputs and outputs of white blood cells 🎥",
|
912 |
-
"CT Imaging🦠": "3 Q&A with emojis on CT Imaging post surgery, how to, what to look for 💊",
|
913 |
-
"Hematoma 💉": "3 Q&A with emojis about hematoma and infection care and study including bacteria cultures and tests or labs💪",
|
914 |
-
"Post Surgery Wound Care 🍌": "3 Q&A with emojis on wound care, and good bedside manner 🩸",
|
915 |
-
"Healing and humor 💊": "3 Q&A with emojis on stories and humor about healing and caregiving 🚑",
|
916 |
-
"Psychology of bedside manner 🧬": "3 Q&A with emojis on bedside manner and how to make patients feel at ease🛠",
|
917 |
-
"CT scan 💊": "3 Q&A with analysis on infection using CT scan and packing for skin, cellulitus and fascia 🩺"
|
918 |
-
}
|
919 |
-
|
920 |
-
# Expander for medical topics
|
921 |
-
with st.expander("Medical Licensing Exam Topics 📚", expanded=False):
|
922 |
-
st.markdown("🩺 **Important**: Variety of topics for medical licensing exams.")
|
923 |
-
|
924 |
-
# Create buttons for each description with unique keys
|
925 |
-
for idx, (label, content) in enumerate(descriptions.items()):
|
926 |
-
button_key = f"button_{idx}"
|
927 |
-
if st.button(label, key=button_key):
|
928 |
-
st.write(f"Running {label}")
|
929 |
-
input='Create markdown outline for definition of topic ' + label + ' also short quiz with appropriate emojis and definitions for: ' + content
|
930 |
-
response=StreamLLMChatResponse(input)
|
931 |
-
filename = generate_filename(response, 'txt')
|
932 |
-
create_file(filename, input, response, should_save)
|
933 |
-
|
934 |
-
def add_medical_exam_buttons2():
|
935 |
-
with st.expander("Medical Licensing Exam Topics 📚", expanded=False):
|
936 |
-
st.markdown("🩺 **Important**: This section provides a variety of medical topics that are often encountered in medical licensing exams.")
|
937 |
-
|
938 |
-
# Define medical exam terminology descriptions
|
939 |
-
descriptions = {
|
940 |
-
"White Blood Cells 🌊": "3 Questions and Answers with emojis about white blood cells 🎥",
|
941 |
-
"CT Imaging🦠": "3 Questions and Answers with emojis about CT Imaging of post surgery abscess, hematoma, and cerosanguiness fluid 💊",
|
942 |
-
"Hematoma 💉": "3 Questions and Answers with emojis about hematoma and infection and how heat helps white blood cells 💪",
|
943 |
-
"Post Surgery Wound Care 🍌": "3 Questions and Answers with emojis about wound care and how to help as a caregiver🩸",
|
944 |
-
"Healing and humor 💊": "3 Questions and Answers with emojis on the use of stories and humor to help patients and family ��",
|
945 |
-
"Psychology of bedside manner 🧬": "3 Questions and Answers with emojis about good bedside manner 🛠",
|
946 |
-
"CT scan 💊": "3 Questions and Answers with analysis of bacteria and understanding infection using cultures and CT scan 🩺"
|
947 |
-
}
|
948 |
-
|
949 |
-
# Create columns
|
950 |
-
col1, col2, col3, col4 = st.columns([1, 1, 1, 1], gap="small")
|
951 |
-
|
952 |
-
# Add buttons to columns
|
953 |
-
if col1.button("Ultrasound with Doppler 🌊"):
|
954 |
-
StreamLLMChatResponse(descriptions["Ultrasound with Doppler 🌊"])
|
955 |
-
|
956 |
-
if col2.button("Oseltamivir 🦠"):
|
957 |
-
StreamLLMChatResponse(descriptions["Oseltamivir 🦠"])
|
958 |
-
|
959 |
-
if col3.button("IM Epinephrine 💉"):
|
960 |
-
StreamLLMChatResponse(descriptions["IM Epinephrine 💉"])
|
961 |
-
|
962 |
-
if col4.button("Hypokalemia 🍌"):
|
963 |
-
StreamLLMChatResponse(descriptions["Hypokalemia 🍌"])
|
964 |
-
|
965 |
-
col5, col6, col7, col8 = st.columns([1, 1, 1, 1], gap="small")
|
966 |
-
|
967 |
-
if col5.button("Succinylcholine 💊"):
|
968 |
-
StreamLLMChatResponse(descriptions["Succinylcholine 💊"])
|
969 |
-
|
970 |
-
if col6.button("Phosphoinositol System 🧬"):
|
971 |
-
StreamLLMChatResponse(descriptions["Phosphoinositol System 🧬"])
|
972 |
-
|
973 |
-
if col7.button("Ramipril 💊"):
|
974 |
-
StreamLLMChatResponse(descriptions["Ramipril 💊"])
|
975 |
-
|
976 |
-
|
977 |
-
|
978 |
# 17. Main
|
979 |
def main():
|
980 |
prompt = f"Write ten funny jokes that are tweet length stories that make you laugh. Show as markdown outline with emojis for each."
|
@@ -1225,11 +1073,7 @@ def main():
|
|
1225 |
#st.markdown("## Glossary Lookup\nEnter a term in the URL query, like `?q=Nanotechnology` or `?query=Martian Syndicate`.")
|
1226 |
|
1227 |
st.markdown('''
|
1228 |
-
### Mixable
|
1229 |
-
- **Elevate Your Game with Mixable Card Game AI:** Dive into a universe where strategy meets creativity.
|
1230 |
-
- **Capabilities:** Crafts intricate glossaries, dynamic rule sets, and seamless jump-link brains.
|
1231 |
-
- **Experience:** Transforms every card game into an adventure, making it more than just play.
|
1232 |
-
- **Query Parameter Usage:** Enter a card game term in the URL query, like `?q=MagicTheGathering` or `?query=DeckBuilding`, to dive deeper into your game of choice.
|
1233 |
''')
|
1234 |
|
1235 |
try:
|
@@ -1242,8 +1086,8 @@ def main():
|
|
1242 |
st.markdown('No glossary lookup')
|
1243 |
|
1244 |
# Display the glossary grid
|
1245 |
-
st.title("
|
1246 |
-
display_glossary_grid(
|
1247 |
st.title("🎲🗺️ Card Game Universe")
|
1248 |
st.markdown("## Explore the vast universes of Dungeons and Dragons, Call of Cthulhu, GURPS, and more through interactive storytelling and encyclopedic knowledge.🌠")
|
1249 |
|
|
|
3 |
import json
|
4 |
from PIL import Image
|
5 |
from urllib.parse import quote # Ensure this import is included
|
6 |
+
import base64
|
7 |
+
import glob
|
8 |
+
import json
|
9 |
+
import math
|
10 |
+
import openai
|
11 |
+
import os
|
12 |
+
import pytz
|
13 |
+
import re
|
14 |
+
import requests
|
15 |
+
import textract
|
16 |
+
import time
|
17 |
+
import zipfile
|
18 |
+
import huggingface_hub
|
19 |
+
import dotenv
|
20 |
+
from audio_recorder_streamlit import audio_recorder
|
21 |
+
from bs4 import BeautifulSoup
|
22 |
+
from collections import deque
|
23 |
+
from datetime import datetime
|
24 |
+
from dotenv import load_dotenv
|
25 |
+
from huggingface_hub import InferenceClient
|
26 |
+
from io import BytesIO
|
27 |
+
from openai import ChatCompletion
|
28 |
+
from PyPDF2 import PdfReader
|
29 |
+
#from templates import bot_template, css, user_template -- pattern with content
|
30 |
+
from xml.etree import ElementTree as ET
|
31 |
+
import streamlit.components.v1 as components # Import Streamlit Components for HTML5
|
32 |
+
|
33 |
|
34 |
# Set page configuration with a title and favicon
|
35 |
st.set_page_config(
|
|
|
44 |
}
|
45 |
)
|
46 |
|
47 |
+
if st.checkbox('Show Anatomy Table'):
|
48 |
+
st.markdown("""
|
49 |
+
## Anatomy Head to Toe Table with Body Organs Costly Conditions, Spending, CPT Codes and Frequency
|
50 |
+
|
51 |
+
| Table Num | Body Part | Organ/Part | Description | 📈 Costly Condition | 💰 Spending (billions) | CPT Range Start | CPT Range Finish | Frequency |
|
52 |
+
|-----------|------------------|----------------------|-------------------------------|------------------------------|------------------------|-----------------|------------------|----------------|
|
53 |
+
| 1 | 🧠 Head | 🧠 Brain | Controls mental processes | 😨 Anxiety & Depression | 210 | 90791 | 90899 | 1 in 5 |
|
54 |
+
| 2 | 👀 Eyes | 👁️ Optic Nerve | Vision | 👓 Cataracts | 10.7 | 92002 | 92499 | 1 in 6 (over 40 years) |
|
55 |
+
| 3 | 👂 Ears | 🐚 Cochlea | Hearing | 📢 Hearing Loss | 7.1 | 92502 | 92700 | 1 in 8 (over 12 years) |
|
56 |
+
| 4 | 👃 Nose | 👃 Olfactory Bulb | Smell | 🤧 Allergies | 25 | 31231 | 31294 | 1 in 3 |
|
57 |
+
| 5 | 👄 Mouth | 👅 Tongue | Taste | 🦷 Dental Issues | 130 | 00100 | 00192 | 1 in 2 |
|
58 |
+
| 6 | 🫁 Neck | 🦋 Thyroid | Metabolism | 🦠 Hypothyroidism | 3.1 | 60210 | 60271 | 1 in 20 |
|
59 |
+
| 7 | 💪 Upper Body | ❤️ Heart | Circulation | 💔 Heart Disease | 230 | 92920 | 93799 | 1 in 4 (over 65 years) |
|
60 |
+
| 8 | 💪 Upper Body | 🫁 Lungs | Respiration | 😷 Chronic Obstructive Pulmonary Disease | 70 | 94002 | 94799 | 1 in 20 (over 45 years) |
|
61 |
+
| 9 | 💪 Upper Body | 🍷 Liver | Detoxification | 🍺 Liver Disease | 40 | 47000 | 47999 | 1 in 10 |
|
62 |
+
| 10 | 💪 Upper Body | 🍹 Kidneys | Filtration | 🌊 Chronic Kidney Disease | 110 | 50010 | 50999 | 1 in 7 |
|
63 |
+
| 11 | 💪 Upper Body | 💉 Pancreas | Insulin secretion | 🍬 Diabetes | 327 | 48100 | 48999 | 1 in 10 |
|
64 |
+
| 12 | 💪 Upper Body | 🍽️ Stomach | Digestion | 🔥 Gastroesophageal Reflux Disease | 17 | 43200 | 43289 | 1 in 5 |
|
65 |
+
| 13 | 💪 Upper Body | 🛡️ Spleen | Immune functions | 🩸 Anemia | 5.6 | 38100 | 38199 | 1 in 6 |
|
66 |
+
| 14 | 💪 Upper Body | 🫀 Blood Vessels | Circulation of blood | 🚑 Hypertension | 55 | 40110 | 40599 | 1 in 3 |
|
67 |
+
| 15 | 🦵 Lower Body | 🍝 Colon | Absorption of water, minerals | 🌟 Colorectal Cancer | 14 | 45378 | 45378 | 1 in 23 |
|
68 |
+
| 16 | 🦵 Lower Body | 🚽 Bladder | Urine excretion | 💧 Urinary Incontinence | 8 | 51700 | 51798 | 1 in 4 (over 65 years) |
|
69 |
+
| 17 | 🦵 Lower Body | 💞 Reproductive Organs | Sex hormone secretion | 🎗️ Endometriosis | 22 | 56405 | 58999 | 1 in 10 (women) |
|
70 |
+
| 18 | 🦶 Feet | 🎯 Nerve endings | Balance and movement | 🤕 Peripheral Neuropathy | 19 | 95900 | 96004 | 1 in 30 |
|
71 |
+
| 19 | 🦶 Feet | 🌡️ Skin | Temperature regulation | 🌞 Skin Cancer | 8.1 | 96910 | 96999 | 1 in 5 |
|
72 |
+
| 20 | 🦶 Feet | 💪 Muscles | Movement and strength | 🏋️♂️ Musculoskeletal Disorders | 176 | 97110 | 97799 | 1 in 2 |
|
73 |
+
|
74 |
+
""")
|
75 |
+
|
76 |
+
body_map_data = {
|
77 |
+
"🧠 Central Nervous System": {
|
78 |
+
"Brain": ["Cognitive functions", "Emotion regulation", "Neural coordination"],
|
79 |
+
"Spinal Cord": ["Nerve signal transmission", "Reflex actions", "Connects brain to body"],
|
80 |
+
},
|
81 |
+
"👀 Sensory Organs": {
|
82 |
+
"Eyes": ["Vision", "Light perception", "Color differentiation"],
|
83 |
+
"Ears": ["Hearing", "Balance maintenance", "Sound localization"],
|
84 |
+
"Nose": ["Smell detection", "Olfactory signaling", "Air filtration"],
|
85 |
+
"Tongue": ["Taste perception", "Texture sensing", "Temperature feeling"],
|
86 |
+
"Skin": ["Touch sensation", "Temperature regulation", "Protection against pathogens"],
|
87 |
+
},
|
88 |
+
"🫁 Respiratory System": {
|
89 |
+
"Lungs": ["Gas exchange", "Oxygen intake", "Carbon dioxide expulsion"],
|
90 |
+
"Trachea": ["Airway protection", "Mucus secretion", "Cough reflex"],
|
91 |
+
},
|
92 |
+
"❤️ Circulatory System": {
|
93 |
+
"Heart": ["Blood pumping", "Circulatory regulation", "Oxygen and nutrients distribution"],
|
94 |
+
"Blood Vessels": ["Blood transport", "Nutrient delivery", "Waste removal"],
|
95 |
+
},
|
96 |
+
"🍽️ Digestive System": {
|
97 |
+
"Stomach": ["Food breakdown", "Enzyme secretion", "Nutrient digestion"],
|
98 |
+
"Intestines": ["Nutrient absorption", "Waste processing", "Microbiome hosting"],
|
99 |
+
},
|
100 |
+
"💪 Musculoskeletal System": {
|
101 |
+
"Bones": ["Structural support", "Protection of organs", "Mineral storage"],
|
102 |
+
"Muscles": ["Movement facilitation", "Posture maintenance", "Heat production"],
|
103 |
+
},
|
104 |
+
"🚽 Excretory System": {
|
105 |
+
"Kidneys": ["Waste filtration", "Water balance", "Electrolyte regulation"],
|
106 |
+
"Bladder": ["Urine storage", "Excretion control", "Toxin removal"],
|
107 |
+
},
|
108 |
+
"💞 Endocrine System": {
|
109 |
+
"Thyroid": ["Metabolic regulation", "Hormone secretion", "Energy management"],
|
110 |
+
"Adrenal Glands": ["Stress response", "Metabolism control", "Immune system regulation"],
|
111 |
+
},
|
112 |
+
"🧬 Reproductive System": {
|
113 |
+
"Male Reproductive Organs": ["Sperm production", "Sexual function", "Hormone synthesis"],
|
114 |
+
"Female Reproductive Organs": ["Egg production", "Fetus gestation", "Hormone regulation"],
|
115 |
+
},
|
116 |
+
"🩸 Immune System": {
|
117 |
+
"White Blood Cells": ["Pathogen defense", "Infection response", "Immunity maintenance"],
|
118 |
+
"Lymphatic System": ["Fluid balance", "Waste removal", "Antibody production"],
|
119 |
+
},
|
120 |
+
"🧘 Integrative Body Functions": {
|
121 |
+
"Sleep Regulation": ["Rest and recovery", "Memory consolidation", "Energy conservation"],
|
122 |
+
"Stress Management": ["Coping mechanisms", "Hormonal balance", "Emotional regulation"],
|
123 |
+
},
|
124 |
+
"🔬 Research and Innovations": {
|
125 |
+
"Genetic Studies": ["Disease predisposition", "Trait inheritance", "Gene therapy"],
|
126 |
+
"Biomedical Engineering": ["Medical devices", "Prosthetics design", "Healthcare technologies"],
|
127 |
+
},
|
128 |
+
"🎓 Education and Awareness": {
|
129 |
+
"Anatomy and Physiology": ["Body structure", "Function understanding", "Health education"],
|
130 |
+
"Public Health Initiatives": ["Disease prevention", "Health promotion", "Community wellness"],
|
131 |
+
},
|
132 |
+
}
|
133 |
+
|
134 |
+
|
135 |
+
|
136 |
# Ensure the directory for storing scores exists
|
137 |
score_dir = "scores"
|
138 |
os.makedirs(score_dir, exist_ok=True)
|
|
|
167 |
return score_data["score"]
|
168 |
return 0
|
169 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
170 |
|
171 |
|
172 |
def search_glossary(query):
|
|
|
|
|
|
|
|
|
173 |
|
174 |
st.write('## ' + query)
|
175 |
|
|
|
208 |
|
209 |
|
210 |
# Function to display the entire glossary in a grid format with links
|
211 |
+
def display_glossary_grid(body_map_data):
|
212 |
search_urls = {
|
213 |
"📖": lambda k: f"https://en.wikipedia.org/wiki/{quote(k)}",
|
214 |
"🔍": lambda k: f"https://www.google.com/search?q={quote(k)}",
|
215 |
"▶️": lambda k: f"https://www.youtube.com/results?search_query={quote(k)}",
|
216 |
"🔎": lambda k: f"https://www.bing.com/search?q={quote(k)}",
|
217 |
+
"🎲": lambda k: f"https://huggingface.co/spaces/awacke1/AI-ChatGPT-CPT-Body-Map-Cost?q={quote(k)}", # this url plus query!
|
218 |
|
219 |
}
|
220 |
|
221 |
+
for category, details in body_map_data.items():
|
222 |
st.write(f"### {category}")
|
223 |
cols = st.columns(len(details)) # Create dynamic columns based on the number of games
|
224 |
for idx, (game, terms) in enumerate(details.items()):
|
|
|
254 |
|
255 |
# Adjusted display_buttons_with_scores function
|
256 |
def display_buttons_with_scores():
|
257 |
+
for category, games in body_map_data.items():
|
258 |
category_emoji = topic_emojis.get(category, "🔍") # Default to search icon if no match
|
259 |
st.markdown(f"## {category_emoji} {category}")
|
260 |
for game, terms in games.items():
|
|
|
269 |
# -----------------------------------------------------------------
|
270 |
# query_body = f"Create a detailed outline for **{term}** with subpoints highlighting key aspects, using emojis for visual engagement. Include step-by-step rules and boldface important entities and ruleset elements."
|
271 |
query_body = f"Create a streamlit python app.py that produces a detailed markdown outline and CSV dataset user interface with an outline for **{term}** with subpoints highlighting key aspects, using emojis for visual engagement. Include step-by-step rules and boldface important entities and ruleset elements."
|
272 |
+
response = search_glossary(query_prefix + query_body, body_map_data)
|
273 |
|
274 |
|
275 |
def fetch_wikipedia_summary(keyword):
|
|
|
355 |
|
356 |
|
357 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
358 |
# 1. Constants and Top Level UI Variables
|
359 |
|
360 |
# My Inference API Copy
|
|
|
373 |
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."
|
374 |
should_save = st.sidebar.checkbox("💾 Save", value=True, help="Save your session data.")
|
375 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
376 |
def SpeechSynthesis(result):
|
377 |
documentHTML5='''
|
378 |
<!DOCTYPE html>
|
|
|
587 |
else:
|
588 |
return ""
|
589 |
|
590 |
+
# 11. Chat with GPT - Caution on quota
|
591 |
@st.cache_resource
|
592 |
def chat_with_model(prompt, document_section='', model_choice='gpt-3.5-turbo'):
|
593 |
model = model_choice
|
|
|
619 |
st.write(time.time() - start_time)
|
620 |
return full_reply_content
|
621 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
622 |
def extract_mime_type(file):
|
623 |
if isinstance(file, str):
|
624 |
pattern = r"type='(.*?)'"
|
|
|
823 |
st.write(f"Showing resources or questions related to: {topic}")
|
824 |
|
825 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
826 |
# 17. Main
|
827 |
def main():
|
828 |
prompt = f"Write ten funny jokes that are tweet length stories that make you laugh. Show as markdown outline with emojis for each."
|
|
|
1073 |
#st.markdown("## Glossary Lookup\nEnter a term in the URL query, like `?q=Nanotechnology` or `?query=Martian Syndicate`.")
|
1074 |
|
1075 |
st.markdown('''
|
1076 |
+
### Mixable AI 🃏🚀📚
|
|
|
|
|
|
|
|
|
1077 |
''')
|
1078 |
|
1079 |
try:
|
|
|
1086 |
st.markdown('No glossary lookup')
|
1087 |
|
1088 |
# Display the glossary grid
|
1089 |
+
st.title("Body Map Glossary 🎲")
|
1090 |
+
display_glossary_grid(body_map_data)
|
1091 |
st.title("🎲🗺️ Card Game Universe")
|
1092 |
st.markdown("## Explore the vast universes of Dungeons and Dragons, Call of Cthulhu, GURPS, and more through interactive storytelling and encyclopedic knowledge.🌠")
|
1093 |
|