Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -68,3 +68,22 @@ with gr.Blocks() as demo:
|
|
| 68 |
|
| 69 |
if __name__ == "__main__":
|
| 70 |
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
if __name__ == "__main__":
|
| 70 |
demo.launch()
|
| 71 |
+
def chat(prompt, max_length=200):
|
| 72 |
+
# Convertimos el prompt en tensores para el modelo
|
| 73 |
+
inputs = tokenizer.encode(prompt, return_tensors="pt").to(device)
|
| 74 |
+
|
| 75 |
+
# Generamos la respuesta del modelo
|
| 76 |
+
outputs = model.generate(
|
| 77 |
+
inputs,
|
| 78 |
+
max_length=max_length,
|
| 79 |
+
pad_token_id=tokenizer.eos_token_id,
|
| 80 |
+
do_sample=True,
|
| 81 |
+
top_p=0.9,
|
| 82 |
+
temperature=0.7
|
| 83 |
+
)
|
| 84 |
+
|
| 85 |
+
# ⚡ Aquí ponemos el código para quitar la columna de tokens
|
| 86 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 87 |
+
|
| 88 |
+
# Devolvemos solo la respuesta en texto plano
|
| 89 |
+
return response[len(prompt):].strip()
|