Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,40 +1,52 @@
|
|
1 |
|
2 |
import gradio as gr
|
3 |
-
import
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
problem,
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
|
2 |
import gradio as gr
|
3 |
+
from inference import load_model, generate
|
4 |
+
# Imaginemos que 'generate' es una función adaptada en 'inference.py' que ya maneja la generación de problemas matemáticos.
|
5 |
+
|
6 |
+
# Cargar modelo
|
7 |
+
model_name = "deepseek-ai/deepseek-vl-7b-chat" # Ejemplo de nombre de modelo
|
8 |
+
tokenizer, model, _ = load_model(model_name)
|
9 |
+
|
10 |
+
def math_problem_generator(theme):
|
11 |
+
"""
|
12 |
+
Simula la generación de un problema matemático basado en el tema seleccionado.
|
13 |
+
Devuelve un problema y cuatro posibles soluciones, donde solo una es correcta.
|
14 |
+
"""
|
15 |
+
# Este es un ejemplo simplificado. Aquí deberías generar el problema y las soluciones basándote en el tema.
|
16 |
+
if theme == 'Álgebra':
|
17 |
+
problem = "¿Cuál es el resultado de x en la ecuación 2x + 3 = 7?"
|
18 |
+
options = ["x = 1", "x = 2", "x = 3", "x = 4"]
|
19 |
+
correct_answer = "x = 2"
|
20 |
+
elif theme == 'Geometría':
|
21 |
+
problem = "¿Cuál es el área de un círculo con radio de 4 unidades?"
|
22 |
+
options = ["16π unidades cuadradas", "8π unidades cuadradas", "4π unidades cuadradas", "2π unidades cuadradas"]
|
23 |
+
correct_answer = "16π unidades cuadradas"
|
24 |
+
# Agrega más temas y problemas aquí según sea necesario.
|
25 |
+
|
26 |
+
return problem, options, correct_answer
|
27 |
+
|
28 |
+
def solve_math_problem(theme):
|
29 |
+
problem, options, correct_answer = math_problem_generator(theme)
|
30 |
+
return problem, options, correct_answer
|
31 |
+
|
32 |
+
themes = ["Álgebra", "Geometría"] # Agrega más temas según sea necesario
|
33 |
+
theme_dropdown = gr.Dropdown(choices=themes, label="Selecciona un tema matemático")
|
34 |
+
|
35 |
+
problem_text = gr.Textbox(label="Problema")
|
36 |
+
options_radio = gr.Radio(label="Opciones")
|
37 |
+
correct_answer_text = gr.Textbox(label="Respuesta Correcta", visible=False)
|
38 |
+
|
39 |
+
def update_response(theme):
|
40 |
+
problem, options, correct_answer = solve_math_problem(theme)
|
41 |
+
problem_text.update(value=problem)
|
42 |
+
options_radio.update(choices=options, value=None)
|
43 |
+
correct_answer_text.update(value=correct_answer, visible=False)
|
44 |
+
return problem, options
|
45 |
+
|
46 |
+
theme_dropdown.change(update_response, inputs=[theme_dropdown], outputs=[problem_text, options_radio])
|
47 |
+
|
48 |
+
def check_answer(user_choice, correct_answer):
|
49 |
+
if user_choice == correct_answer:
|
50 |
+
return "¡Correcto!"
|
51 |
+
else:
|
52 |
+
correct_answer_text.update(visible=True)
|