Satyam / app.py
SatyamSinghal's picture
Update app.py
f10f88b verified
import gradio as gr
import openai
import os
openai.api_key = os.getenv("GROQ_API_KEY")
openai.api_base = "https://api.groq.com/openai/v1"
def get_groq_response(message):
try:
response = openai.ChatCompletion.create(
model = "llama-3.3-70b-versatile",
messages = [
{"role" : "user", "content": "Main baat nhi krunga bhidu πŸ˜‚"}
]
)
return response.choices[0].message["content"]
except Exception as e:
return f"Error: {str(e)}"
def chatbot(user_input, history=[]):
# Get the response from Groq model
bot_response = get_groq_response(user_input)
history.append((user_input, bot_response)) # Append the conversation to history
return history, history # Return history and updated state
# Gradio Interface setup
chat_interface = gr.Interface(
fn=chatbot, # Function to call for chatbot interaction
inputs=["text","state"], # Input fields: user message and chat history (state)
outputs=["chatbot","state"], # Outputs: the chat and the updated history (state)
live=False, # Disable live chat, responses will be shown after submit
title="My Chatbot", # Title of the app
description="Apan Tapori hai bhidu, kitna hi krle answer ni dega apun πŸ˜‚ \nChatGPT at home:" )
chat_interface.launch()