Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -4,24 +4,13 @@ import gradio as gr
|
|
4 |
import os
|
5 |
import torch
|
6 |
|
7 |
-
os.system('pip install dashscope')
|
8 |
-
from http import HTTPStatus
|
9 |
-
import dashscope
|
10 |
-
from dashscope import Generation
|
11 |
-
from dashscope.api_entities.dashscope_response import Role
|
12 |
-
from typing import List, Optional, Tuple, Dict
|
13 |
-
from urllib.error import HTTPError
|
14 |
-
default_system = 'You are a helpful assistant.'
|
15 |
-
|
16 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
17 |
-
|
18 |
# Aseg煤rate de que tu token de Hugging Face est谩 cargado como una variable de entorno
|
19 |
hf_token = os.environ.get("token")
|
20 |
if hf_token is not None:
|
21 |
from huggingface_hub import HfFolder
|
22 |
HfFolder.save_token(hf_token)
|
23 |
-
else:
|
24 |
-
print("No se encontr贸 el token de Hugging Face. Aseg煤rate de que la variable de entorno HF_TOKEN est茅 configurada.")
|
25 |
|
26 |
# Configuraci贸n inicial
|
27 |
tokenizer = AutoTokenizer.from_pretrained("somosnlp/chaterapia_model")
|
@@ -64,7 +53,6 @@ def generate_response(user_input):
|
|
64 |
|
65 |
# Agregar la respuesta del bot al historial
|
66 |
chat_history.append({"content": generated_text, "role": "assistant"})
|
67 |
-
print(chat_history)
|
68 |
return generated_text
|
69 |
|
70 |
def respond(message):
|
@@ -81,10 +69,6 @@ def clear_chat_and_history():
|
|
81 |
global chatbot_text
|
82 |
chat_history.clear()# Vaciar el historial de chat
|
83 |
chatbot_text.clear()
|
84 |
-
# Devolver valores que efectivamente "limpien" los componentes de Gradio visualmente
|
85 |
-
# En este caso, estamos limpiando el Textbox y el Chatbot, pero como el Chatbot
|
86 |
-
# no puede ser "limpiado" directamente de esta manera, simplemente retornamos una lista vac铆a
|
87 |
-
# que ser谩 interpretada como ning煤n mensaje nuevo para mostrar.
|
88 |
return "", []
|
89 |
|
90 |
with gr.Blocks() as demo:
|
@@ -97,8 +81,6 @@ with gr.Blocks() as demo:
|
|
97 |
|
98 |
# Acci贸n al presionar el bot贸n Enviar
|
99 |
send_btn.click(fn=respond, inputs=msg, outputs=chatbot)
|
100 |
-
# Configurar el bot贸n de limpieza para ejecutar clear_chat_and_history cuando se presione
|
101 |
-
# y actualizar tanto el msg como el chatbot con los valores retornados por la funci贸n
|
102 |
clear_btn.click(fn=clear_chat_and_history, inputs=None, outputs=[msg, chatbot])
|
103 |
|
104 |
demo.launch()
|
|
|
4 |
import os
|
5 |
import torch
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
8 |
+
|
9 |
# Aseg煤rate de que tu token de Hugging Face est谩 cargado como una variable de entorno
|
10 |
hf_token = os.environ.get("token")
|
11 |
if hf_token is not None:
|
12 |
from huggingface_hub import HfFolder
|
13 |
HfFolder.save_token(hf_token)
|
|
|
|
|
14 |
|
15 |
# Configuraci贸n inicial
|
16 |
tokenizer = AutoTokenizer.from_pretrained("somosnlp/chaterapia_model")
|
|
|
53 |
|
54 |
# Agregar la respuesta del bot al historial
|
55 |
chat_history.append({"content": generated_text, "role": "assistant"})
|
|
|
56 |
return generated_text
|
57 |
|
58 |
def respond(message):
|
|
|
69 |
global chatbot_text
|
70 |
chat_history.clear()# Vaciar el historial de chat
|
71 |
chatbot_text.clear()
|
|
|
|
|
|
|
|
|
72 |
return "", []
|
73 |
|
74 |
with gr.Blocks() as demo:
|
|
|
81 |
|
82 |
# Acci贸n al presionar el bot贸n Enviar
|
83 |
send_btn.click(fn=respond, inputs=msg, outputs=chatbot)
|
|
|
|
|
84 |
clear_btn.click(fn=clear_chat_and_history, inputs=None, outputs=[msg, chatbot])
|
85 |
|
86 |
demo.launch()
|