Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,20 +1,13 @@
|
|
1 |
import streamlit as st
|
2 |
-
from datetime import time, datetime
|
3 |
-
import time as t
|
4 |
-
from time import time as now
|
5 |
import pandas as pd
|
6 |
-
import pandas_profiling
|
7 |
-
import numpy as np
|
8 |
from streamlit_pandas_profiling import st_profile_report
|
9 |
-
from io import StringIO
|
10 |
-
import requests
|
11 |
from pathlib import Path
|
12 |
-
from
|
13 |
|
14 |
st.set_page_config(page_title="Francesco Daimon Fernicola", page_icon=":milky_way:", layout="wide")
|
15 |
|
16 |
with st.container():
|
17 |
-
st.subheader("Hello, and welcome to my official webpage! I am Daimon :
|
18 |
st.title("PhD Candidate in Machine Translation / Translator / Mountain enthusiast")
|
19 |
st.write("I am passionate about finding new ways to effectively use and understand Machine Translation and effectively evaluating its quality.")
|
20 |
st.write("""
|
@@ -24,318 +17,24 @@ with st.container():
|
|
24 |
[Twitter](https://twitter.com/FrancescoDaimon)
|
25 |
""")
|
26 |
|
27 |
-
st.
|
28 |
-
|
29 |
-
if st.button('Say hello'):
|
30 |
-
st.write('Why hello there')
|
31 |
-
else:
|
32 |
-
st.write('Goodbye')
|
33 |
-
|
34 |
-
st.header('st.slider')
|
35 |
-
st.subheader('Slider')
|
36 |
-
age = st.slider('How old are you?', 0, 120, 25)
|
37 |
-
st.write(f"I'm {age} years old")
|
38 |
-
|
39 |
-
|
40 |
-
st.subheader('Range Slider')
|
41 |
-
|
42 |
-
values = st.slider(
|
43 |
-
'Select a range of values',
|
44 |
-
0.0, 100.0, (25.0, 75.0)
|
45 |
-
)
|
46 |
-
st.write(f"Values: {values}")
|
47 |
-
|
48 |
-
|
49 |
-
st.subheader('Range time slider')
|
50 |
-
|
51 |
-
appointment = st.slider(
|
52 |
-
"Schedule your appointment:",
|
53 |
-
value=(time(11,30), time(12,45)),
|
54 |
-
format="hh:mm"
|
55 |
-
)
|
56 |
-
st.write(f"You're scheduled for: {appointment}")
|
57 |
-
|
58 |
-
|
59 |
-
st.subheader('Datetime slider')
|
60 |
-
|
61 |
-
start_time = st.slider(
|
62 |
-
"When do you start?",
|
63 |
-
value=datetime(2023, 1, 1, 9, 30),
|
64 |
-
format="DD/MM/YY - hh:mm"
|
65 |
-
)
|
66 |
-
|
67 |
-
st.write(f"Start time: {start_time}")
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
st.header('Line Chart')
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
chart_data = pd.DataFrame(
|
77 |
-
np.random.randn(20, 3),
|
78 |
-
columns=['a', 'b', 'c']
|
79 |
-
)
|
80 |
-
|
81 |
-
st.line_chart(chart_data)
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
with st.container():
|
86 |
-
option = st.selectbox(
|
87 |
-
'What is your favorite color?',
|
88 |
-
('Blue', 'Red', 'Green', 'More')
|
89 |
-
)
|
90 |
-
|
91 |
-
if not option == 'More':
|
92 |
-
st.write(f'Your favorite color is {option}')
|
93 |
-
else:
|
94 |
-
new_option = st.multiselect(
|
95 |
-
'What are your favorite colors',
|
96 |
-
['Green', 'Yellow', 'Red', 'Blue'],
|
97 |
-
['Yellow', 'Red']
|
98 |
-
)
|
99 |
-
st.write(f'Your favorite colors are {", ".join(new_option)}')
|
100 |
-
|
101 |
-
st.header('st.checkbox')
|
102 |
-
|
103 |
-
st.write('What would you like to order?')
|
104 |
-
|
105 |
-
icecream = st.checkbox('Ice cream')
|
106 |
-
coffee = st.checkbox('Coffee')
|
107 |
-
cola = st.checkbox('Cola')
|
108 |
-
|
109 |
-
if icecream:
|
110 |
-
st.write("Great! Heres some more :icecream:")
|
111 |
-
|
112 |
-
if coffee:
|
113 |
-
st.write("Okay, here's some coffee :coffee:")
|
114 |
-
|
115 |
-
if cola:
|
116 |
-
st.write("Here you go 🥤")
|
117 |
-
|
118 |
-
|
119 |
-
#st.header('streamlig_pandas_profiling')
|
120 |
-
|
121 |
-
#df = pd.read_csv('https://raw.githubusercontent.com/dataprofessor/data/master/penguins_cleaned.csv')
|
122 |
-
|
123 |
-
#pr = df.profile_report()
|
124 |
-
#st_profile_report(pr)
|
125 |
-
|
126 |
-
|
127 |
-
#st.write("Contents of the '.streamlit/config.toml' file of this app")
|
128 |
-
|
129 |
-
st.code("""
|
130 |
-
[theme]
|
131 |
-
primaryColor="#F39C12"
|
132 |
-
backgroundColor="#2E86C1"
|
133 |
-
secondaryBackgroundColor="#AED6F1"
|
134 |
-
textColor="#FFFFFF"
|
135 |
-
font="monospace"
|
136 |
-
""")
|
137 |
-
|
138 |
-
number = st.sidebar.slider('Select a number:', 0, 10, 5)
|
139 |
-
st.write(f'Selected number from slider widget is: {number}')
|
140 |
-
|
141 |
-
#st.header("This is taken from the .streamlit/secrets.toml")
|
142 |
-
|
143 |
-
#st.write(f"Secret message: {st.secrets['message']}")
|
144 |
-
#st.header("Remember to add the file to the .gitignore!")
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
st.title('st.file_uploader')
|
149 |
|
150 |
st.subheader('Input TSV/CSV')
|
151 |
uploaded_file = st.file_uploader("Choose a file")
|
152 |
-
|
153 |
-
if uploaded_file is not None:
|
154 |
-
|
155 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
156 |
else:
|
157 |
-
|
158 |
-
|
159 |
-
st.subheader("DataFrame")
|
160 |
-
st.write(data)
|
161 |
-
st.write(data.describe())
|
162 |
|
163 |
-
else:
|
164 |
-
st.info("☝️ Upload a TSV/CSV file")
|
165 |
-
|
166 |
-
|
167 |
-
with st.expander('About this app'):
|
168 |
-
st.write('This app shows the various options you can use (and should use) to customize your page')
|
169 |
-
st.image('https://imgs.xkcd.com/comics/app.png', width=250)
|
170 |
-
st.write('Below you will also display the progress of the calculation via "st.progress()"')
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
st.sidebar.header('Input')
|
175 |
-
user_name = st.sidebar.text_input('What is your name?')
|
176 |
-
user_emoji = st.sidebar.selectbox('Choose an emoji', ['', '😄', '😆', '😊', '😍', '😴', '😕', '😱'])
|
177 |
-
user_food = st.sidebar.selectbox('What is your favorite food?', ['', 'Tom Yum Kung', 'Burrito', 'Lasagna', 'Hamburger', 'Pizza'])
|
178 |
-
|
179 |
-
st.header('Output')
|
180 |
-
|
181 |
-
col1, col2, col3 = st.columns(3)
|
182 |
-
|
183 |
-
with col1:
|
184 |
-
if user_name != '':
|
185 |
-
st.write(f'👋 Hello {user_name}!')
|
186 |
-
else:
|
187 |
-
st.write('👈 Please enter your **name**!')
|
188 |
-
|
189 |
-
with col2:
|
190 |
-
if user_emoji != '':
|
191 |
-
st.write(f'{user_emoji} is your favorite **emoji**!')
|
192 |
-
else:
|
193 |
-
st.write('👈 Please choose an **emoji**!')
|
194 |
-
|
195 |
-
with col3:
|
196 |
-
if user_food != '':
|
197 |
-
st.write(f'🍴 **{user_food}** is your favorite **food**!')
|
198 |
-
else:
|
199 |
-
st.write('👈 Please choose your favorite **food**!')
|
200 |
-
|
201 |
-
|
202 |
-
#my_bar = st.progress(0)
|
203 |
-
|
204 |
-
#for percent_complete in range(100):
|
205 |
-
# t.sleep(0.05)
|
206 |
-
# my_bar.progress(percent_complete + 1)
|
207 |
-
|
208 |
-
st.metric(label="F1",
|
209 |
-
value="81.1",
|
210 |
-
delta="-0.1")
|
211 |
-
|
212 |
-
|
213 |
-
st.title('st.cache')
|
214 |
-
|
215 |
-
a0 = now()
|
216 |
-
st.subheader('Using st.cache')
|
217 |
-
|
218 |
-
@st.cache(suppress_st_warning=True)
|
219 |
-
def load_data_a():
|
220 |
-
dataframe = pd.DataFrame(
|
221 |
-
np.random.rand(2000000, 5),
|
222 |
-
columns=['a', 'b', 'c', 'd', 'e']
|
223 |
-
)
|
224 |
-
return dataframe
|
225 |
-
|
226 |
-
st.write(load_data_a())
|
227 |
-
a1 = now()
|
228 |
-
st.info(a1-a0)
|
229 |
-
|
230 |
-
b0 = now()
|
231 |
-
|
232 |
-
|
233 |
-
st.subheader('Not using st.cache')
|
234 |
-
|
235 |
-
def load_data_b():
|
236 |
-
dataframe = pd.DataFrame(
|
237 |
-
np.random.rand(2000000, 5),
|
238 |
-
columns=['a', 'b', 'c', 'd', 'e']
|
239 |
-
)
|
240 |
-
return dataframe
|
241 |
-
|
242 |
-
st.write(load_data_b())
|
243 |
-
b1 = now()
|
244 |
-
st.info(b1-b0)
|
245 |
-
|
246 |
-
st.title('st.session_state')
|
247 |
-
|
248 |
-
def lbs_to_kg():
|
249 |
-
st.session_state.kg = st.session_state.lbs/2.2046
|
250 |
-
|
251 |
-
def kg_to_lbs():
|
252 |
-
st.session_state.lbs = st.session_state.kg*2.2046
|
253 |
-
|
254 |
-
st.header('Input kg/lbs')
|
255 |
-
col1, spacer, col2 = st.columns([2, 1, 2])
|
256 |
-
|
257 |
-
with col1:
|
258 |
-
punds = st.number_input("Pounds:", key = "lbs", on_change = lbs_to_kg)
|
259 |
-
|
260 |
-
with col2:
|
261 |
-
kilogram = st.number_input("Kilograms:", key = "kg", on_change= kg_to_lbs)
|
262 |
-
|
263 |
-
st.header('Output')
|
264 |
-
st.write("st.session_state object: ", st.session_state)
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
st.title('🏀 Bored API app')
|
269 |
-
|
270 |
-
st.sidebar.header("Input Boredom")
|
271 |
-
selected_type = st.sidebar.selectbox('Select an activity type', ["education", "recreational", "social", "diy", "charity", "cooking", "relaxation", "music", "busywork"])
|
272 |
-
|
273 |
-
suggested_activity_url = f'http://www.boredapi.com/api/activity?type={selected_type}'
|
274 |
-
json_response = requests.get(suggested_activity_url)
|
275 |
-
suggested_activity = json_response.json()
|
276 |
-
|
277 |
-
|
278 |
-
c1, c2 = st.columns(2)
|
279 |
-
|
280 |
-
with c1:
|
281 |
-
with st.expander('About this app'):
|
282 |
-
st.write('Bored stiff? The **BORED API APP** gives suggestions on activities that you can do when bored. This is powered by Bored API.')
|
283 |
-
with c2:
|
284 |
-
with st.expander('JSON data'):
|
285 |
-
st.write(suggested_activity)
|
286 |
-
|
287 |
-
st.header('Suggested activity')
|
288 |
-
st.info(suggested_activity['activity'])
|
289 |
-
|
290 |
-
col1, col2, col3 = st.columns(3)
|
291 |
-
|
292 |
-
with col1:
|
293 |
-
st.metric(label="Number of Participants", value=suggested_activity['participants'], delta='')
|
294 |
-
with col2:
|
295 |
-
st.metric(label="Type of Activity", value=suggested_activity['type'].capitalize(), delta='')
|
296 |
-
with col3:
|
297 |
-
st.metric(label='Price', value=suggested_activity['price'], delta='')
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
media_url = st.text_input("Media URL", value="https://www.youtube.com/watch?v=9EcjWd-O4jI&ab_channel=TechnotronicVEVO")
|
302 |
-
|
303 |
-
layout = [
|
304 |
-
# Media item is positioned in coordinates x=0 and y=3, and takes 6/12 columns and has a height of 4.
|
305 |
-
dashboard.Item("media", 0, 2, 12, 4),
|
306 |
-
]
|
307 |
-
|
308 |
-
with elements("demo"):
|
309 |
-
|
310 |
-
# Create a new dashboard with the layout specified above.
|
311 |
-
#
|
312 |
-
# draggableHandle is a CSS query selector to define the draggable part of each dashboard item.
|
313 |
-
# Here, elements with a 'draggable' class name will be draggable.
|
314 |
-
#
|
315 |
-
# For more information on available parameters for dashboard grid:
|
316 |
-
# https://github.com/react-grid-layout/react-grid-layout#grid-layout-props
|
317 |
-
# https://github.com/react-grid-layout/react-grid-layout#responsive-grid-layout-props
|
318 |
-
|
319 |
-
with dashboard.Grid(layout, draggableHandle=".draggable"):
|
320 |
-
with mui.Card(key="media", sx={"display": "flex", "flexDirection": "column"}):
|
321 |
-
mui.CardHeader(title="Media Player", className="draggable")
|
322 |
-
with mui.CardContent(sx={"flex": 1, "minHeight": 0}):
|
323 |
-
|
324 |
-
# This element is powered by ReactPlayer, it supports many more players other
|
325 |
-
# than YouTube. You can check it out there: https://github.com/cookpete/react-player#props
|
326 |
-
|
327 |
-
media.Player(url=media_url, width="100%", height="100%", controls=True)
|
328 |
-
|
329 |
-
|
330 |
-
def local_css(file_name):
|
331 |
-
with open(file_name) as f:
|
332 |
-
st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)
|
333 |
-
|
334 |
-
local_css("style/style.css")
|
335 |
-
|
336 |
-
|
337 |
-
from transformers import MBartForConditionalGeneration, MBart50TokenizerFast
|
338 |
-
|
339 |
|
340 |
st.subheader("MBART-50 Translator")
|
341 |
|
@@ -347,7 +46,6 @@ tokenizer = MBart50TokenizerFast.from_pretrained("facebook/mbart-large-50-many-t
|
|
347 |
|
348 |
def get_translation(src_code, trg_code, src):
|
349 |
|
350 |
-
# translate Hindi to French
|
351 |
tokenizer.src_lang = src_code
|
352 |
encoded = tokenizer(src, return_tensors="pt")
|
353 |
generated_tokens = model.generate(
|
@@ -366,7 +64,6 @@ with st.form("my_form"):
|
|
366 |
src_lang = st.selectbox(
|
367 |
'Source language',
|
368 |
('en_XX', 'fr_XX', 'de_DE', 'it_IT', 'es_XX'),
|
369 |
-
|
370 |
)
|
371 |
with right_c:
|
372 |
trg_lang = st.selectbox(
|
|
|
1 |
import streamlit as st
|
|
|
|
|
|
|
2 |
import pandas as pd
|
|
|
|
|
3 |
from streamlit_pandas_profiling import st_profile_report
|
|
|
|
|
4 |
from pathlib import Path
|
5 |
+
from transformers import MBartForConditionalGeneration, MBart50TokenizerFast
|
6 |
|
7 |
st.set_page_config(page_title="Francesco Daimon Fernicola", page_icon=":milky_way:", layout="wide")
|
8 |
|
9 |
with st.container():
|
10 |
+
st.subheader("Hello, and welcome to my official webpage! I am Daimon :alien:")
|
11 |
st.title("PhD Candidate in Machine Translation / Translator / Mountain enthusiast")
|
12 |
st.write("I am passionate about finding new ways to effectively use and understand Machine Translation and effectively evaluating its quality.")
|
13 |
st.write("""
|
|
|
17 |
[Twitter](https://twitter.com/FrancescoDaimon)
|
18 |
""")
|
19 |
|
20 |
+
st.title('Upload your data')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
st.subheader('Input TSV/CSV')
|
23 |
uploaded_file = st.file_uploader("Choose a file")
|
24 |
+
with st.spinner("Loading..."):
|
25 |
+
if uploaded_file is not None:
|
26 |
+
if uploaded_file.name.endswith('.tsv'):
|
27 |
+
data = pd.read_csv(uploaded_file, sep="\t")
|
28 |
+
else:
|
29 |
+
data = pd.read_csv(uploaded_file)
|
30 |
+
|
31 |
+
st.subheader("DataFrame")
|
32 |
+
st.write(data)
|
33 |
+
st.write(data.describe())
|
34 |
+
|
35 |
else:
|
36 |
+
st.info("☝️ Upload a TSV/CSV file")
|
|
|
|
|
|
|
|
|
37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
st.subheader("MBART-50 Translator")
|
40 |
|
|
|
46 |
|
47 |
def get_translation(src_code, trg_code, src):
|
48 |
|
|
|
49 |
tokenizer.src_lang = src_code
|
50 |
encoded = tokenizer(src, return_tensors="pt")
|
51 |
generated_tokens = model.generate(
|
|
|
64 |
src_lang = st.selectbox(
|
65 |
'Source language',
|
66 |
('en_XX', 'fr_XX', 'de_DE', 'it_IT', 'es_XX'),
|
|
|
67 |
)
|
68 |
with right_c:
|
69 |
trg_lang = st.selectbox(
|