Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,23 +18,26 @@ CONTEXTO Y BASE DE CONOCIMIENTO DE LA EMPRESA:
|
|
| 18 |
"""
|
| 19 |
|
| 20 |
# Modelo para seguir instrucciones
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
prompt = f"{final_system_prompt}\n\n{context}"
|
| 28 |
|
| 29 |
response = ""
|
| 30 |
-
for
|
| 31 |
-
prompt,
|
| 32 |
max_new_tokens=max_tokens,
|
| 33 |
temperature=temperature,
|
| 34 |
top_p=top_p,
|
| 35 |
stream=True
|
| 36 |
):
|
| 37 |
-
response +=
|
| 38 |
yield response
|
| 39 |
|
| 40 |
# 3. Interfaz gr谩fica
|
|
@@ -43,8 +46,8 @@ chatbot = gr.ChatInterface(
|
|
| 43 |
title=bot_name,
|
| 44 |
description=bot_description,
|
| 45 |
additional_inputs=[
|
| 46 |
-
gr.Slider(
|
| 47 |
-
gr.Slider(0.1,
|
| 48 |
gr.Slider(0.1, 1.0, 0.95, step=0.05, label="Top-p"),
|
| 49 |
],
|
| 50 |
examples=[
|
|
@@ -55,7 +58,8 @@ chatbot = gr.ChatInterface(
|
|
| 55 |
)
|
| 56 |
|
| 57 |
with gr.Blocks() as demo:
|
| 58 |
-
gr.
|
|
|
|
| 59 |
chatbot.render()
|
| 60 |
|
| 61 |
if __name__ == "__main__":
|
|
|
|
| 18 |
"""
|
| 19 |
|
| 20 |
# Modelo para seguir instrucciones
|
| 21 |
+
def respond(message, history, max_tokens, temperature, top_p, hf_token: gr.OAuthToken):
|
| 22 |
+
if hf_token is None:
|
| 23 |
+
yield "鈿狅笍 Por favor inicia sesi贸n con tu cuenta de Hugging Face."
|
| 24 |
+
return
|
| 25 |
+
|
| 26 |
+
client = InferenceClient(model="microsoft/DialoGPT-medium", token=hf_token.token)
|
| 27 |
|
| 28 |
+
messages = [{"role": "system", "content": final_system_prompt}]
|
| 29 |
+
messages.extend(history)
|
| 30 |
+
messages.append({"role": "user", "content": message})
|
|
|
|
|
|
|
| 31 |
|
| 32 |
response = ""
|
| 33 |
+
for msg in client.text_generation(
|
| 34 |
+
prompt=client.conversation_prompt(messages),
|
| 35 |
max_new_tokens=max_tokens,
|
| 36 |
temperature=temperature,
|
| 37 |
top_p=top_p,
|
| 38 |
stream=True
|
| 39 |
):
|
| 40 |
+
response += msg
|
| 41 |
yield response
|
| 42 |
|
| 43 |
# 3. Interfaz gr谩fica
|
|
|
|
| 46 |
title=bot_name,
|
| 47 |
description=bot_description,
|
| 48 |
additional_inputs=[
|
| 49 |
+
gr.Slider(1, 2048, 1024, step=1, label="Max new tokens"),
|
| 50 |
+
gr.Slider(0.1, 4.0, 0.7, step=0.1, label="Temperature"),
|
| 51 |
gr.Slider(0.1, 1.0, 0.95, step=0.05, label="Top-p"),
|
| 52 |
],
|
| 53 |
examples=[
|
|
|
|
| 58 |
)
|
| 59 |
|
| 60 |
with gr.Blocks() as demo:
|
| 61 |
+
with gr.Sidebar():
|
| 62 |
+
gr.LoginButton()
|
| 63 |
chatbot.render()
|
| 64 |
|
| 65 |
if __name__ == "__main__":
|