Spaces:
Sleeping
Sleeping
Mejora visualización
Browse files
app.py
CHANGED
@@ -128,6 +128,32 @@ class NgramModel:
|
|
128 |
def create_interface():
|
129 |
model = NgramModel()
|
130 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
def train_model(text_input, file_input):
|
132 |
"""Entrena el modelo con texto o archivo."""
|
133 |
if file_input is not None:
|
@@ -161,6 +187,17 @@ def create_interface():
|
|
161 |
max-width: 900px;
|
162 |
margin: auto;
|
163 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
164 |
""") as interface:
|
165 |
with gr.Column(elem_classes="container"):
|
166 |
# Logo centrado
|
@@ -172,12 +209,12 @@ def create_interface():
|
|
172 |
</div>
|
173 |
""")
|
174 |
|
175 |
-
gr.
|
176 |
-
|
177 |
-
|
|
|
178 |
|
179 |
with gr.Tab("Entrenamiento"):
|
180 |
-
gr.Markdown("### Entrena el modelo con texto")
|
181 |
text_input = gr.Textbox(
|
182 |
label="Texto de entrenamiento",
|
183 |
lines=5,
|
@@ -203,7 +240,6 @@ def create_interface():
|
|
203 |
)
|
204 |
|
205 |
with gr.Tab("Predicción"):
|
206 |
-
gr.Markdown("### Predice la siguiente palabra")
|
207 |
input_text = gr.Textbox(
|
208 |
label="Introduce texto",
|
209 |
placeholder="Escribe aquí el texto para predecir la siguiente palabra..."
|
|
|
128 |
def create_interface():
|
129 |
model = NgramModel()
|
130 |
|
131 |
+
def train_model(text_input, file_input):
|
132 |
+
"""Entrena el modelo con texto o archivo."""
|
133 |
+
if file_input is not None:
|
134 |
+
training_text = file_input
|
135 |
+
elif text_input.strip():
|
136 |
+
training_text = text_input
|
137 |
+
else:
|
138 |
+
return "Por favor, proporcione texto de entrenamiento."
|
139 |
+
|
140 |
+
model.train(training_text)
|
141 |
+
return "Modelo entrenado exitosamente."
|
142 |
+
|
143 |
+
def predict(input_text):
|
144 |
+
"""Realiza la predicción y actualiza el texto de entrada."""
|
145 |
+
if not model.is_trained:
|
146 |
+
return input_text, "", "El modelo no ha sido entrenado aún."
|
147 |
+
|
148 |
+
next_word, explanation = model.predict_next_word(input_text)
|
149 |
+
new_text = input_text.strip() + " " + next_word if input_text.strip() else next_word
|
150 |
+
|
151 |
+
return new_text, next_word, explanation
|
152 |
+
|
153 |
+
# Crear interfaz con Gradio
|
154 |
+
def create_interface():
|
155 |
+
model = NgramModel()
|
156 |
+
|
157 |
def train_model(text_input, file_input):
|
158 |
"""Entrena el modelo con texto o archivo."""
|
159 |
if file_input is not None:
|
|
|
187 |
max-width: 900px;
|
188 |
margin: auto;
|
189 |
}
|
190 |
+
.centered-title {
|
191 |
+
text-align: center !important;
|
192 |
+
}
|
193 |
+
.centered-title h1 {
|
194 |
+
text-align: center !important;
|
195 |
+
margin-bottom: 1.5rem;
|
196 |
+
}
|
197 |
+
.centered-title h2 {
|
198 |
+
text-align: center !important;
|
199 |
+
margin-bottom: 1rem;
|
200 |
+
}
|
201 |
""") as interface:
|
202 |
with gr.Column(elem_classes="container"):
|
203 |
# Logo centrado
|
|
|
209 |
</div>
|
210 |
""")
|
211 |
|
212 |
+
with gr.Column(elem_classes="centered-title"):
|
213 |
+
gr.Markdown("# ¡Construye tu propio miniGPT!")
|
214 |
+
gr.Markdown("### En la pestaña Entrenamiento puedes copiar o subir un texto base y entrenar tu miniGPT")
|
215 |
+
gr.Markdown("### En la pestaña Predicción puedes comenzar a escribir un texto y usar tu miniGPT para continuarlo automáticamente")
|
216 |
|
217 |
with gr.Tab("Entrenamiento"):
|
|
|
218 |
text_input = gr.Textbox(
|
219 |
label="Texto de entrenamiento",
|
220 |
lines=5,
|
|
|
240 |
)
|
241 |
|
242 |
with gr.Tab("Predicción"):
|
|
|
243 |
input_text = gr.Textbox(
|
244 |
label="Introduce texto",
|
245 |
placeholder="Escribe aquí el texto para predecir la siguiente palabra..."
|