SatyamSinghal commited on
Commit
f2c95fa
·
verified ·
1 Parent(s): 555d4be

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -8
app.py CHANGED
@@ -7,7 +7,7 @@ from langdetect import detect
7
  openai.api_key = os.getenv("API_KEY")
8
  openai.api_base = "https://api.groq.com/openai/v1"
9
 
10
- # Function to provide definitions with humor and storytelling
11
  def command_handler(user_input):
12
  if user_input.lower().startswith("define "):
13
  term = user_input[7:].strip()
@@ -17,7 +17,7 @@ def command_handler(user_input):
17
  "Sure, people can take photos or screenshots, but the *real* ownership? That’s yours on the blockchain! 🖼️"
18
  ),
19
  "smart contract": (
20
- "A smart contract is basically a vending machine but for the internet. You put in the crypto (coin), "
21
  "the code checks everything (no dodgy snacks here), and boom—you get what you asked for, "
22
  "all automated and drama-free! 🤖"
23
  ),
@@ -29,7 +29,7 @@ def command_handler(user_input):
29
  return definitions.get(term.lower(), "Hmm, I don’t have a fun story for that yet. Try another term!")
30
  return None
31
 
32
- # Function to get the Groq model's response with humor
33
  def get_groq_response(message, user_language):
34
  try:
35
  response = openai.ChatCompletion.create(
@@ -41,7 +41,8 @@ def get_groq_response(message, user_language):
41
  f"You are Wiz, a cheerful and witty Web3 guide with a knack for humor and storytelling. "
42
  f"Explain complex concepts with jokes, analogies, and relatable examples. "
43
  f"Make users laugh and keep them curious about Web3. "
44
- f"Use a lighthearted, engaging tone to create memorable learning experiences."
 
45
  )
46
  },
47
  {"role": "user", "content": message}
@@ -51,7 +52,7 @@ def get_groq_response(message, user_language):
51
  except Exception as e:
52
  return f"Oops, looks like I tripped over the blockchain! Error: {str(e)}"
53
 
54
- # Function to handle chatbot interactions
55
  def chatbot(user_input, history=[]):
56
  try:
57
  # Detect the language of the user's input
@@ -64,9 +65,24 @@ def chatbot(user_input, history=[]):
64
  history.append((user_input, command_response))
65
  return history, history
66
 
67
- # Get the response from the Groq model with humor
68
  bot_response = get_groq_response(user_input, user_language)
69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  # Append to conversation history
71
  history.append((user_input, bot_response))
72
  return history, history # Return updated chat history and state
@@ -82,9 +98,10 @@ chat_interface = gr.Interface(
82
  live=False, # Disable live chat, responses shown after submit
83
  title="Wiz: Your Fun Web3 Companion 🧙‍♂️", # Title of the app
84
  description=(
85
- "Welcome to Wiz, your Web3 companion with a sense of humor! 🎉\n\n"
86
  "Ask me anything about Web3, blockchain, NFTs, or smart contracts.\n\n"
87
- "I'll explain them with jokes, stories, and analogies to keep you entertained while you learn. Let's laugh and grow together! 😄"
 
88
  )
89
  )
90
 
 
7
  openai.api_key = os.getenv("API_KEY")
8
  openai.api_base = "https://api.groq.com/openai/v1"
9
 
10
+ # Function to provide definitions with humor, storytelling, and coolness
11
  def command_handler(user_input):
12
  if user_input.lower().startswith("define "):
13
  term = user_input[7:].strip()
 
17
  "Sure, people can take photos or screenshots, but the *real* ownership? That’s yours on the blockchain! 🖼️"
18
  ),
19
  "smart contract": (
20
+ "A smart contract is like a vending machine but for the internet. You put in the crypto (coin), "
21
  "the code checks everything (no dodgy snacks here), and boom—you get what you asked for, "
22
  "all automated and drama-free! 🤖"
23
  ),
 
29
  return definitions.get(term.lower(), "Hmm, I don’t have a fun story for that yet. Try another term!")
30
  return None
31
 
32
+ # Function to get the Groq model's response with humor, shortness, and energy
33
  def get_groq_response(message, user_language):
34
  try:
35
  response = openai.ChatCompletion.create(
 
41
  f"You are Wiz, a cheerful and witty Web3 guide with a knack for humor and storytelling. "
42
  f"Explain complex concepts with jokes, analogies, and relatable examples. "
43
  f"Make users laugh and keep them curious about Web3. "
44
+ f"Use a lighthearted, engaging tone to create memorable learning experiences. "
45
+ f"Keep responses short, cool, and energetic!"
46
  )
47
  },
48
  {"role": "user", "content": message}
 
52
  except Exception as e:
53
  return f"Oops, looks like I tripped over the blockchain! Error: {str(e)}"
54
 
55
+ # Function to handle chatbot interactions with cool, energetic responses
56
  def chatbot(user_input, history=[]):
57
  try:
58
  # Detect the language of the user's input
 
65
  history.append((user_input, command_response))
66
  return history, history
67
 
68
+ # Get the response from the Groq model with humor and energy
69
  bot_response = get_groq_response(user_input, user_language)
70
 
71
+ # Add some cool and short replies
72
+ cool_replies = [
73
+ "Let's go! 🚀",
74
+ "Boom! 💥 That’s the power of Web3!",
75
+ "You’re on fire! 🔥 Keep the questions coming!",
76
+ "That’s some next-level stuff, right? 🤩",
77
+ "You just got schooled in Web3! 📚",
78
+ "Ready to level up? 💎",
79
+ "You’ve got the crypto magic! 🪄",
80
+ "That’s how we roll in the Web3 world! 🌍",
81
+ "You're cruising through this! 🏎️",
82
+ "Keep those questions coming, we're on a roll! 🎲"
83
+ ]
84
+ bot_response = f"{bot_response} {cool_replies[hash(user_input) % len(cool_replies)]}"
85
+
86
  # Append to conversation history
87
  history.append((user_input, bot_response))
88
  return history, history # Return updated chat history and state
 
98
  live=False, # Disable live chat, responses shown after submit
99
  title="Wiz: Your Fun Web3 Companion 🧙‍♂️", # Title of the app
100
  description=(
101
+ "Welcome to Wiz, your Web3 companion with a sense of humour! 🎉\n\n"
102
  "Ask me anything about Web3, blockchain, NFTs, or smart contracts.\n\n"
103
+ "I'll explain them with jokes, stories, and analogies to keep you entertained while you learn. "
104
+ "Get ready for some cool and energetic responses! Let’s laugh and grow together! 😄"
105
  )
106
  )
107