Daimon commited on
Commit
8b092c8
β€’
1 Parent(s): 49adbc5

Added main app and requirements

Browse files
Files changed (4) hide show
  1. .gitignore +2 -0
  2. README.md +1 -13
  3. app.py +414 -0
  4. requirements.txt +9 -0
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ .streamlit/
2
+ .venv/
README.md CHANGED
@@ -1,13 +1 @@
1
- ---
2
- title: Translation Demo
3
- emoji: 🏒
4
- colorFrom: green
5
- colorTo: purple
6
- sdk: streamlit
7
- sdk_version: 1.17.0
8
- app_file: app.py
9
- pinned: false
10
- license: afl-3.0
11
- ---
12
-
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
+ # personal-webpage
 
 
 
 
 
 
 
 
 
 
 
 
app.py ADDED
@@ -0,0 +1,414 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 streamlit_elements import elements, dashboard, mui, media
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 :wink:")
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("""
21
+ [Github](https://github.com/FrancescoFernicola)
22
+ [Unibo](https://www.unibo.it/sitoweb/francesco.fernicola2)
23
+ [LinkedIn](https://www.linkedin.com/in/francesco-fernicola-69a0771b7/?locale=en_US)
24
+ [Twitter](https://twitter.com/FrancescoDaimon)
25
+ """)
26
+
27
+ st.header('st.button')
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
+ if uploaded_file.name.endswith('.tsv'):
155
+ data = pd.read_csv(uploaded_file, sep="\t")
156
+ else:
157
+ data = pd.read_csv(uploaded_file)
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
+
342
+ source = "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."
343
+ target = ""
344
+ model = MBartForConditionalGeneration.from_pretrained("facebook/mbart-large-50-many-to-many-mmt")
345
+ tokenizer = MBart50TokenizerFast.from_pretrained("facebook/mbart-large-50-many-to-many-mmt")
346
+
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(
354
+ **encoded,
355
+ forced_bos_token_id=tokenizer.lang_code_to_id[trg_code]
356
+ )
357
+ trg = tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)
358
+
359
+ return trg
360
+
361
+ valid_languages = ['en_XX', 'fr_XX', 'de_DE', 'it_IT', 'es_XX']
362
+
363
+ with st.form("my_form"):
364
+ left_c, right_c = st.columns(2)
365
+ with left_c:
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(
373
+ 'Target language',
374
+ ('fr_XX', 'en_XX', 'de_DE', 'it_IT', 'es_XX')
375
+ )
376
+ source = st.text_area("Source", value=source, height=130, placeholder="Enter the source text...")
377
+
378
+
379
+ submitted = st.form_submit_button("Translate")
380
+ if submitted:
381
+ if len(source) > 0 and src_lang in valid_languages and trg_lang in valid_languages:
382
+ with st.spinner("Translating..."):
383
+ try:
384
+ target = get_translation(src_lang, trg_lang, source)[0]
385
+ st.subheader("Translation done!")
386
+ target = st.text_area("Target", value=target, height=130)
387
+ except:
388
+ st.subheader("Translation failed :sad:")
389
+
390
+ else:
391
+ st.write("Please enter the source text, source language and target language.")
392
+
393
+
394
+
395
+ # ---- CONTACT ----
396
+ with st.container():
397
+ st.write("---")
398
+ st.header("Get in Touch With Me!")
399
+ st.write("##")
400
+
401
+ contact_form = """
402
+ <form action="https://formsubmit.co/daimon.f@outlook.com" method="POST">
403
+ <input type="hidden" name="_captcha" value="false">
404
+ <input type="text" name="name" placeholder="Your name" required>
405
+ <input type="email" name="email" placeholder="Your email" required>
406
+ <textarea name="message" placeholder="Your message here" required></textarea>
407
+ <button type="submit">Send</button>
408
+ </form>
409
+ """
410
+ left_column, right_column = st.columns(2)
411
+ with left_column:
412
+ st.markdown(contact_form, unsafe_allow_html=True)
413
+ with right_column:
414
+ st.empty()
requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ pandas
2
+ streamlit
3
+ pathlib
4
+ openai
5
+ numpy
6
+ streamlit_pandas_profiling
7
+ streamlit-elements==0.1.*
8
+ transformers
9
+ torch