Update app.py
Browse files
app.py
CHANGED
|
@@ -4,40 +4,28 @@ from huggingface_hub import InferenceClient
|
|
| 4 |
"""
|
| 5 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
| 6 |
"""
|
| 7 |
-
client = InferenceClient("
|
| 8 |
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
system_message
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
):
|
| 18 |
-
messages = [{"role": "system", "content": system_message}]
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
messages.append({"role": "assistant", "content": val[1]})
|
| 25 |
-
|
| 26 |
-
messages.append({"role": "user", "content": message})
|
| 27 |
-
|
| 28 |
-
response = ""
|
| 29 |
-
|
| 30 |
-
for message in client.chat_completion(
|
| 31 |
-
messages,
|
| 32 |
-
max_tokens=max_tokens,
|
| 33 |
-
stream=True,
|
| 34 |
temperature=temperature,
|
| 35 |
top_p=top_p,
|
| 36 |
-
)
|
| 37 |
-
token = message.choices[0].delta.content
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
|
|
|
| 41 |
|
| 42 |
|
| 43 |
|
|
@@ -87,16 +75,15 @@ with gr.Blocks() as demo:
|
|
| 87 |
|
| 88 |
with gr.Tab("Chatbot LeIA GO"):
|
| 89 |
gr.ChatInterface(
|
| 90 |
-
respond,
|
| 91 |
additional_inputs=[
|
| 92 |
-
gr.Textbox(value="
|
| 93 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 94 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 95 |
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
|
| 96 |
],
|
| 97 |
)
|
| 98 |
|
|
|
|
| 99 |
if __name__ == "__main__":
|
| 100 |
demo.launch()
|
| 101 |
-
|
| 102 |
-
|
|
|
|
| 4 |
"""
|
| 5 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
| 6 |
"""
|
| 7 |
+
client = InferenceClient("susanazhou/our.modelo_final")
|
| 8 |
|
| 9 |
|
| 10 |
+
# Funci贸n para generar respuesta usando text_generation
|
| 11 |
+
def respond(message, history, system_message, max_tokens, temperature, top_p):
|
| 12 |
+
# Arma el prompt incluyendo sistema, historial y nuevo mensaje
|
| 13 |
+
prompt = system_message + "\n"
|
| 14 |
+
for user_input, assistant_response in history:
|
| 15 |
+
prompt += f"Usuario: {user_input}\nAsistente: {assistant_response}\n"
|
| 16 |
+
prompt += f"Usuario: {message}\nAsistente:"
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
# Llama a la API de Hugging Face para generar texto
|
| 19 |
+
response = client.text_generation(
|
| 20 |
+
prompt=prompt,
|
| 21 |
+
max_new_tokens=max_tokens,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
temperature=temperature,
|
| 23 |
top_p=top_p,
|
| 24 |
+
)
|
|
|
|
| 25 |
|
| 26 |
+
# Extrae solo la parte generada (quita el prompt original)
|
| 27 |
+
generated_text = response.generated_text[len(prompt):]
|
| 28 |
+
return generated_text
|
| 29 |
|
| 30 |
|
| 31 |
|
|
|
|
| 75 |
|
| 76 |
with gr.Tab("Chatbot LeIA GO"):
|
| 77 |
gr.ChatInterface(
|
| 78 |
+
fn=respond,
|
| 79 |
additional_inputs=[
|
| 80 |
+
gr.Textbox(value="Eres una asistente ling眉铆stica especializada en espa帽ol regional.", label="System message"),
|
| 81 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 82 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 83 |
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
|
| 84 |
],
|
| 85 |
)
|
| 86 |
|
| 87 |
+
# Lanza la app
|
| 88 |
if __name__ == "__main__":
|
| 89 |
demo.launch()
|
|
|
|
|
|