Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,12 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
|
|
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
def responder_chat(mensaje, system_message, max_tokens, temperature, top_p):
|
| 8 |
try:
|
|
@@ -16,7 +20,6 @@ def responder_chat(mensaje, system_message, max_tokens, temperature, top_p):
|
|
| 16 |
)
|
| 17 |
return response.generated_text
|
| 18 |
except Exception as e:
|
| 19 |
-
# Aquí capturamos cualquier error y devolvemos un mensaje amigable
|
| 20 |
return f"Lo siento, hubo un error procesando tu mensaje: {str(e)}"
|
| 21 |
|
| 22 |
with gr.Blocks() as demo:
|
|
@@ -27,7 +30,9 @@ with gr.Blocks() as demo:
|
|
| 27 |
top_p = gr.Slider(minimum=0.1, maximum=1.0, value=0.9, step=0.05, label="Top-p")
|
| 28 |
chat_output = gr.Textbox(label="Respuesta del asistente")
|
| 29 |
|
| 30 |
-
chat_input.submit(
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
demo.launch()
|
| 33 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
+
import os
|
| 4 |
|
| 5 |
+
# Lee el token secreto desde las variables de entorno
|
| 6 |
+
hf_token = os.getenv("HF_API_TOKEN")
|
| 7 |
+
|
| 8 |
+
# Inicializa el cliente con el modelo y el token
|
| 9 |
+
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta", token=hf_token)
|
| 10 |
|
| 11 |
def responder_chat(mensaje, system_message, max_tokens, temperature, top_p):
|
| 12 |
try:
|
|
|
|
| 20 |
)
|
| 21 |
return response.generated_text
|
| 22 |
except Exception as e:
|
|
|
|
| 23 |
return f"Lo siento, hubo un error procesando tu mensaje: {str(e)}"
|
| 24 |
|
| 25 |
with gr.Blocks() as demo:
|
|
|
|
| 30 |
top_p = gr.Slider(minimum=0.1, maximum=1.0, value=0.9, step=0.05, label="Top-p")
|
| 31 |
chat_output = gr.Textbox(label="Respuesta del asistente")
|
| 32 |
|
| 33 |
+
chat_input.submit(
|
| 34 |
+
responder_chat,
|
| 35 |
+
inputs=[chat_input, system_message, max_tokens, temperature, top_p],
|
| 36 |
+
outputs=chat_output_
|
| 37 |
|
|
|
|
| 38 |
|