Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Proyecto 12 Llama 3.1 - Groq en Español Latino America Unida
|
| 2 |
+
#
|
| 3 |
+
|
| 4 |
+
import gradio as gr # Intefax gradio en Español usando Blocks
|
| 5 |
+
from groq import Groq
|
| 6 |
+
|
| 7 |
+
# Inicializar el cliente Groq
|
| 8 |
+
client = Groq()
|
| 9 |
+
|
| 10 |
+
# Función para manejar la completación del chat
|
| 11 |
+
def chat_con_bot(mensaje_usuario):
|
| 12 |
+
completion = client.chat.completions.create(
|
| 13 |
+
model="llama-3.1-70b-versatile",
|
| 14 |
+
messages=[
|
| 15 |
+
{
|
| 16 |
+
"role": "user",
|
| 17 |
+
"content": mensaje_usuario
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
temperature=1,
|
| 21 |
+
max_tokens=1024,
|
| 22 |
+
top_p=1,
|
| 23 |
+
stream=True,
|
| 24 |
+
stop=None,
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
# Recopilar la respuesta
|
| 28 |
+
respuesta = ""
|
| 29 |
+
for chunk in completion:
|
| 30 |
+
respuesta += chunk.choices[0].delta.content or ""
|
| 31 |
+
|
| 32 |
+
return respuesta
|
| 33 |
+
|
| 34 |
+
# Configurar la interfaz de Gradio usando Blocks
|
| 35 |
+
with gr.Blocks() as interfaz:
|
| 36 |
+
gr.Markdown("# Chat con IA\nChatea con Llama 3.1 70B en español")
|
| 37 |
+
with gr.Row():
|
| 38 |
+
mensaje = gr.Textbox(label="Escribe tu mensaje")
|
| 39 |
+
respuesta = gr.Textbox(label="Respuesta del bot")
|
| 40 |
+
with gr.Row():
|
| 41 |
+
enviar = gr.Button("Enviar")
|
| 42 |
+
limpiar = gr.Button("Limpiar")
|
| 43 |
+
|
| 44 |
+
enviar.click(fn=chat_con_bot, inputs=mensaje, outputs=respuesta)
|
| 45 |
+
limpiar.click(fn=lambda: "", inputs=None, outputs=mensaje)
|
| 46 |
+
|
| 47 |
+
# Lanzar la aplicación
|
| 48 |
+
interfaz.launch()
|