Spaces:
Runtime error
Runtime error
abhilashnl2006
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,27 +1,36 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
|
3 |
-
#
|
4 |
-
|
5 |
-
"
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
}
|
13 |
|
14 |
def chatbot(message, history):
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
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="
|
24 |
-
description="
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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()
|