Spaces:
Build error
Build error
ffreemt
commited on
Commit
•
c707091
1
Parent(s):
3294385
Update app-org.py
Browse files- app-org.py +14 -5
- app.py +63 -4
- run-app.bat +1 -0
app-org.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
-
"""
|
|
|
2 |
|
3 |
colab gradio-chatinterface.
|
4 |
|
@@ -40,12 +41,20 @@ def chat(message, history):
|
|
40 |
):
|
41 |
yield response
|
42 |
|
|
|
|
|
|
|
43 |
|
44 |
-
gr.ChatInterface(
|
45 |
chat,
|
|
|
|
|
|
|
46 |
title="gradio-chatinterface-tryout",
|
47 |
-
# description="fooling around",
|
48 |
-
# examples=[["test me"],],
|
49 |
examples=examples_list,
|
50 |
theme=gr.themes.Glass(text_size="sm", spacing_size="sm"),
|
51 |
-
).queue(max_size=
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
Try out gradio.Chatinterface.
|
3 |
|
4 |
colab gradio-chatinterface.
|
5 |
|
|
|
41 |
):
|
42 |
yield response
|
43 |
|
44 |
+
chatbot = gr.Chatbot([], label="Bot", height=450)
|
45 |
+
textbox = gr.Textbox('', scale=10, label='', lines=2, placeholder="Ask me anything")
|
46 |
+
submit_btn = gr.Button(value="Send", scale=1, min_width=0, variant="primary")
|
47 |
|
48 |
+
interf = gr.ChatInterface(
|
49 |
chat,
|
50 |
+
chatbot=chatbot,
|
51 |
+
textbox=textbox,
|
52 |
+
submit_btn=submit_btn,
|
53 |
title="gradio-chatinterface-tryout",
|
|
|
|
|
54 |
examples=examples_list,
|
55 |
theme=gr.themes.Glass(text_size="sm", spacing_size="sm"),
|
56 |
+
).queue(max_size=5)
|
57 |
+
|
58 |
+
|
59 |
+
if __name__ == "__main__":
|
60 |
+
interf.launch(debug=True)
|
app.py
CHANGED
@@ -26,6 +26,8 @@ demo.launch()
|
|
26 |
"""
|
27 |
# pylint: disable=line-too-long, missing-module-docstring, missing-function-docstring
|
28 |
# import torch
|
|
|
|
|
29 |
import gradio as gr
|
30 |
|
31 |
|
@@ -43,7 +45,7 @@ def stream_chat():
|
|
43 |
resp += str(elm)
|
44 |
from time import sleep
|
45 |
sleep(0.1)
|
46 |
-
yield
|
47 |
|
48 |
|
49 |
def chat(message="", history=[]):
|
@@ -63,8 +65,9 @@ def chat(message="", history=[]):
|
|
63 |
for response in stream_chat():
|
64 |
# yield response
|
65 |
g.send(response)
|
|
|
66 |
|
67 |
-
|
68 |
|
69 |
|
70 |
def update_chatbot():
|
@@ -72,6 +75,7 @@ def update_chatbot():
|
|
72 |
message = yield
|
73 |
print(f"{message=}")
|
74 |
|
|
|
75 |
def greet(name):
|
76 |
return "Hello " + name + "!"
|
77 |
|
@@ -79,7 +83,9 @@ with gr.Blocks() as block:
|
|
79 |
name = gr.Textbox(label="Name")
|
80 |
output = gr.Textbox(label="Output Box")
|
81 |
greet_btn = gr.Button("Greet")
|
82 |
-
greet_btn.click(fn=greet, inputs=name, outputs=output, api_name="greet")
|
|
|
|
|
83 |
|
84 |
_ = """
|
85 |
with gr.Blocks(theme=gr.themes.Glass(text_size="sm", spacing_size="sm"),) as block:
|
@@ -96,4 +102,57 @@ block(
|
|
96 |
).queue(max_size=2).launch()
|
97 |
# """
|
98 |
|
99 |
-
block.queue(max_size=2).launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
"""
|
27 |
# pylint: disable=line-too-long, missing-module-docstring, missing-function-docstring
|
28 |
# import torch
|
29 |
+
import random
|
30 |
+
import time
|
31 |
import gradio as gr
|
32 |
|
33 |
|
|
|
45 |
resp += str(elm)
|
46 |
from time import sleep
|
47 |
sleep(0.1)
|
48 |
+
yield resp
|
49 |
|
50 |
|
51 |
def chat(message="", history=[]):
|
|
|
65 |
for response in stream_chat():
|
66 |
# yield response
|
67 |
g.send(response)
|
68 |
+
yield response
|
69 |
|
70 |
+
yield 'done ' + response
|
71 |
|
72 |
|
73 |
def update_chatbot():
|
|
|
75 |
message = yield
|
76 |
print(f"{message=}")
|
77 |
|
78 |
+
|
79 |
def greet(name):
|
80 |
return "Hello " + name + "!"
|
81 |
|
|
|
83 |
name = gr.Textbox(label="Name")
|
84 |
output = gr.Textbox(label="Output Box")
|
85 |
greet_btn = gr.Button("Greet")
|
86 |
+
# greet_btn.click(fn=greet, inputs=name, outputs=output, api_name="greet")
|
87 |
+
|
88 |
+
greet_btn.click(fn=chat, inputs=name, outputs=output, api_name="greet")
|
89 |
|
90 |
_ = """
|
91 |
with gr.Blocks(theme=gr.themes.Glass(text_size="sm", spacing_size="sm"),) as block:
|
|
|
102 |
).queue(max_size=2).launch()
|
103 |
# """
|
104 |
|
105 |
+
# block.queue(max_size=2).launch()
|
106 |
+
|
107 |
+
with gr.Blocks() as demo:
|
108 |
+
chatbot = gr.Chatbot()
|
109 |
+
msg = gr.Textbox()
|
110 |
+
clear = gr.ClearButton([msg, chatbot])
|
111 |
+
|
112 |
+
def respond(message, chat_history):
|
113 |
+
bot_message = random.choice(["How are you?", "I love you", "I'm very hungry"])
|
114 |
+
chat_history.append((message, bot_message))
|
115 |
+
time.sleep(2)
|
116 |
+
return "", chat_history
|
117 |
+
|
118 |
+
def respond1(message, chat_history):
|
119 |
+
if chat_history is None:
|
120 |
+
chat_history = []
|
121 |
+
bot_message = random.choice(["How are you?", "I love you", "I'm very hungry"])
|
122 |
+
|
123 |
+
temp = ""
|
124 |
+
chat_history.append((message, temp))
|
125 |
+
for elm in range(len(bot_message)):
|
126 |
+
temp = bot_message[:elm+1]
|
127 |
+
time.sleep(0.2)
|
128 |
+
chat_history[-1] = message, temp
|
129 |
+
yield message, chat_history
|
130 |
+
|
131 |
+
chat_history[-1] = (message, "done " + bot_message)
|
132 |
+
time.sleep(2)
|
133 |
+
|
134 |
+
yield "", chat_history
|
135 |
+
|
136 |
+
def respond2(message, chat_history):
|
137 |
+
if chat_history is None:
|
138 |
+
chat_history = []
|
139 |
+
bot_message = random.choice(["How are you?", "I love you", "I'm very hungry"])
|
140 |
+
|
141 |
+
temp = ""
|
142 |
+
chat_history.append((message, temp))
|
143 |
+
for elm in range(len(bot_message)):
|
144 |
+
temp = bot_message[:elm+1]
|
145 |
+
time.sleep(0.2)
|
146 |
+
chat_history[-1] = message, temp
|
147 |
+
# yield message, chat_history
|
148 |
+
# chatbot.value = chat_history
|
149 |
+
|
150 |
+
chat_history[-1] = (message, "done " + bot_message)
|
151 |
+
time.sleep(2)
|
152 |
+
|
153 |
+
yield "", chat_history
|
154 |
+
|
155 |
+
|
156 |
+
msg.submit(respond2, [msg, chatbot], [msg, chatbot])
|
157 |
+
|
158 |
+
demo.queue(max_size=2).launch()
|
run-app.bat
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
nodemon -w app.py -x python app.py
|