Spaces:
Sleeping
Sleeping
File size: 1,890 Bytes
2819471 ea1876e 2819471 1be8155 98f61bb 2819471 1be8155 2819471 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
import os
import requests
import gradio as gr
groq_api_key = os.environ.get("GROQ_API_KEY")
url = "https://api.groq.com/openai/v1/chat/completions"
headers = {
"Authorization": f"Bearer {groq_api_key}"
}
def chat_with_groq(user_input):
body = {
"model": "llama-3.1-8b-instant",
"messages": [
{"role": "user", "content": user_input}
]
}
response = requests.post(url, headers=headers, json=body)
if response.status_code == 200:
return response.json()['choices'][0]['message']['content']
else:
return f"Error: {response.json()}"
css = """
/* Estilo para el contenedor del título */
.gradio-container h1 {
display: flex;
align-items: center;
justify-content: center; /* Centra el título y el logo */
gap: 10px; /* Espacio entre el logo y el texto */
font-size: 2.5em; /* Ajusta el tamaño de la fuente del título si es necesario */
}
/* Agrega una pseudoclase ::before al h1 para el logo */
.gradio-container h1::before {
content: ''; /* Obligatorio para pseudoclases */
background-image: url('/file=Nullbyte.jpg'); /* Reemplaza con la ruta a tu logo */
background-size: contain; /* Ajusta el tamaño de la imagen dentro del contenedor */
background-repeat: no-repeat;
background-position: center;
width: 60px; /* Ancho del logo */
height: 60px; /* Alto del logo */
display: inline-block; /* Permite controlar el tamaño y alineación */
}
"""
interface = gr.Interface(
fn=chat_with_groq,
inputs=gr.Textbox(lines=2, placeholder="Ask me anything..."),
outputs=gr.Textbox(),
title="Jean Paul Chat with Groq AI (Llama 3.1-8B)", # El título sigue siendo texto normal
description="Type your question below and get a response powered by Groq's Llama 3.1-8B model.",
css=css # Aquí se inyecta el CSS personalizado
)
interface.launch() |