abhilashnl2006 commited on
Commit
91da114
·
verified ·
1 Parent(s): 06dd63b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -31
app.py CHANGED
@@ -1,36 +1,25 @@
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()
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
 
 
2
 
3
+ def clear_message():
4
+ return None
 
 
 
 
 
 
 
5
 
6
+ def undo_message():
7
+ return None
 
 
 
8
 
9
+ def submit_input():
10
+ return None
 
 
 
 
 
 
 
 
 
 
 
11
 
12
+ with gr.Blocks() as app:
13
+ with gr.Row():
14
+ chat_interface = gr.Chatbox()
15
+ buttons = [
16
+ gr.Button("Clear"),
17
+ gr.Button("Undo"),
18
+ gr.Button("Submit")
19
+ ]
20
+
21
+ chat_interface.change(clear_message, inputs=buttons[0], outputs=chat_interface)
22
+ chat_interface.change(undo_message, inputs=buttons[1], outputs=chat_interface)
23
+ chat_interface.change(submit_input, inputs=buttons[2], outputs=chat_interface)
24
+
25
+ app.launch()