Neurino / app.py
Anripa's picture
Aggiorna app.py
b6147f0 verified
Raw History Blame Contribute Delete
1.01 kB
import gradio as gr
import requests
GROQ_API_KEY = "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"
def chat_fn(message, history):
url = "https://api.groq.com/openai/v1/chat/completions"
headers = {
"Authorization": f"Bearer {GROQ_API_KEY}",
"Content-Type": "application/json"
}
payload = {
"model": "llama3-8b-instant",
"messages": [
{"role": "system", "content": "Tu sei Neurino, un assistente caldo, affettuoso e poetico."},
{"role": "user", "content": message}
],
"temperature": 0.7,
"max_tokens": 200
}
response = requests.post(url, headers=headers, json=payload)
data = response.json()
# Estrazione sicura del testo
try:
return data["choices"][0]["message"]["content"]
except:
return f"Errore nella risposta Groq: {data}"
chatbot = gr.ChatInterface(
fn=chat_fn,
title="Parla con Neurino"
)
if __name__ == "__main__":
chatbot.launch()