awacke1 commited on
Commit
a061b45
·
1 Parent(s): 2e42b59

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -224
app.py CHANGED
@@ -1,225 +1,41 @@
1
  import streamlit as st
2
- import json
3
-
4
- urls = [
5
- "https://huggingface.co/spaces/awacke1/CB-GR-Chatbot-Blenderbot",
6
- "https://huggingface.co/spaces/awacke1/TTS-STT-Blocks",
7
- "https://huggingface.co/spaces/awacke1/Prompt-Refinery-Text-to-Image-Generation",
8
- "https://huggingface.co/spaces/awacke1/Video-Summary",
9
- "https://huggingface.co/spaces/awacke1/AI-MovieMaker-Comedy",
10
- "https://huggingface.co/spaces/awacke1/ChatGPT-Memory-Chat-Story-Generator",
11
- "https://huggingface.co/spaces/awacke1/CloneAnyVoice",
12
- "https://huggingface.co/spaces/awacke1/ChatGPT-Streamlit-2",
13
- "https://huggingface.co/spaces/awacke1/WikipediaUltimateAISearch",
14
- "https://huggingface.co/spaces/awacke1/RLHF.Cognitive.Episodic.Semantic.Memory",
15
- "https://huggingface.co/spaces/awacke1/Memory-Shared",
16
- "https://huggingface.co/spaces/awacke1/VideoSwap",
17
- "https://huggingface.co/spaces/awacke1/AI-Wikipedia-Search",
18
- "https://huggingface.co/spaces/awacke1/AutoMLUsingStreamlit-Plotly",
19
- "https://huggingface.co/spaces/awacke1/NLP-Lyric-Chorus-Image",
20
- "https://huggingface.co/spaces/awacke1/OpenAssistant-Chatbot-FTW-Open-Source",
21
- "https://huggingface.co/spaces/awacke1/ChatGPTStreamlit7",
22
- "https://huggingface.co/spaces/awacke1/MultiPDF-QA-ChatGPT-Langchain",
23
- "https://huggingface.co/spaces/awacke1/SOTA-Plan",
24
- "https://huggingface.co/spaces/awacke1/AIandSmartTools",
25
- "https://huggingface.co/spaces/awacke1/3DVirtualFood",
26
- "https://huggingface.co/spaces/awacke1/Gradio-Gallery-Health-Medical-Icon-Sets",
27
- "https://huggingface.co/spaces/awacke1/DatasetAnalyzer",
28
- "https://huggingface.co/spaces/awacke1/PrompTart",
29
- "https://huggingface.co/spaces/awacke1/sileod-deberta-v3-base-tasksource-nli",
30
- "https://huggingface.co/spaces/awacke1/File-Memory-Operations-Human-Feedback-Gradio",
31
- "https://huggingface.co/spaces/awacke1/Bloom.Big.Science.Continual.Generator",
32
- "https://huggingface.co/spaces/awacke1/Ontology-Gradio",
33
- "https://huggingface.co/spaces/awacke1/HTML5-Aframe-3dMap-Flight",
34
- "https://huggingface.co/spaces/awacke1/Bloom.Generative.Writer",
35
- "https://huggingface.co/spaces/awacke1/Voice-ChatGPT-Streamlit-12",
36
- "https://huggingface.co/spaces/awacke1/HTML5-AR-VR",
37
- "https://huggingface.co/spaces/awacke1/AnimationAI",
38
- "https://huggingface.co/spaces/awacke1/GenerativeWordsandImages",
39
- "https://huggingface.co/spaces/awacke1/AR-VR-IOT-Demo",
40
- "https://huggingface.co/spaces/awacke1/ArtStyleFoodsandNutrition",
41
- "https://huggingface.co/spaces/awacke1/CarePlanQnAWithContext",
42
- "https://huggingface.co/spaces/awacke1/VideoSummaryYoutube3",
43
- "https://huggingface.co/spaces/awacke1/AW-01ST-CSV-Dataset-Analyzer",
44
- "https://huggingface.co/spaces/awacke1/Try.Playing.Learning.Sharing.On.This",
45
- "https://huggingface.co/spaces/awacke1/google-flan-t5-base",
46
- "https://huggingface.co/spaces/awacke1/PubMed-Parrot-Paraphraser-on-T5",
47
- "https://huggingface.co/spaces/awacke1/Writing-Grammar-And-Paraphrase-w-Pegasus",
48
- "https://huggingface.co/spaces/awacke1/runwayml-stable-diffusion-v1-5",
49
- "https://huggingface.co/spaces/awacke1/DockerGoFlanT5",
50
- "https://huggingface.co/spaces/awacke1/GradioContinualGenerator",
51
- "https://huggingface.co/spaces/awacke1/StreamlitSuperPowerCheatSheet"
52
- ]
53
-
54
- # Extract the last part of each URL (after the last '/') to serve as the name of the button
55
- url_names = [url.split('/')[-1] for url in urls]
56
-
57
- # Associate each URL with a relevant emoji based on keywords in its name
58
- emoji_mapping = {
59
- "Chatbot": "🤖",
60
- "TTS": "🗣️",
61
- "STT": "👂",
62
- "Video": "🎥",
63
- "MovieMaker": "🍿",
64
- "ChatGPT": "💬",
65
- "Voice": "🎙️",
66
- "Wikipedia": "📖",
67
- "Memory": "🧠",
68
- "AI": "🧠",
69
- "OpenAssistant": "🤝",
70
- "3D": "🕶️",
71
- "AR": "👓",
72
- "VR": "🕶️",
73
- "Animation": "🖌️",
74
- "Dataset": "📊",
75
- "Gradio": "📻",
76
- "HTML5": "🌐",
77
- "Writing": "✍️",
78
- "Grammar": "🖋️",
79
- "Paraphrase": "🔄",
80
- "Streamlit": "🌠"
81
- }
82
-
83
- # Map each URL name to its most relevant emoji
84
- url_emojis = []
85
- for name in url_names:
86
- associated_emoji = "🔗" # Default emoji
87
- for keyword, emoji in emoji_mapping.items():
88
- if keyword in name:
89
- associated_emoji = emoji
90
- break
91
- url_emojis.append(associated_emoji)
92
-
93
- #url_emojis[:5], url_names[:5] # Display the first 5 URL names with their associated emojis
94
-
95
- import streamlit as st
96
- import json
97
- import webbrowser
98
-
99
- # Function to load the history of clicks from the text file
100
- def load_history():
101
- try:
102
- with open("click_history.txt", "r") as f:
103
- return json.load(f)
104
- except FileNotFoundError:
105
- return {url: 0 for url in urls}
106
-
107
- # Function to save the updated history of clicks to the text file
108
- def save_history(history):
109
- with open("click_history.txt", "w") as f:
110
- json.dump(history, f)
111
-
112
- # Load the history of clicks
113
- history = load_history()
114
-
115
- # Display the buttons for each URL
116
- for url, name, emoji in zip(urls, url_names, url_emojis):
117
- if st.button(f"{emoji} {name}"):
118
- # Open the URL in a new browser tab using JavaScript
119
- st.write('<script>window.open("'+url+'", "_blank");</script>', unsafe_allow_html=True)
120
- # Update the history of clicks
121
- history[url] += 1
122
- save_history(history)
123
- # Display the number of times the URL was opened below its corresponding button
124
- st.write(f"Clicked: {history[url]} times")
125
-
126
- import time
127
- from bokeh.plotting import figure
128
- from bokeh.models import ColumnDataSource
129
-
130
- # ... [rest of the initial code remains unchanged] ...
131
-
132
- # Streamlit app
133
- def main():
134
-
135
- # Session state to hold the value of AutoRepeat button across reruns
136
- if "auto_repeat" not in st.session_state:
137
- st.session_state.auto_repeat = "On"
138
- if "current_index" not in st.session_state:
139
- st.session_state.current_index = 0 # Use 0 as a default index
140
-
141
- # Load the history of clicks
142
- history = load_history()
143
-
144
- # Display the buttons for each URL
145
- for url, name, emoji in zip(urls, url_names, url_emojis):
146
- #if st.button(f"{emoji} {name}"):
147
- if st.button(f"{emoji} {name}", key=url): # using the URL as the unique key
148
- # Open the URL in a new browser tab using JavaScript
149
- st.write('<script>window.open("'+url+'", "_blank");</script>', unsafe_allow_html=True)
150
- # Update the history of clicks
151
- history[url] += 1
152
- save_history(history)
153
- # Display the number of times the URL was opened below its corresponding button
154
- st.write(f"Clicked: {history[url]} times")
155
-
156
- # Function to load the history of clicks from the text file
157
- def load_history():
158
- try:
159
- with open("click_history.txt", "r") as f:
160
- return json.load(f)
161
- except FileNotFoundError:
162
- return {url: 0 for url in urls}
163
-
164
- # Function to save the updated history of clicks to the text file
165
- def save_history(history):
166
- with open("click_history.txt", "w") as f:
167
- json.dump(history, f)
168
-
169
- # Streamlit app
170
- def main():
171
- # Load the history of clicks
172
- history = load_history()
173
-
174
- # Create a list of URLs with their associated names, emojis, and click counts
175
- url_data = [{'url': url, 'name': name, 'emoji': emoji, 'clicks': history[url]}
176
- for url, name, emoji in zip(urls, url_names, url_emojis)]
177
-
178
- # Sort the list by click counts in descending order
179
- url_data.sort(key=lambda x: x['clicks'], reverse=True)
180
-
181
- # Display the sorted URLs in columns up to four columns wide
182
- num_cols = min(4, len(url_data))
183
- cols = st.columns(num_cols)
184
-
185
- for i, data in enumerate(url_data):
186
- col = cols[i % num_cols]
187
- with col:
188
- try: # and figure out a solution to the duplicate key problem ;)
189
- if st.button(f"{emoji} {name}", key=url): # using the URL as the unique key
190
- # Open the URL in a new browser tab using JavaScript
191
- st.write('<script>window.open("'+data['url']+'", "_blank");</script>', unsafe_allow_html=True)
192
- # Update the history of clicks
193
- history[data['url']] += 1
194
- save_history(history)
195
- except:
196
- st.write('Keep Trying ;)')
197
- # Display the number of times the URL was opened below its corresponding button
198
- st.write(f"Clicked: {history[data['url']]} times")
199
-
200
-
201
-
202
- if __name__ == "__main__":
203
- main()
204
-
205
-
206
- # Timer logic
207
- if st.session_state.auto_repeat == "On":
208
- timer_placeholder = st.empty()
209
- for i in range(10, 0, -1):
210
- timer_placeholder.text(f"Reloading in {i} seconds...")
211
- time.sleep(1)
212
- history = load_history() # Reload the history after the countdown
213
-
214
- # Display the Bokeh graph showing the click counts
215
- non_zero_urls = [name for url, name in zip(urls, url_names) if history[url] > 0]
216
- non_zero_counts = [history[url] for url in urls if history[url] > 0]
217
-
218
- source = ColumnDataSource(data=dict(urls=non_zero_urls, counts=non_zero_counts))
219
-
220
- p = figure(x_range=non_zero_urls, plot_height=350, title="Click Counts per URL",
221
- toolbar_location=None, tools="")
222
- p.vbar(x='urls', top='counts', width=0.9, source=source)
223
- p.xaxis.major_label_orientation = 1.2
224
-
225
- st.bokeh_chart(p)
 
1
  import streamlit as st
2
+ import pandas as pd
3
+
4
+ # Create a dataset for stories and votes
5
+ df = pd.DataFrame({
6
+ 'story': [
7
+ "A 45-year-old man presents with a long history of ulcers on the bottom of his feet. 👣🚑",
8
+ "A 24-year-old man, an information technology professional, gets himself tested for serum immunoglobulin M (IgM) levels. 💻🧪",
9
+ "A 33-year-old woman who was recently involved in a motor vehicle accident presents to a medical clinic for a follow-up visit. 🚗🏥",
10
+ ],
11
+ 'votes': [0, 0, 0]
12
+ })
13
+
14
+ # Function to vote on a story
15
+ def vote_story(index):
16
+ df.loc[index, 'votes'] += 1
17
+
18
+ # Function to break story into sentences
19
+ def break_into_sentences(story):
20
+ return story.split(". ")
21
+
22
+ # Function to display story and voting
23
+ def display_story(index, row):
24
+ sentences = break_into_sentences(row['story'])
25
+ for sentence in sentences:
26
+ st.text(sentence)
27
+ st.button(f"Vote for Story {index + 1}", on_click=vote_story, args=(index,))
28
+
29
+ # Main app
30
+ st.title('Medical Story Voting 🗳️')
31
+
32
+ # Display stories and voting buttons
33
+ for index, row in df.iterrows():
34
+ col1, col2 = st.columns([3,1])
35
+ with col1:
36
+ display_story(index, row)
37
+ col2.write(f"Votes: {row['votes']}")
38
+
39
+ # Display total votes
40
+ st.markdown("### 📊 Vote Summary")
41
+ st.table(df)