Spaces:
Running
Running
Add multilingual texts description funcionality
Browse files- app.py +41 -15
- multilingual_texts.csv +14 -0
app.py
CHANGED
@@ -3,10 +3,11 @@ import gradio as gr
|
|
3 |
from gradio.components import Slider
|
4 |
import torch
|
5 |
from transformers import pipeline
|
|
|
6 |
|
7 |
# Model, information and examples ----------------------------------------------
|
8 |
MODEL_NAMES = ["FLOR-1.3B-GL","Cerebras-1.3B-GL"]
|
9 |
-
|
10 |
# Galician LLMs
|
11 |
|
12 |
|
@@ -23,6 +24,24 @@ This space contains the Galician language models developed by [Proxecto Nós](ht
|
|
23 |
👀 **Learn more about Cerebras-1.3B-GL:** [HF official model card](https://huggingface.co/proxectonos/Cerebras-1.3B-GL)
|
24 |
"""
|
25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
short_prompts_examples = [
|
27 |
["A receita tradicional das filloas é"],
|
28 |
["O neno vivía preto de"]
|
@@ -41,6 +60,10 @@ generator_model_flor = pipeline("text-generation", model=model_id_flor)
|
|
41 |
model_id_cerebras = "proxectonos/Cerebras-1.3B-GL"
|
42 |
generator_model_cerebras = pipeline("text-generation", model=model_id_cerebras, token=os.environ['TOKEN_HF'])
|
43 |
|
|
|
|
|
|
|
|
|
44 |
# Generation functions ---------------------------------------------------------
|
45 |
def get_model(model_selection):
|
46 |
if model_selection == "FLOR-1.3B-GL":
|
@@ -75,6 +98,9 @@ def predict(prompt, model_select, max_length, repetition_penalty, temperature):
|
|
75 |
return generated_sequence
|
76 |
|
77 |
# Gradio app ---------------------------------------------------------
|
|
|
|
|
|
|
78 |
def clear():
|
79 |
return (
|
80 |
None,
|
@@ -109,49 +135,49 @@ def gradio_app():
|
|
109 |
with gr.Column(scale=0.1):
|
110 |
gr.HTML('<img src="https://huggingface.co/spaces/proxectonos/README/resolve/main/title-card.png" width="100%" style="border-radius: 0.75rem;">')
|
111 |
with gr.Column():
|
112 |
-
gr.Markdown(markdown_description)
|
113 |
with gr.Row(equal_height=True):
|
114 |
model_select = gr.Dropdown(
|
115 |
-
label="
|
116 |
choices=MODEL_NAMES,
|
117 |
value=MODEL_NAMES[0],
|
118 |
interactive=True
|
119 |
)
|
120 |
with gr.Row(equal_height=True):
|
121 |
with gr.Column():
|
122 |
-
text_gl = gr.Textbox(label="
|
123 |
lines=6, placeholder="e.g. O neno vai a escola con ")
|
124 |
with gr.Row(variant="panel"):
|
125 |
-
with gr.Accordion("
|
126 |
max_length = Slider(
|
127 |
minimum=1,
|
128 |
maximum=200,
|
129 |
step=1,
|
130 |
value=30,
|
131 |
-
label="
|
132 |
)
|
133 |
repetition_penalty = Slider(
|
134 |
minimum=0.1,
|
135 |
maximum=4,
|
136 |
step=0.1,
|
137 |
value=1.3,
|
138 |
-
label="
|
139 |
)
|
140 |
temperature = Slider(
|
141 |
minimum=0,
|
142 |
maximum=1,
|
143 |
value=0.5,
|
144 |
-
label="
|
145 |
)
|
146 |
-
generator_btn = gr.Button(value="
|
147 |
with gr.Column():
|
148 |
-
generated_gl = gr.Textbox(label="
|
149 |
lines=6,
|
150 |
-
placeholder="
|
151 |
interactive=False,
|
152 |
show_copy_button=True)
|
153 |
-
pass_btn = gr.Button(value="
|
154 |
-
clean_btn = gr.Button(value="
|
155 |
|
156 |
generator_btn.click(predict, inputs=[text_gl, model_select, max_length, repetition_penalty, temperature], outputs=generated_gl, api_name="generate-flor-gl")
|
157 |
clean_btn.click(fn=clear, inputs=[], outputs=[text_gl, generated_gl, max_length, repetition_penalty, temperature], queue=False, api_name=False)
|
@@ -160,7 +186,7 @@ def gradio_app():
|
|
160 |
with gr.Row():
|
161 |
with gr.Column(scale=0.5):
|
162 |
gr.Examples(
|
163 |
-
label = "
|
164 |
examples = short_prompts_examples,
|
165 |
inputs = [text_gl],
|
166 |
outputs = [max_length, repetition_penalty, temperature],
|
@@ -168,7 +194,7 @@ def gradio_app():
|
|
168 |
run_on_click = True
|
169 |
)
|
170 |
gr.Examples(
|
171 |
-
label = "
|
172 |
examples = few_shot_prompts_examples,
|
173 |
inputs = [text_gl],
|
174 |
outputs = [max_length, repetition_penalty, temperature],
|
|
|
3 |
from gradio.components import Slider
|
4 |
import torch
|
5 |
from transformers import pipeline
|
6 |
+
import pandas as pd
|
7 |
|
8 |
# Model, information and examples ----------------------------------------------
|
9 |
MODEL_NAMES = ["FLOR-1.3B-GL","Cerebras-1.3B-GL"]
|
10 |
+
markdown_description_en = """
|
11 |
# Galician LLMs
|
12 |
|
13 |
|
|
|
24 |
👀 **Learn more about Cerebras-1.3B-GL:** [HF official model card](https://huggingface.co/proxectonos/Cerebras-1.3B-GL)
|
25 |
"""
|
26 |
|
27 |
+
markdown_description_gl = """
|
28 |
+
# LLMs de galego
|
29 |
+
|
30 |
+
|
31 |
+
Este espazo grandes modelos da linguaxe feitos para o galego desenvolvidos polo [Proxecto Nós](https://nos.gal/en/proxecto-nos).
|
32 |
+
|
33 |
+
|
34 |
+
💐 **[FLOR-1.3B-GL](https://huggingface.co/proxectonos/FLOR-1.3B-GL)** é un modelo de parámetros 1.3B que é un preadestramento continuo de [FLOR-1.3B]( https://huggingface.co/projecte-aina/FLOR-1.3B), baseado a súa vez en [Bloom 1.7B](https://huggingface.co/bigscience/bloom-1b7).
|
35 |
+
|
36 |
+
👀 **Máis información sobre FLOR-1.3B-GL:** [tarxeta modelo oficial HF](https://huggingface.co/proxectonos/FLOR-1.3B-GL).
|
37 |
+
|
38 |
+
|
39 |
+
🧠 **[Cerebras-1.3B-GL](https://huggingface.co/proxectonos/Cerebras-1.3B-GL)** é un modelo de parámetros 1.3B baseado en [Cerebras-GPT 1.3B](https:/ /huggingface.co/cerebras/Cerebras-GPT-1.3B).
|
40 |
+
|
41 |
+
👀 **Máis información sobre Cerebras-1.3B-GL:** [tarxeta modelo oficial HF](https://huggingface.co/proxectonos/Cerebras-1.3B-GL)
|
42 |
+
"""
|
43 |
+
|
44 |
+
markdown_description ={"en": markdown_description_en,"gl": markdown_description_gl}
|
45 |
short_prompts_examples = [
|
46 |
["A receita tradicional das filloas é"],
|
47 |
["O neno vivía preto de"]
|
|
|
60 |
model_id_cerebras = "proxectonos/Cerebras-1.3B-GL"
|
61 |
generator_model_cerebras = pipeline("text-generation", model=model_id_cerebras, token=os.environ['TOKEN_HF'])
|
62 |
|
63 |
+
# Load language texts ---------------------------------------------------------
|
64 |
+
df_texts = pd.read_csv("multilingual_texts.csv")
|
65 |
+
lang = "gl"
|
66 |
+
|
67 |
# Generation functions ---------------------------------------------------------
|
68 |
def get_model(model_selection):
|
69 |
if model_selection == "FLOR-1.3B-GL":
|
|
|
98 |
return generated_sequence
|
99 |
|
100 |
# Gradio app ---------------------------------------------------------
|
101 |
+
def get_text_lang(variable):
|
102 |
+
return df_texts.loc[df_texts['variable'] == variable, lang].values[0]
|
103 |
+
|
104 |
def clear():
|
105 |
return (
|
106 |
None,
|
|
|
135 |
with gr.Column(scale=0.1):
|
136 |
gr.HTML('<img src="https://huggingface.co/spaces/proxectonos/README/resolve/main/title-card.png" width="100%" style="border-radius: 0.75rem;">')
|
137 |
with gr.Column():
|
138 |
+
gr.Markdown(markdown_description[lang])
|
139 |
with gr.Row(equal_height=True):
|
140 |
model_select = gr.Dropdown(
|
141 |
+
label=get_text_lang["model_select"],
|
142 |
choices=MODEL_NAMES,
|
143 |
value=MODEL_NAMES[0],
|
144 |
interactive=True
|
145 |
)
|
146 |
with gr.Row(equal_height=True):
|
147 |
with gr.Column():
|
148 |
+
text_gl = gr.Textbox(label=get_text_lang["text_gl"],
|
149 |
lines=6, placeholder="e.g. O neno vai a escola con ")
|
150 |
with gr.Row(variant="panel"):
|
151 |
+
with gr.Accordion(get_text_lang["accordion_parameters"], open=False):
|
152 |
max_length = Slider(
|
153 |
minimum=1,
|
154 |
maximum=200,
|
155 |
step=1,
|
156 |
value=30,
|
157 |
+
label=get_text_lang["max_length"]
|
158 |
)
|
159 |
repetition_penalty = Slider(
|
160 |
minimum=0.1,
|
161 |
maximum=4,
|
162 |
step=0.1,
|
163 |
value=1.3,
|
164 |
+
label=get_text_lang["repetition_penalty"]
|
165 |
)
|
166 |
temperature = Slider(
|
167 |
minimum=0,
|
168 |
maximum=1,
|
169 |
value=0.5,
|
170 |
+
label=get_text_lang["temperature"]
|
171 |
)
|
172 |
+
generator_btn = gr.Button(value=get_text_lang["generator_btn"],variant='primary')
|
173 |
with gr.Column():
|
174 |
+
generated_gl = gr.Textbox(label=get_text_lang["generated_gl_label"],
|
175 |
lines=6,
|
176 |
+
placeholder=get_text_lang["generated_gl_placeholder"],
|
177 |
interactive=False,
|
178 |
show_copy_button=True)
|
179 |
+
pass_btn = gr.Button(value=get_text_lang["pass_btn"])
|
180 |
+
clean_btn = gr.Button(value=get_text_lang["clean_btn"])
|
181 |
|
182 |
generator_btn.click(predict, inputs=[text_gl, model_select, max_length, repetition_penalty, temperature], outputs=generated_gl, api_name="generate-flor-gl")
|
183 |
clean_btn.click(fn=clear, inputs=[], outputs=[text_gl, generated_gl, max_length, repetition_penalty, temperature], queue=False, api_name=False)
|
|
|
186 |
with gr.Row():
|
187 |
with gr.Column(scale=0.5):
|
188 |
gr.Examples(
|
189 |
+
label = get_text_lang["examples_short_prompts"],
|
190 |
examples = short_prompts_examples,
|
191 |
inputs = [text_gl],
|
192 |
outputs = [max_length, repetition_penalty, temperature],
|
|
|
194 |
run_on_click = True
|
195 |
)
|
196 |
gr.Examples(
|
197 |
+
label = get_text_lang["examples_few_shot"],
|
198 |
examples = few_shot_prompts_examples,
|
199 |
inputs = [text_gl],
|
200 |
outputs = [max_length, repetition_penalty, temperature],
|
multilingual_texts.csv
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
variable,en,gl
|
2 |
+
model_select,Model selection,Seleccione un modelo
|
3 |
+
text_gl,Input,Entrada
|
4 |
+
accordion_parameters,Model parameters,Parámetros do modelo
|
5 |
+
max_length,Max tokens,Max tokens
|
6 |
+
repetition_penalty,Repetition penalty,Penalización por repetición
|
7 |
+
temperature,Temperature,Temperatura
|
8 |
+
generator_btn,Generate,Xerar
|
9 |
+
generated_gl_label,Output,Saída
|
10 |
+
generated_gl_placeholder,Generated text will appear here...,O texto xerado aparecerá aquí...
|
11 |
+
pass_btn,Pass text to input,Pasar texto á entrada
|
12 |
+
clean_btn,Clean,Limpar
|
13 |
+
examples_short_prompts,Short Prompts,Prompts curtos
|
14 |
+
examples_few_shot,Few-Shot Prompts,Prompts con poucos exemplos
|