awacke1 commited on
Commit
1887ea3
·
verified ·
1 Parent(s): 4f0cb74

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -19
app.py CHANGED
@@ -1,5 +1,8 @@
1
  import streamlit as st
2
  import json
 
 
 
3
 
4
  urls = [
5
  "https://huggingface.co/spaces/awacke1/CB-GR-Chatbot-Blenderbot",
@@ -80,17 +83,6 @@ emoji_mapping = {
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
-
94
  def get_emoji(name):
95
  for key, emoji in emoji_mapping.items():
96
  if key in name:
@@ -113,20 +105,17 @@ def main():
113
 
114
  if 'current_url' not in st.session_state:
115
  st.session_state.current_url = None
116
-
117
  votes = load_votes()
118
 
119
- # Create two columns
120
  col1, col2 = st.columns([1, 2])
121
 
122
  with col1:
123
- # Create sorted list of items
124
  items = [{"url": url, "name": url.split('/')[-1],
125
  "emoji": get_emoji(url.split('/')[-1]),
126
  "votes": votes[url]} for url in urls]
127
  items.sort(key=lambda x: (-x["votes"], x["name"]))
128
 
129
- # Display buttons in 2 columns within col1
130
  button_cols = st.columns(2)
131
  for i, item in enumerate(items):
132
  with button_cols[i % 2]:
@@ -139,18 +128,31 @@ def main():
139
 
140
  with col2:
141
  if st.session_state.current_url:
142
- st.components.iframe(st.session_state.current_url, height=800, scrolling=True)
 
 
 
 
 
 
 
 
 
 
 
143
  else:
144
- st.write("Select an app to view")
145
 
146
- # Display vote graph at bottom of col1
147
  if any(votes.values()):
148
  with col1:
149
  source = ColumnDataSource({
150
  'names': [i["name"] for i in items if votes[i["url"]] > 0],
151
  'votes': [i["votes"] for i in items if votes[i["url"]] > 0]
152
  })
153
- p = figure(x_range=source.data['names'], height=250, title="Vote Counts")
 
 
 
154
  p.vbar(x='names', top='votes', width=0.9, source=source)
155
  p.xaxis.major_label_orientation = 1.2
156
  st.bokeh_chart(p)
 
1
  import streamlit as st
2
  import json
3
+ import time
4
+ from bokeh.plotting import figure
5
+ from bokeh.models import ColumnDataSource
6
 
7
  urls = [
8
  "https://huggingface.co/spaces/awacke1/CB-GR-Chatbot-Blenderbot",
 
83
  "Streamlit": "🌠"
84
  }
85
 
 
 
 
 
 
 
 
 
 
 
 
86
  def get_emoji(name):
87
  for key, emoji in emoji_mapping.items():
88
  if key in name:
 
105
 
106
  if 'current_url' not in st.session_state:
107
  st.session_state.current_url = None
108
+
109
  votes = load_votes()
110
 
 
111
  col1, col2 = st.columns([1, 2])
112
 
113
  with col1:
 
114
  items = [{"url": url, "name": url.split('/')[-1],
115
  "emoji": get_emoji(url.split('/')[-1]),
116
  "votes": votes[url]} for url in urls]
117
  items.sort(key=lambda x: (-x["votes"], x["name"]))
118
 
 
119
  button_cols = st.columns(2)
120
  for i, item in enumerate(items):
121
  with button_cols[i % 2]:
 
128
 
129
  with col2:
130
  if st.session_state.current_url:
131
+ html_string = f"""
132
+ <div style="width:100%; height:800px; overflow:hidden;">
133
+ <iframe src="{st.session_state.current_url}"
134
+ width="100%"
135
+ height="100%"
136
+ frameborder="0"
137
+ scrolling="yes"
138
+ style="border: 1px solid #ddd;">
139
+ </iframe>
140
+ </div>
141
+ """
142
+ st.components.v1.html(html_string, height=800)
143
  else:
144
+ st.info("Select an app to view")
145
 
 
146
  if any(votes.values()):
147
  with col1:
148
  source = ColumnDataSource({
149
  'names': [i["name"] for i in items if votes[i["url"]] > 0],
150
  'votes': [i["votes"] for i in items if votes[i["url"]] > 0]
151
  })
152
+ p = figure(x_range=source.data['names'],
153
+ height=250,
154
+ title="Vote Counts",
155
+ toolbar_location=None)
156
  p.vbar(x='names', top='votes', width=0.9, source=source)
157
  p.xaxis.major_label_orientation = 1.2
158
  st.bokeh_chart(p)