mariagrandury commited on
Commit
3954682
1 Parent(s): aca543d

Initial commit

Browse files
Files changed (4) hide show
  1. .gitignore +1 -0
  2. README.md +3 -3
  3. app.py +113 -0
  4. requirements.txt +4 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ venv/
README.md CHANGED
@@ -1,7 +1,7 @@
1
  ---
2
- title: Bertin
3
- emoji: 📈
4
- colorFrom: green
5
  colorTo: red
6
  sdk: streamlit
7
  app_file: app.py
 
1
  ---
2
+ title: BERTIN
3
+ emoji: 🔥
4
+ colorFrom: yellow
5
  colorTo: red
6
  sdk: streamlit
7
  app_file: app.py
app.py ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import random
2
+ from mtranslate import translate
3
+ import streamlit as st
4
+ from transformers import AutoTokenizer, AutoModelForMaskedLM, pipeline
5
+
6
+
7
+ LOGO = "https://raw.githubusercontent.com/nlp-en-es/assets/main/logo.png"
8
+
9
+ MODELS = {
10
+ "RoBERTa Base": {
11
+ "url": "https://api-inference.huggingface.co/models/bertin-project/bertin-roberta-base-spanish"
12
+ },
13
+ "RoBERTa Base Gaussian": {
14
+ "url": "https://api-inference.huggingface.co/models/bertin-project/bertin-base-gaussian"
15
+ },
16
+ "RoBERTa Base Random": {
17
+ "url": "https://api-inference.huggingface.co/models/bertin-project/bertin-base-random"
18
+ },
19
+ "RoBERTa Base Stepwise": {
20
+ "url": "https://api-inference.huggingface.co/models/bertin-project/bertin-base-stepwise"
21
+ },
22
+ "RoBERTa Base Gaussian Experiment": {
23
+ "url": "https://api-inference.huggingface.co/models/bertin-project/bertin-base-gaussian-exp-512seqlen"
24
+ },
25
+ "RoBERTa Base Random Experiment": {
26
+ "url": "https://api-inference.huggingface.co/models/bertin-project/bertin-base-random-exp-512seqlen"
27
+ }
28
+ }
29
+
30
+ PROMPT_LIST = [
31
+ "Fui a la librería a comprar un <mask>.",
32
+ "¡Qué buen <mask> hace hoy!",
33
+ "Hoy empiezan las vacaciones, vamos a la <mask>.",
34
+ "Mi color favorito es el <mask>.",
35
+ "Voy a <mask>, estoy muy cansada.",
36
+ "Mañana vienen mis amigos de <mask>.",
37
+ "¿Te apetece venir a <mask> conmigo?",
38
+ "En verano hace mucho <mask>.",
39
+ "En el bosque había <mask>."
40
+ ]
41
+
42
+
43
+ @st.cache(show_spinner=False, persist=True)
44
+ def load_model(masked_text, model_name):
45
+ model = AutoModelForMaskedLM.from_pretrained(model_name)
46
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
47
+ nlp = pipeline("fill-mask", model=model, tokenizer=tokenizer)
48
+ result = nlp(masked_text)
49
+ return result
50
+
51
+
52
+ # Page
53
+ st.set_page_config(page_title="BERTIN Demo", page_icon=LOGO)
54
+ st.title("BERTIN")
55
+
56
+ #Sidebar
57
+ st.sidebar.image(LOGO)
58
+
59
+ # Body
60
+ st.markdown(
61
+ """
62
+ BERTIN is a series of BERT-based models for Spanish.
63
+ The models are trained with Flax and using TPUs sponsored by Google since this is part of the
64
+ [Flax/Jax Community Week](https://discuss.huggingface.co/t/open-to-the-community-community-week-using-jax-flax-for-nlp-cv/7104)
65
+ organised by HuggingFace.
66
+ """
67
+ )
68
+
69
+ model_name = st.selectbox("Model",(MODELS.keys()))
70
+
71
+ prompt = st.selectbox("Prompt", ["Random", "Custom"])
72
+ if prompt == "Custom":
73
+ prompt_box = "Enter your masked text here..."
74
+ else:
75
+ prompt_box = random.choice(PROMPT_LIST)
76
+ text = st.text_area("Enter text", prompt_box)
77
+
78
+ if st.button("Fill the mask"):
79
+ with st.spinner(text="Getting results..."):
80
+ st.subheader("Result")
81
+ result = load_model(text, model_name)
82
+ if "error" in result:
83
+ if type(result["error"]) is str:
84
+ st.write(f'{result["error"]}.', end=" ")
85
+ if "estimated_time" in result:
86
+ st.write(
87
+ f'Please try again in about {result["estimated_time"]:.0f} seconds.'
88
+ )
89
+ else:
90
+ if type(result["error"]) is list:
91
+ for error in result["error"]:
92
+ st.write(f"{error}")
93
+ else:
94
+ result_sequence, result_token = result[0]["sequence"], result[0]["token_str"]
95
+ st.write(result_sequence)
96
+ st.text("English translation")
97
+ st.write(translate(result_sequence, "en", "es"))
98
+
99
+ st.markdown(
100
+ """
101
+ ### Team members
102
+ - Javier de la Rosa ([versae](https://huggingface.co/versae))
103
+ - Eduardo González ([edugp](https://huggingface.co/edugp))
104
+ - Paulo Villegas ([paulo](https://huggingface.co/paulo))
105
+ - Pablo González de Prado ([Pablogps](https://huggingface.co/Pablogps))
106
+ - Manu Romero ([mrm8488](https://huggingface.co/mrm8488))
107
+ - María Grandury ([mariagrandury](https://huggingface.co/mariagrandury))
108
+
109
+ ### More information
110
+ You can find more information about these models
111
+ [here](https://huggingface.co/bertin-project/bertin-roberta-base-spanish).
112
+ """
113
+ )
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ streamlit
2
+ mtranslate
3
+ transformers
4
+ torch