abhilashnl2006 commited on
Commit
06dd63b
·
verified ·
1 Parent(s): 7b41b9c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -17
app.py CHANGED
@@ -1,27 +1,36 @@
1
  import gradio as gr
 
 
2
 
3
- # Dictionary of predefined responses
4
- responses = {
5
- "hello": "Hello! How can I help you today?",
6
- "how are you": "I'm doing well, thank you for asking! How about you?",
7
- "what's your name": "My name is SimpleBot. It's nice to meet you!",
8
- "goodbye": "Goodbye! Have a great day!",
9
- "tell me a joke": "Why don't scientists trust atoms? Because they make up everything!",
10
- "what can you do": "I'm a simple chatbot. I can respond to basic greetings, tell a joke, and provide some information about myself.",
11
- "who created you": "I was created as a simple example of a chatbot using Gradio.",
12
- }
13
 
14
  def chatbot(message, history):
15
- message = message.lower()
16
- if message in responses:
17
- return responses[message]
18
- else:
19
- return "I'm sorry, I don't understand that. Can you try asking something else?"
20
 
21
  iface = gr.ChatInterface(
22
  fn=chatbot,
23
- title="SimpleBot",
24
- description="A simple chatbot that responds to basic queries. Try saying 'hello', 'how are you', or 'tell me a joke'!"
 
 
 
 
 
 
 
 
25
  )
26
 
 
27
  iface.launch()
 
1
  import gradio as gr
2
+ import time
3
+ import random
4
 
5
+ # Function to simulate text generation
6
+ def generate_text(prompt, max_length=50):
7
+ words = prompt.split() + ["the", "a", "an", "in", "on", "at", "to", "for", "with", "by", "from", "of"]
8
+ generated = prompt
9
+ for _ in range(max_length):
10
+ next_word = random.choice(words)
11
+ generated += " " + next_word
12
+ yield generated
13
+ time.sleep(0.1) # Simulate processing time
 
14
 
15
  def chatbot(message, history):
16
+ bot_message = ""
17
+ for chunk in generate_text(message):
18
+ bot_message = chunk
19
+ yield bot_message
 
20
 
21
  iface = gr.ChatInterface(
22
  fn=chatbot,
23
+ title="Streaming Chatbot",
24
+ description="This chatbot demonstrates streaming output. Type a message and watch the response generate gradually!",
25
+ examples=[
26
+ ["Tell me about artificial intelligence"],
27
+ ["What are the benefits of exercise?"],
28
+ ["Explain the importance of climate change"],
29
+ ],
30
+ retry_btn=None,
31
+ undo_btn="Delete Previous",
32
+ clear_btn="Clear",
33
  )
34
 
35
+ iface.queue()
36
  iface.launch()