Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -33,61 +33,55 @@ from PyPDF2 import PdfReader
|
|
33 |
from templates import bot_template, css, user_template
|
34 |
from xml.etree import ElementTree as ET
|
35 |
|
36 |
-
|
37 |
-
import streamlit as st
|
38 |
-
from datasets import load_dataset
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
# π Streamlit App π
|
44 |
-
st.title("USMLE Step 1 Dataset Viewer")
|
45 |
-
|
46 |
-
# π Check if dataset is empty
|
47 |
-
if len(dataset) == 0:
|
48 |
-
st.write("π’ The dataset is empty.")
|
49 |
-
else:
|
50 |
-
st.write("""
|
51 |
-
π Use the search box to filter questions or use the grid to scroll through the dataset.
|
52 |
-
""")
|
53 |
-
|
54 |
-
# π©βπ¬ Search Box
|
55 |
-
search_term = st.text_input("Search for a specific question:", "")
|
56 |
-
# π Pagination
|
57 |
-
records_per_page = 100
|
58 |
-
num_records = len(dataset)
|
59 |
-
num_pages = max(int(num_records / records_per_page), 1)
|
60 |
-
|
61 |
-
# Skip generating the slider if num_pages is 1 (i.e., all records fit in one page)
|
62 |
-
if num_pages > 1:
|
63 |
-
page_number = st.select_slider("Select page:", options=list(range(1, num_pages + 1)))
|
64 |
else:
|
65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
if search_term:
|
76 |
-
if search_term.lower() in record['text'].lower():
|
77 |
filtered_data.append(record)
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
st.write("
|
89 |
-
|
90 |
-
st.write(f"π Total Records: {num_records} | π Displaying {start_idx+1} to {min(end_idx, num_records)}")
|
91 |
|
92 |
|
93 |
|
@@ -157,6 +151,37 @@ def add_witty_humor_buttons():
|
|
157 |
if col7[0].button("More Funny Rhymes ποΈ"):
|
158 |
StreamLLMChatResponse(descriptions["More Funny Rhymes ποΈ"])
|
159 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
160 |
|
161 |
# 3. Stream Llama Response
|
162 |
@st.cache_resource
|
@@ -196,36 +221,7 @@ def StreamLLMChatResponse(prompt):
|
|
196 |
|
197 |
except:
|
198 |
st.write('Stream llm issue')
|
199 |
-
|
200 |
-
documentHTML5='''
|
201 |
-
<!DOCTYPE html>
|
202 |
-
<html>
|
203 |
-
<head>
|
204 |
-
<title>Read It Aloud</title>
|
205 |
-
<script type="text/javascript">
|
206 |
-
function readAloud() {
|
207 |
-
const text = document.getElementById("textArea").value;
|
208 |
-
const speech = new SpeechSynthesisUtterance(text);
|
209 |
-
window.speechSynthesis.speak(speech);
|
210 |
-
}
|
211 |
-
</script>
|
212 |
-
</head>
|
213 |
-
<body>
|
214 |
-
<h1>π Read It Aloud</h1>
|
215 |
-
<textarea id="textArea" rows="10" cols="80">
|
216 |
-
'''
|
217 |
-
documentHTML5 = documentHTML5 + result
|
218 |
-
documentHTML5 = documentHTML5 + '''
|
219 |
-
</textarea>
|
220 |
-
<br>
|
221 |
-
<button onclick="readAloud()">π Read Aloud</button>
|
222 |
-
</body>
|
223 |
-
</html>
|
224 |
-
'''
|
225 |
-
|
226 |
-
import streamlit.components.v1 as components # Import Streamlit
|
227 |
-
components.html(documentHTML5, width=1280, height=1024)
|
228 |
-
return result
|
229 |
except:
|
230 |
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).')
|
231 |
|
@@ -638,6 +634,8 @@ def main():
|
|
638 |
filename = generate_filename(user_prompt, choice)
|
639 |
create_file(filename, user_prompt, response, should_save)
|
640 |
st.sidebar.markdown(get_table_download_link(filename), unsafe_allow_html=True)
|
|
|
|
|
641 |
all_files = glob.glob("*.*")
|
642 |
all_files = [file for file in all_files if len(os.path.splitext(file)[0]) >= 20] # exclude files with short names
|
643 |
all_files.sort(key=lambda x: (os.path.splitext(x)[1], x), reverse=True) # sort by file type and file name in descending order
|
@@ -657,6 +655,7 @@ def main():
|
|
657 |
with open(file, 'r') as f:
|
658 |
file_contents = f.read()
|
659 |
next_action='md'
|
|
|
660 |
with col2:
|
661 |
st.markdown(get_table_download_link(file), unsafe_allow_html=True)
|
662 |
with col3:
|
@@ -664,11 +663,13 @@ def main():
|
|
664 |
with open(file, 'r') as f:
|
665 |
file_contents = f.read()
|
666 |
next_action='open'
|
|
|
667 |
with col4:
|
668 |
if st.button("π", key="read_"+file): # search emoji button
|
669 |
with open(file, 'r') as f:
|
670 |
file_contents = f.read()
|
671 |
next_action='search'
|
|
|
672 |
with col5:
|
673 |
if st.button("π", key="delete_"+file):
|
674 |
os.remove(file)
|
|
|
33 |
from templates import bot_template, css, user_template
|
34 |
from xml.etree import ElementTree as ET
|
35 |
|
36 |
+
def add_Med_Licensing_Exam_Dataset():
|
37 |
+
import streamlit as st
|
38 |
+
from datasets import load_dataset
|
39 |
+
dataset = load_dataset("augtoma/usmle_step_1")['test'] # Using 'test' split
|
40 |
+
st.title("USMLE Step 1 Dataset Viewer")
|
41 |
+
if len(dataset) == 0:
|
42 |
+
st.write("π’ The dataset is empty.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
else:
|
44 |
+
st.write("""
|
45 |
+
π Use the search box to filter questions or use the grid to scroll through the dataset.
|
46 |
+
""")
|
47 |
+
|
48 |
+
# π©βπ¬ Search Box
|
49 |
+
search_term = st.text_input("Search for a specific question:", "")
|
50 |
+
# π Pagination
|
51 |
+
records_per_page = 100
|
52 |
+
num_records = len(dataset)
|
53 |
+
num_pages = max(int(num_records / records_per_page), 1)
|
54 |
+
|
55 |
+
# Skip generating the slider if num_pages is 1 (i.e., all records fit in one page)
|
56 |
+
if num_pages > 1:
|
57 |
+
page_number = st.select_slider("Select page:", options=list(range(1, num_pages + 1)))
|
58 |
+
else:
|
59 |
+
page_number = 1 # Only one page
|
60 |
+
|
61 |
+
# π Display Data
|
62 |
+
start_idx = (page_number - 1) * records_per_page
|
63 |
+
end_idx = start_idx + records_per_page
|
64 |
|
65 |
+
# π§ͺ Apply the Search Filter
|
66 |
+
filtered_data = []
|
67 |
+
for record in dataset[start_idx:end_idx]:
|
68 |
+
if isinstance(record, dict) and 'text' in record and 'id' in record:
|
69 |
+
if search_term:
|
70 |
+
if search_term.lower() in record['text'].lower():
|
71 |
+
filtered_data.append(record)
|
72 |
+
else:
|
|
|
|
|
73 |
filtered_data.append(record)
|
74 |
+
|
75 |
+
# π Render the Grid
|
76 |
+
for record in filtered_data:
|
77 |
+
st.write(f"## Question ID: {record['id']}")
|
78 |
+
st.write(f"### Question:")
|
79 |
+
st.write(f"{record['text']}")
|
80 |
+
st.write(f"### Answer:")
|
81 |
+
st.write(f"{record['answer']}")
|
82 |
+
st.write("---")
|
83 |
+
|
84 |
+
st.write(f"π Total Records: {num_records} | π Displaying {start_idx+1} to {min(end_idx, num_records)}")
|
|
|
|
|
85 |
|
86 |
|
87 |
|
|
|
151 |
if col7[0].button("More Funny Rhymes ποΈ"):
|
152 |
StreamLLMChatResponse(descriptions["More Funny Rhymes ποΈ"])
|
153 |
|
154 |
+
def addDocumentHTML5(result):
|
155 |
+
documentHTML5='''
|
156 |
+
<!DOCTYPE html>
|
157 |
+
<html>
|
158 |
+
<head>
|
159 |
+
<title>Read It Aloud</title>
|
160 |
+
<script type="text/javascript">
|
161 |
+
function readAloud() {
|
162 |
+
const text = document.getElementById("textArea").value;
|
163 |
+
const speech = new SpeechSynthesisUtterance(text);
|
164 |
+
window.speechSynthesis.speak(speech);
|
165 |
+
}
|
166 |
+
</script>
|
167 |
+
</head>
|
168 |
+
<body>
|
169 |
+
<h1>π Read It Aloud</h1>
|
170 |
+
<textarea id="textArea" rows="10" cols="80">
|
171 |
+
'''
|
172 |
+
documentHTML5 = documentHTML5 + result
|
173 |
+
documentHTML5 = documentHTML5 + '''
|
174 |
+
</textarea>
|
175 |
+
<br>
|
176 |
+
<button onclick="readAloud()">π Read Aloud</button>
|
177 |
+
</body>
|
178 |
+
</html>
|
179 |
+
'''
|
180 |
+
|
181 |
+
import streamlit.components.v1 as components # Import Streamlit
|
182 |
+
components.html(documentHTML5, width=1280, height=1024)
|
183 |
+
return result
|
184 |
+
|
185 |
|
186 |
# 3. Stream Llama Response
|
187 |
@st.cache_resource
|
|
|
221 |
|
222 |
except:
|
223 |
st.write('Stream llm issue')
|
224 |
+
add_documentHTML5(result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
225 |
except:
|
226 |
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).')
|
227 |
|
|
|
634 |
filename = generate_filename(user_prompt, choice)
|
635 |
create_file(filename, user_prompt, response, should_save)
|
636 |
st.sidebar.markdown(get_table_download_link(filename), unsafe_allow_html=True)
|
637 |
+
|
638 |
+
# Compose a file sidebar of past encounters
|
639 |
all_files = glob.glob("*.*")
|
640 |
all_files = [file for file in all_files if len(os.path.splitext(file)[0]) >= 20] # exclude files with short names
|
641 |
all_files.sort(key=lambda x: (os.path.splitext(x)[1], x), reverse=True) # sort by file type and file name in descending order
|
|
|
655 |
with open(file, 'r') as f:
|
656 |
file_contents = f.read()
|
657 |
next_action='md'
|
658 |
+
addDocumentHTML5(file_contents)
|
659 |
with col2:
|
660 |
st.markdown(get_table_download_link(file), unsafe_allow_html=True)
|
661 |
with col3:
|
|
|
663 |
with open(file, 'r') as f:
|
664 |
file_contents = f.read()
|
665 |
next_action='open'
|
666 |
+
addDocumentHTML5(file_contents)
|
667 |
with col4:
|
668 |
if st.button("π", key="read_"+file): # search emoji button
|
669 |
with open(file, 'r') as f:
|
670 |
file_contents = f.read()
|
671 |
next_action='search'
|
672 |
+
addDocumentHTML5(file_contents)
|
673 |
with col5:
|
674 |
if st.button("π", key="delete_"+file):
|
675 |
os.remove(file)
|