Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,27 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
|
4 |
+
# Cargar el modelo y el tokenizador
|
5 |
+
model_name = "meta-llama/Llama-3.2-1B-Instruct" # Asegúrate de que este sea el nombre correcto
|
6 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
8 |
+
|
9 |
+
# Leer el archivo de texto
|
10 |
+
with open("reparaciones.txt", "r") as file:
|
11 |
+
informacion_adicional = file.read()
|
12 |
+
|
13 |
+
def respond_to_query(user_input):
|
14 |
+
# Crear el prompt
|
15 |
+
prompt = f"{informacion_adicional} Responde la siguiente pregunta: {user_input}"
|
16 |
+
|
17 |
+
# Tokenizar el prompt
|
18 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
19 |
+
|
20 |
+
# Generar la respuesta
|
21 |
+
outputs = model.generate(**inputs)
|
22 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
23 |
+
|
24 |
+
return response
|
25 |
+
|
26 |
+
# Crear la interfaz de Gradio
|
27 |
+
gr.Interface(fn=respond_to_query, inputs="text", outputs="text").launch()
|