SatyamSinghal commited on
Commit
92ed5af
Β·
verified Β·
1 Parent(s): 25b141b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -21
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
- try:
10
- response = openai.ChatCompletion.create(
11
- model = "llama-3.1-70b-versatile",
12
- messages = [
13
- {"role" : "user", "content": "A naught play boy talking in Hinglish"},
14
- {"role" : "user", "content": "A girl doing dirty wild sexual talks in Hinglish"}
15
- ]
16
- )
17
- return response.choices[0].message["content"]
18
- except Exception as e:
19
- return f"Error: {str(e)}"
 
 
 
 
 
 
 
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)) # Append the conversation to history
25
- return history, history # Return history and updated state
26
 
27
- # Gradio Interface setup
28
  chat_interface = gr.Interface(
29
- fn=chatbot, # Function to call for chatbot interaction
30
- inputs=["text","state"], # Input fields: user message and chat history (state)
31
- outputs=["chatbot","state"], # Outputs: the chat and the updated history (state)
32
- live=False, # Disable live chat, responses will be shown after submit
33
- title="My Chatbot", # Title of the app
34
- description="Dekh bhai! Sambhal kar baat krna me Gaali diye bina subah uthta bhi nahi...Apun Acid hai πŸ˜‚ \nChatGPT at home:" )
 
 
 
 
 
 
 
 
 
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()