0Learn commited on
Commit
ca0c79b
Β·
verified Β·
1 Parent(s): cb20a7a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -8
app.py CHANGED
@@ -40,9 +40,30 @@ game_map = {
40
  }
41
  }
42
 
43
- def get_bot_response(message):
44
  message = message.lower().strip()
45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  if not game_state["game_started"]:
47
  if "start game" in message or "play game" in message:
48
  game_state["game_started"] = True
@@ -92,18 +113,18 @@ def get_bot_response(message):
92
  return "I don't understand that command. Type 'help' for a list of commands."
93
 
94
  # Function to handle user input and generate response
95
- def chat(message, history):
96
  history = history or []
97
  # Add user message to chat history
98
  history.append((message, ""))
99
 
100
  # Get bot response
101
- bot_message = get_bot_response(message)
102
 
103
  # Add bot message to chat history
104
- history.append((message, bot_message))
105
 
106
- return history
107
 
108
  # Function to add selected emoji to input
109
  def add_emoji(emoji, current_input):
@@ -132,7 +153,7 @@ with gr.Blocks() as demo:
132
  with gr.Column(scale=9):
133
  msg = gr.Textbox(label="Type your message here", placeholder="Enter your message...")
134
  with gr.Column(scale=1):
135
- emoji_dropdown = gr.Dropdown(choices=emojis, label="", interactive=True)
136
 
137
  with gr.Row():
138
  submit = gr.Button("Submit")
@@ -148,8 +169,8 @@ with gr.Blocks() as demo:
148
  feedback_text = gr.Textbox(label="Feedback Status")
149
 
150
  # Set up event handlers
151
- submit.click(chat, inputs=[msg, chatbot], outputs=[chatbot])
152
- msg.submit(chat, inputs=[msg, chatbot], outputs=[chatbot])
153
  clear.click(lambda: None, None, chatbot, queue=False)
154
  emoji_dropdown.change(add_emoji, inputs=[emoji_dropdown, msg], outputs=msg)
155
  copy_button.click(copy_last_message, inputs=[chatbot], outputs=[copied_text])
 
40
  }
41
  }
42
 
43
+ def get_bot_response(message, emoji):
44
  message = message.lower().strip()
45
 
46
+ # Emoji-based responses
47
+ emoji_responses = {
48
+ "πŸ˜€": "You seem happy! That's great to see.",
49
+ "πŸ˜‚": "I'm glad you find this amusing!",
50
+ "😊": "Your smile brightens up the adventure!",
51
+ "😍": "Wow, you really love this game, don't you?",
52
+ "πŸ€”": "Hmm, thinking deeply about your next move?",
53
+ "😎": "Looking cool! Ready for some adventure?",
54
+ "πŸ™Œ": "High five! You're doing great!",
55
+ "πŸ‘": "Thumbs up to you too! Keep going!",
56
+ "❀️": "I'm thrilled you're enjoying the game!",
57
+ "πŸŽ‰": "Time to celebrate your progress!"
58
+ }
59
+
60
+ # If an emoji is selected, respond to it
61
+ if emoji in emoji_responses:
62
+ return emoji_responses[emoji] + "\n\n" + get_game_response(message)
63
+ else:
64
+ return get_game_response(message)
65
+
66
+ def get_game_response(message):
67
  if not game_state["game_started"]:
68
  if "start game" in message or "play game" in message:
69
  game_state["game_started"] = True
 
113
  return "I don't understand that command. Type 'help' for a list of commands."
114
 
115
  # Function to handle user input and generate response
116
+ def chat(message, history, emoji):
117
  history = history or []
118
  # Add user message to chat history
119
  history.append((message, ""))
120
 
121
  # Get bot response
122
+ bot_message = get_bot_response(message, emoji)
123
 
124
  # Add bot message to chat history
125
+ history[-1] = (message, bot_message)
126
 
127
+ return history, "" # Return an empty string to clear the input
128
 
129
  # Function to add selected emoji to input
130
  def add_emoji(emoji, current_input):
 
153
  with gr.Column(scale=9):
154
  msg = gr.Textbox(label="Type your message here", placeholder="Enter your message...")
155
  with gr.Column(scale=1):
156
+ emoji_dropdown = gr.Dropdown(choices=emojis, label="", value="", interactive=True)
157
 
158
  with gr.Row():
159
  submit = gr.Button("Submit")
 
169
  feedback_text = gr.Textbox(label="Feedback Status")
170
 
171
  # Set up event handlers
172
+ submit.click(chat, inputs=[msg, chatbot, emoji_dropdown], outputs=[chatbot, msg])
173
+ msg.submit(chat, inputs=[msg, chatbot, emoji_dropdown], outputs=[chatbot, msg])
174
  clear.click(lambda: None, None, chatbot, queue=False)
175
  emoji_dropdown.change(add_emoji, inputs=[emoji_dropdown, msg], outputs=msg)
176
  copy_button.click(copy_last_message, inputs=[chatbot], outputs=[copied_text])