Abusive_ChatBot / app.py
SatyamSinghal's picture
Update app.py
97741eb verified
import gradio as gr
import openai
import os
import random
# Setting up the API key for Groq API
openai.api_key = os.getenv("GROQ_API_KEY")
openai.api_base = "https://api.groq.com/openai/v1"
# Predefined fine-tuned chat dataset for reference
fine_tuned_chats = [
{"user": "Bhai, padhai nahi ho rahi…", "bot": "Arre, chill kar bhai! Padhai ki tension mat le, thoda break le… Mast coffee maar aur wapas aa ja. ☕"},
{"user": "Yaar, motivation nahi mil raha…", "bot": "Motivation milta nahi… Usko dhoondhna padta hai! 😎 Ek goal set kar aur bas lag ja kaam pe."},
{"user": "Life boring lag rahi hai…", "bot": "Arre bhai, life boring nahi hoti… Bas hum thoda lazy ho jate hai! 😂 Chal, kuch naya try kar!"},
{"user": "Bro, exam aa raha hai… tension ho rahi hai.", "bot": "Arre bhai, tension lene ka nahi… Last night ke revision pe bharosa rakh! 📚"},
{"user": "Bhai, dosti mein problem ho gayi hai…", "bot": "Arre, dosti ka funda simple hai… Ego hatao, apna dil kholo. Jo real friend hoga, woh samjhega. 🤝"},
{"user": "Bore ho raha hoon… Timepass karna hai.", "bot": "Arre, meme dekho, thoda gaming karlo, ya kisi se baat karlo. Zindagi ka mazza lo! 😂"},
{"user": "Career ko lekar confuse hoon… kya karu?", "bot": "Confusion sabko hota hai… Thoda explore karo, apne interest find karo. Passion follow karo, paise apne aap aayenge. 💼"}
]
# Function to get a casual, funny response with grammatical errors
def get_groq_response(message):
# Check if the user message matches any fine-tuned chat
for chat in fine_tuned_chats:
if message.lower() == chat["user"].lower():
return chat["bot"]
# If not in the predefined chats, call the Groq API
try:
response = openai.ChatCompletion.create(
model="llama-3.1-70b-versatile",
messages=[
{
"role": "system",
"content": (
"You are a chill, funny college buddy who talks in Hinglish. Use playful jokes and casual chat language. "
"Avoid perfect grammar — make intentional grammatical mistakes like missing articles, mixing tenses, and using casual expressions. "
"Always keep the conversation light-hearted, friendly, and positive. No roasting, no offensive content."
)
},
{"role": "user", "content": message}
]
)
return response.choices[0].message["content"]
except Exception as e:
return f"Error: {str(e)}"
# Chatbot function
def chatbot(user_input, history=[]):
bot_response = get_groq_response(user_input)
history.append((user_input, bot_response))
return history, history
# Gradio Interface setup with a fun description
chat_interface = gr.Interface(
fn=chatbot,
inputs=["text", "state"],
outputs=["chatbot", "state"],
live=False,
title="Bhai ka Chatbot 😎",
description=(
"Welcome to **Bhai ka Chatbot!** 🤓\n\n"
"Yaha **GPT nahi, apun hai!**\n\n"
"Baat karenge college ki life, friends, study tension aur kuch random faaltu jokes bhi milega. 😂\n\n"
"Warning: **Thoda chill maar, grammar mat seekh... Apun thoda lazy hai!**\n"
"*Bol... kya baat hai?* 🤙"
),
)
# Launch the Gradio interface
chat_interface.launch()