Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,34 +2,52 @@ import gradio as gr
|
|
| 2 |
import openai
|
| 3 |
import os
|
| 4 |
|
|
|
|
| 5 |
openai.api_key = os.getenv("GROQ_API_KEY")
|
| 6 |
openai.api_base = "https://api.groq.com/openai/v1"
|
| 7 |
|
|
|
|
| 8 |
def get_groq_response(message):
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
|
|
|
| 21 |
def chatbot(user_input, history=[]):
|
| 22 |
-
# Get the response from Groq model
|
| 23 |
bot_response = get_groq_response(user_input)
|
| 24 |
-
history.append((user_input, bot_response))
|
| 25 |
-
return history, history
|
| 26 |
|
| 27 |
-
# Gradio Interface setup
|
| 28 |
chat_interface = gr.Interface(
|
| 29 |
-
fn=chatbot,
|
| 30 |
-
inputs=["text","state"],
|
| 31 |
-
outputs=["chatbot","state"],
|
| 32 |
-
live=False,
|
| 33 |
-
title="
|
| 34 |
-
description=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
chat_interface.launch()
|
|
|
|
| 2 |
import openai
|
| 3 |
import os
|
| 4 |
|
| 5 |
+
# Setting up the API key for Groq API
|
| 6 |
openai.api_key = os.getenv("GROQ_API_KEY")
|
| 7 |
openai.api_base = "https://api.groq.com/openai/v1"
|
| 8 |
|
| 9 |
+
# Function to get a casual, funny response with grammatical errors
|
| 10 |
def get_groq_response(message):
|
| 11 |
+
try:
|
| 12 |
+
response = openai.ChatCompletion.create(
|
| 13 |
+
model="llama-3.1-70b-versatile",
|
| 14 |
+
messages=[
|
| 15 |
+
{
|
| 16 |
+
"role": "system",
|
| 17 |
+
"content": (
|
| 18 |
+
"You are a chill, funny college buddy who talks in Hinglish. Use playful jokes and casual chat language. "
|
| 19 |
+
"Avoid perfect grammar β make intentional grammatical mistakes like missing articles, mixing tenses, and using casual expressions. "
|
| 20 |
+
"Always keep the conversation light-hearted, friendly, and positive. No roasting, no offensive content."
|
| 21 |
+
)
|
| 22 |
+
},
|
| 23 |
+
{"role": "user", "content": message}
|
| 24 |
+
]
|
| 25 |
+
)
|
| 26 |
+
return response.choices[0].message["content"]
|
| 27 |
+
except Exception as e:
|
| 28 |
+
return f"Error: {str(e)}"
|
| 29 |
|
| 30 |
+
# Chatbot function
|
| 31 |
def chatbot(user_input, history=[]):
|
|
|
|
| 32 |
bot_response = get_groq_response(user_input)
|
| 33 |
+
history.append((user_input, bot_response))
|
| 34 |
+
return history, history
|
| 35 |
|
| 36 |
+
# Gradio Interface setup with a fun description
|
| 37 |
chat_interface = gr.Interface(
|
| 38 |
+
fn=chatbot,
|
| 39 |
+
inputs=["text", "state"],
|
| 40 |
+
outputs=["chatbot", "state"],
|
| 41 |
+
live=False,
|
| 42 |
+
title="Bhai ka Chatbot π",
|
| 43 |
+
description=(
|
| 44 |
+
"Welcome to **Bhai ka Chatbot!** π€\n\n"
|
| 45 |
+
"Yaha **GPT nahi, apun hai!**\n\n"
|
| 46 |
+
"Baat karenge college ki life, friends, study tension aur kuch random faaltu jokes bhi milega. π\n\n"
|
| 47 |
+
"Warning: **Thoda chill maar, grammar mat seekh... Apun thoda lazy hai!**\n"
|
| 48 |
+
"*Bol... kya baat hai?* π€"
|
| 49 |
+
),
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
# Launch the Gradio interface
|
| 53 |
chat_interface.launch()
|