File size: 874 Bytes
7e75850
 
 
 
 
01a92dc
7e75850
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import os
from groq import Groq

# Initialize Groq client
client = Groq(api_key="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")

# Chat function
def chat_with_groq(user_input):
    try:
        # Create a chat completion request
        chat_completion = client.chat.completions.create(
            messages=[
                {"role": "user", "content": user_input},
            ],
            model="llama-3.3-70b-versatile",
        )
        # Return the AI's response
        return chat_completion.choices[0].message.content
    except Exception as e:
        return f"Error: {e}"

# Gradio interface
iface = gr.Interface(
    fn=chat_with_groq,
    inputs="text",
    outputs="text",
    title="Groq Chatbot",
    description="A chatbot powered by Groq API and Gradio."
)

# Launch locally
if __name__ == "__main__":
    iface.launch()