Spaces:
Sleeping
Sleeping
import gradio as gr | |
import openai | |
import os | |
# Set up OpenAI API key and base URL | |
openai.api_key = os.getenv("OPENAI_API_KEY") | |
openai.api_base = "https://api.groq.com/openai/v1" | |
def get_groq_response(message): | |
try: | |
response = openai.ChatCompletion.create( | |
model="llama-3.1-70b-versatile", | |
messages=[ | |
{"role": "system", "content": "You are a friendly and helpful assistant."}, | |
{"role": "user", "content": message} | |
] | |
) | |
return response.choices[0].message["content"] | |
except Exception as e: | |
return f"Error: {str(e)}" | |
def chatbot(user_input, history=[]): | |
bot_response = get_groq_response(user_input) | |
history.append((user_input, bot_response)) | |
return history, history | |
# Gradio Interface | |
chat_interface = gr.Interface( | |
fn=chatbot, | |
inputs=["text", "state"], | |
outputs=["chatbot", "state"], | |
live=False, | |
title="PYAAR_KA_SAATHI", | |
description="A friendly and conversational chatbot for students." | |
) | |
chat_interface.launch() | |