|
import streamlit as st |
|
import pandas as pd |
|
import time |
|
import matplotlib.pyplot as plt |
|
import json |
|
|
|
|
|
def load_questions(): |
|
return pd.DataFrame([{"question": "What is the serum level of X?", "answer": "High"}, |
|
{"question": "What causes Y?", "answer": "Z"}]) |
|
|
|
|
|
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() |
|
selected_q = st.selectbox('Select a question:', questions_df['question']) |
|
st.write(f"Answer: {questions_df.loc[questions_df['question'] == selected_q, 'answer'].values[0]}") |
|
|
|
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']) |
|
|