|
import streamlit as st |
|
import pandas as pd |
|
import json |
|
|
|
|
|
def load_questions(): |
|
return pd.DataFrame([{"question": "What is the serum level in Alzheimer's?", "answer": "High", "topic": "Alzheimers"}, |
|
{"question": "What causes memory loss?", "answer": "Many factors", "topic": "Memory"}, |
|
{"question": "How is cognitive behavior therapy used?", "answer": "For mental health", "topic": "cognitive"}]) |
|
|
|
|
|
def vote_story(index): |
|
st.session_state.df.loc[index, 'votes'] += 1 |
|
st.session_state.df.to_csv('votes.csv', index=False) |
|
|
|
|
|
st.title("Medical App 🎙🗳️") |
|
|
|
|
|
if 'df' not in st.session_state: |
|
try: |
|
st.session_state.df = pd.read_csv('votes.csv') |
|
except FileNotFoundError: |
|
st.session_state.df = pd.DataFrame({'story': ['Story 1', 'Story 2'], 'votes': [0, 0]}) |
|
st.session_state.df.to_csv('votes.csv', index=False) |
|
|
|
|
|
tab = st.selectbox("Choose a Tab", ["USMLE Questions", "Story Voting"]) |
|
|
|
if tab == "USMLE Questions": |
|
questions_df = load_questions() |
|
|
|
medical_keywords = ["Brain 🧠", "Memory 📔", "Alzheimers 🌀", "Cognitive 🤔", "Mental 💭", "Behavior 🎭"] |
|
|
|
for keyword in medical_keywords: |
|
keyword_clean = keyword.split(" ")[0] |
|
if st.button(keyword): |
|
filtered_data = questions_df[questions_df['topic'].str.contains(keyword_clean, case=False)] |
|
st.write(f"Filtered Dataset by '{keyword_clean}' 📊") |
|
st.dataframe(filtered_data.iloc[:, :3]) |
|
|
|
elif tab == "Story Voting": |
|
for index, row in st.session_state.df.iterrows(): |
|
if st.button(f"Vote for: {row['story']}"): |
|
vote_story(index) |
|
st.table(st.session_state.df) |
|
st.bar_chart(st.session_state.df.set_index('story')['votes']) |
|
|