Update app.py
Browse files
app.py
CHANGED
@@ -18,18 +18,23 @@ def vote_story(index):
|
|
18 |
def break_into_sentences(story):
|
19 |
return story.split(". ")
|
20 |
|
|
|
|
|
|
|
|
|
|
|
21 |
# Function to display story and voting
|
22 |
def display_story(index, row):
|
23 |
sentences = break_into_sentences(row['story'])
|
24 |
for sentence in sentences:
|
25 |
st.text(sentence)
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
27 |
vote_story(index)
|
28 |
-
|
29 |
-
# Display a small bar chart for vote count
|
30 |
-
fig, ax = plt.subplots()
|
31 |
-
ax.barh(['Votes'], [row['votes']])
|
32 |
-
st.pyplot(fig)
|
33 |
|
34 |
# Initialize session state for the vote counts
|
35 |
if 'df' not in st.session_state:
|
@@ -38,9 +43,9 @@ if 'df' not in st.session_state:
|
|
38 |
except FileNotFoundError:
|
39 |
st.session_state.df = pd.DataFrame({
|
40 |
'story': [
|
41 |
-
"A 45-year-old man presents with a long history of ulcers on the bottom of his feet.
|
42 |
-
"A 24-year-old man, an information technology professional, gets himself tested for serum immunoglobulin M (IgM) levels.
|
43 |
-
"A 33-year-old woman who was recently involved in a motor vehicle accident presents to a medical clinic for a follow-up visit.
|
44 |
],
|
45 |
'votes': [0, 0, 0]
|
46 |
})
|
@@ -51,16 +56,19 @@ st.title('Medical Story Voting 🗳️')
|
|
51 |
|
52 |
# Display stories and voting buttons
|
53 |
for index, row in st.session_state.df.iterrows():
|
54 |
-
|
55 |
-
with col1:
|
56 |
-
display_story(index, row)
|
57 |
-
with col2:
|
58 |
-
st.write(f"Votes: {row['votes']}")
|
59 |
|
60 |
# Display total votes
|
61 |
st.markdown("### 📊 Vote Summary")
|
62 |
st.table(st.session_state.df)
|
63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
# Reload votes from file every 30 seconds
|
65 |
if 'last_updated' not in st.session_state:
|
66 |
st.session_state.last_updated = time.time()
|
|
|
18 |
def break_into_sentences(story):
|
19 |
return story.split(". ")
|
20 |
|
21 |
+
# Function to extract high info words
|
22 |
+
def extract_high_info_words(sentence):
|
23 |
+
words = sentence.split(" ")
|
24 |
+
return [word for word in words if len(word) > 6]
|
25 |
+
|
26 |
# Function to display story and voting
|
27 |
def display_story(index, row):
|
28 |
sentences = break_into_sentences(row['story'])
|
29 |
for sentence in sentences:
|
30 |
st.text(sentence)
|
31 |
+
|
32 |
+
high_info_words = []
|
33 |
+
for sentence in sentences:
|
34 |
+
high_info_words.extend(extract_high_info_words(sentence))
|
35 |
+
|
36 |
+
if st.button(f"Vote for: {' '.join(high_info_words)}"):
|
37 |
vote_story(index)
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
# Initialize session state for the vote counts
|
40 |
if 'df' not in st.session_state:
|
|
|
43 |
except FileNotFoundError:
|
44 |
st.session_state.df = pd.DataFrame({
|
45 |
'story': [
|
46 |
+
"A 45-year-old man presents with a long history of ulcers on the bottom of his feet.",
|
47 |
+
"A 24-year-old man, an information technology professional, gets himself tested for serum immunoglobulin M (IgM) levels.",
|
48 |
+
"A 33-year-old woman who was recently involved in a motor vehicle accident presents to a medical clinic for a follow-up visit.",
|
49 |
],
|
50 |
'votes': [0, 0, 0]
|
51 |
})
|
|
|
56 |
|
57 |
# Display stories and voting buttons
|
58 |
for index, row in st.session_state.df.iterrows():
|
59 |
+
display_story(index, row)
|
|
|
|
|
|
|
|
|
60 |
|
61 |
# Display total votes
|
62 |
st.markdown("### 📊 Vote Summary")
|
63 |
st.table(st.session_state.df)
|
64 |
|
65 |
+
# Show all votes in one graph
|
66 |
+
fig, ax = plt.subplots()
|
67 |
+
ax.barh(st.session_state.df.index, st.session_state.df['votes'])
|
68 |
+
ax.set_yticks(st.session_state.df.index)
|
69 |
+
ax.set_yticklabels(st.session_state.df['story'])
|
70 |
+
st.pyplot(fig)
|
71 |
+
|
72 |
# Reload votes from file every 30 seconds
|
73 |
if 'last_updated' not in st.session_state:
|
74 |
st.session_state.last_updated = time.time()
|