Spaces:
Sleeping
Sleeping
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() | |