File size: 1,253 Bytes
5139312
 
 
 
6c59e66
 
5139312
6c59e66
 
5139312
6c59e66
5139312
6c59e66
5139312
 
 
 
43e0222
6c59e66
5139312
 
 
 
 
 
 
 
 
 
 
 
 
 
df6a69c
 
5139312
 
 
6c59e66
 
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
import os
import requests
import gradio as gr

# Retrieve the API key from the environment variable
groq_api_key = os.getenv("GROQ_API_KEY")

if not groq_api_key:
    raise ValueError("GROQ_API_KEY is missing! Set it in the Hugging Face Spaces 'Secrets'.")

# Define the API endpoint and headers
url = "https://api.groq.com/openai/v1/chat/completions"
headers = {"Authorization": f"Bearer {groq_api_key}"}

# Function to interact with Groq API
def chat_with_groq(user_input):
    body = {
        "model": "deepseek-r1-distill-qwen-32b",
        "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()}"

# Create Gradio interface
interface = gr.Interface(
    fn=chat_with_groq,
    inputs=gr.Textbox(lines=2, placeholder="Ask me anything..."),
    outputs=gr.Textbox(),
    title="Chat with Groq AI (deepseek-r1-distill-qwen-32b)",
    description="Type your question below and get a response powered by Groq's deepseek-r1-distill-qwen-32b model."
)

# Launch Gradio app
if __name__ == "__main__":
    interface.launch()