Divya0503 commited on
Commit
304933a
·
verified ·
1 Parent(s): 38ee967

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -27
app.py CHANGED
@@ -1,43 +1,44 @@
1
  import gradio as gr
2
 
3
- # Initialize conversation history
4
- conversation_history = []
5
-
6
  # Define your chatbot function
7
  def chatbot(input_text):
8
- global conversation_history
9
-
10
- # Add user input to conversation history
11
- conversation_history.append("You: " + input_text)
12
-
13
  # Define some responses based on input_text
14
- if "hello" in input_text.lower():
15
- response = "Bot: Hello! How can I help you?"
16
  elif "how are you" in input_text.lower():
17
- response = "Bot: I'm just a chatbot, but thanks for asking!"
 
 
 
 
 
 
18
  elif "bye" in input_text.lower():
19
- response = "Bot: Goodbye! Have a great day!"
20
- elif "tell me a joke" in input_text.lower():
21
- response = "Bot: Sure, here's one: Why don't skeletons fight each other? They don't have the guts!"
 
 
 
 
 
 
 
 
 
 
 
 
22
  else:
23
- response = "Bot: I'm sorry, I didn't understand that."
24
-
25
- # Add bot response to conversation history
26
- conversation_history.append(response)
27
-
28
- # Limit history to last 5 messages
29
- conversation_history = conversation_history[-5:]
30
-
31
- # Join conversation history with line breaks
32
- history_text = "<br>".join(conversation_history)
33
 
34
- return response, history_text
35
 
36
  # Create the Gradio interface
37
  chatbot_ui = gr.Interface(
38
  fn=chatbot,
39
- inputs=gr.inputs.Textbox(lines=7, label="Input Text"),
40
- outputs=[gr.outputs.Textbox(label="Response"), gr.outputs.HTML(label="Conversation History")],
41
  title="Simple Chatbot",
42
  description="Type a message to chat with the bot."
43
  )
 
1
  import gradio as gr
2
 
 
 
 
3
  # Define your chatbot function
4
  def chatbot(input_text):
 
 
 
 
 
5
  # Define some responses based on input_text
6
+ if "hello" in input_text.lower() or "hi" in input_text.lower():
7
+ response = "Hello! How can I help you?"
8
  elif "how are you" in input_text.lower():
9
+ response = "I'm just a chatbot, but thanks for asking!"
10
+ elif "Who are you" in input_text.lower():
11
+ response = "I'm a chatbot designed to assist you with various tasks and answer your questions."
12
+ elif "what's your name" in input_text.lower():
13
+ response = "I'm just a chatbot, I don't have a name."
14
+ elif "I'm confused" in input_text.lower():
15
+ response = "It's alright. I'm here to help. What are you confused about?"
16
  elif "bye" in input_text.lower():
17
+ response = "Goodbye! Have a great day!"
18
+ elif "Can you assist me with something?" in input_text.lower():
19
+ response = "Of course! What do you need help with?"
20
+ elif "What are the symptoms of the common cold?" in input_text.lower():
21
+ response = "Common cold symptoms include runny nose, sore throat, and cough."
22
+ elif "thank you" in input_text.lower() or "thanks" in input_text.lower():
23
+ response = "You're welcome!"
24
+ elif "How's the weather today?" in input_text.lower():
25
+ response = "I'm not equipped to check the weather, but I hope it's nice wherever you are!"
26
+ elif "I'm feeling sad." in input_text.lower():
27
+ response = "I'm sorry to hear that. Is there anything specific I can do to help?"
28
+ elif "Life is so frustrating!" in input_text.lower():
29
+ response = "I understand. Sometimes things can be challenging. Is there anything I can do to assist you?"
30
+ elif "Tell me a joke." in input_text.lower():
31
+ response = "Sure, here's one: Why don't skeletons fight each other? They don't have the guts!"
32
  else:
33
+ response = "I'm sorry, I didn't understand that."
 
 
 
 
 
 
 
 
 
34
 
35
+ return response
36
 
37
  # Create the Gradio interface
38
  chatbot_ui = gr.Interface(
39
  fn=chatbot,
40
+ inputs = gr.Textbox(lines=7, label="Input Text"),
41
+ outputs = "text",
42
  title="Simple Chatbot",
43
  description="Type a message to chat with the bot."
44
  )