Spaces:
Build error
Build error
Create app.py
Browse files12345678910111213141516171819202122232425262728293031323334353637383940import osimport requestsimport gradio as gr
# Load Groq API key from environment variablegroq_api_key = os.getenv("GROQ_API_KEY")
# Groq API endpointurl = "https://api.groq.com/openai/v1/chat/completions"
headers = { "Authorization": f"Bearer {groq_api_key}"}
# Function to call Groq APIdef 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()}"
# Gradio interfaceinterface = gr.Interface( fn=chat_with_groq, inputs=gr.Textbox(lines=2, placeholder="Ask me anything..."), outputs=gr.Textbox(), title="DDS Chat with Groq AI (Llama 3.1-8B)", description="Ask your question to Groq's Llama 3.1-8B model.")
interface.launch()app.pyAdded+40