File size: 1,436 Bytes
dfc9fe7
a061b45
628a01b
 
86d2fb9
a061b45
86d2fb9
 
 
 
a061b45
86d2fb9
a061b45
ad081e3
86d2fb9
a061b45
86d2fb9
 
a061b45
86d2fb9
628a01b
 
 
 
86d2fb9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import streamlit as st
import pandas as pd
import time
import matplotlib.pyplot as plt
import json

# Load USMLE questions from a JSON file
def load_questions():
    return pd.DataFrame([{"question": "What is the serum level of X?", "answer": "High"},
                         {"question": "What causes Y?", "answer": "Z"}])

# Vote for a story
def vote_story(index):
    st.session_state.df.loc[index, 'votes'] += 1
    st.session_state.df.to_csv('votes.csv', index=False)

# Streamlit App
st.title("Medical App 🎙🗳️")

# Initialize session state
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 layout
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'])