Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -66,9 +66,9 @@ stopping_criteria = ListOfTokensStoppingCriteria(tokenizer, stop_tokens)
|
|
66 |
# Añade tu criterio de parada a una StoppingCriteriaList
|
67 |
stopping_criteria_list = StoppingCriteriaList([stopping_criteria])
|
68 |
|
69 |
-
def generate_text(prompt, max_length=2100):
|
70 |
prompt=prompt.replace("\n", "").replace("¿","").replace("?","")
|
71 |
-
input_text = f'''<bos><start_of_turn>system
|
72 |
inputs = tokenizer.encode(input_text, return_tensors="pt", add_special_tokens=False).to("cuda:0")
|
73 |
max_new_tokens=max_length
|
74 |
generation_config = GenerationConfig(
|
@@ -82,15 +82,15 @@ def generate_text(prompt, max_length=2100):
|
|
82 |
outputs = model.generate(generation_config=generation_config, input_ids=inputs, stopping_criteria=stopping_criteria_list,)
|
83 |
return tokenizer.decode(outputs[0], skip_special_tokens=False) #True
|
84 |
|
85 |
-
def mostrar_respuesta(pregunta):
|
86 |
try:
|
87 |
-
res= generate_text(pregunta, max_length=500)
|
88 |
return str(res)
|
89 |
except Exception as e:
|
90 |
return str(e)
|
91 |
|
92 |
# Ejemplos de preguntas
|
93 |
-
|
94 |
["¿Dime la receta de la tortilla de patatatas?"],
|
95 |
["¿Dime la receta del ceviche?"],
|
96 |
["¿Como se cocinan unos autenticos frijoles?"],
|
@@ -99,10 +99,11 @@ ejemplos = [
|
|
99 |
iface = gr.Interface(
|
100 |
fn=mostrar_respuesta,
|
101 |
inputs=gr.Textbox(label="Pregunta"),
|
|
|
102 |
outputs=[gr.Textbox(label="Respuesta", lines=2),],
|
103 |
title="Recetas de la Abuel@",
|
104 |
description="Introduce tu pregunta sobre recetas de cocina.",
|
105 |
-
|
106 |
)
|
107 |
|
108 |
iface.queue(max_size=14).launch() # share=True,debug=True
|
|
|
66 |
# Añade tu criterio de parada a una StoppingCriteriaList
|
67 |
stopping_criteria_list = StoppingCriteriaList([stopping_criteria])
|
68 |
|
69 |
+
def generate_text(prompt, context, max_length=2100):
|
70 |
prompt=prompt.replace("\n", "").replace("¿","").replace("?","")
|
71 |
+
input_text = f'''<bos><start_of_turn>system ¿{context}?<end_of_turn><start_of_turn>user ¿{prompt}?<end_of_turn><start_of_turn>model'''
|
72 |
inputs = tokenizer.encode(input_text, return_tensors="pt", add_special_tokens=False).to("cuda:0")
|
73 |
max_new_tokens=max_length
|
74 |
generation_config = GenerationConfig(
|
|
|
82 |
outputs = model.generate(generation_config=generation_config, input_ids=inputs, stopping_criteria=stopping_criteria_list,)
|
83 |
return tokenizer.decode(outputs[0], skip_special_tokens=False) #True
|
84 |
|
85 |
+
def mostrar_respuesta(pregunta, contexto):
|
86 |
try:
|
87 |
+
res= generate_text(pregunta, contexto, max_length=500)
|
88 |
return str(res)
|
89 |
except Exception as e:
|
90 |
return str(e)
|
91 |
|
92 |
# Ejemplos de preguntas
|
93 |
+
mis_ejemplos = [
|
94 |
["¿Dime la receta de la tortilla de patatatas?"],
|
95 |
["¿Dime la receta del ceviche?"],
|
96 |
["¿Como se cocinan unos autenticos frijoles?"],
|
|
|
99 |
iface = gr.Interface(
|
100 |
fn=mostrar_respuesta,
|
101 |
inputs=gr.Textbox(label="Pregunta"),
|
102 |
+
context=gr.Textbox(label="Contexto", value="You are a helpful AI assistant. Eres un experto cocinero hispanoamericano."),
|
103 |
outputs=[gr.Textbox(label="Respuesta", lines=2),],
|
104 |
title="Recetas de la Abuel@",
|
105 |
description="Introduce tu pregunta sobre recetas de cocina.",
|
106 |
+
ejemplos=mis_ejemplos,
|
107 |
)
|
108 |
|
109 |
iface.queue(max_size=14).launch() # share=True,debug=True
|