Download app.py from Anripa/Neurino: direct link, hf CLI and curl.
- Browser
- Download file 1.01 kB
-
https://huggingface.co/spaces/Anripa/Neurino/resolve/main/app.py
- Command line
-
hf download hf://spaces/Anripa/Neurino/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Anripa/Neurino/resolve/main/app.py
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() | |