Spaces:
Runtime error
Runtime error
feat: use the customized submit function
Browse files
app.py
CHANGED
@@ -7,6 +7,10 @@ import time
|
|
7 |
import random
|
8 |
|
9 |
import gradio as gr
|
|
|
|
|
|
|
|
|
10 |
from huggingface_hub import Repository, InferenceClient
|
11 |
from utils import force_git_push
|
12 |
|
@@ -230,7 +234,7 @@ chatbot = gr.Chatbot(label="PersianGPT",
|
|
230 |
rtl=True,
|
231 |
show_share_button=True,
|
232 |
show_copy_button=True,
|
233 |
-
layout="panel",
|
234 |
bubble_full_width = False)
|
235 |
|
236 |
textbox = gr.Textbox(
|
@@ -251,7 +255,30 @@ textbox_whoareu = gr.Textbox(
|
|
251 |
placeholder="Who are you?",
|
252 |
)
|
253 |
|
254 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
255 |
generate,
|
256 |
chatbot=chatbot,
|
257 |
textbox=textbox,
|
|
|
7 |
import random
|
8 |
|
9 |
import gradio as gr
|
10 |
+
from gradio.helpers import special_args
|
11 |
+
from gradio.routes import Request
|
12 |
+
import anyio
|
13 |
+
|
14 |
from huggingface_hub import Repository, InferenceClient
|
15 |
from utils import force_git_push
|
16 |
|
|
|
234 |
rtl=True,
|
235 |
show_share_button=True,
|
236 |
show_copy_button=True,
|
237 |
+
#layout="panel",
|
238 |
bubble_full_width = False)
|
239 |
|
240 |
textbox = gr.Textbox(
|
|
|
255 |
placeholder="Who are you?",
|
256 |
)
|
257 |
|
258 |
+
class ChatInterface(gr.ChatInterface():
|
259 |
+
async def _submit_fn(
|
260 |
+
self,
|
261 |
+
message: str,
|
262 |
+
history_with_input: list[list[str | None]],
|
263 |
+
request: Request,
|
264 |
+
*args,
|
265 |
+
) -> tuple[list[list[str | None]], list[list[str | None]]]:
|
266 |
+
history = history_with_input[:-1]
|
267 |
+
inputs, _, _ = special_args(
|
268 |
+
self.fn, inputs=[message, history, *args], request=request
|
269 |
+
)
|
270 |
+
|
271 |
+
if self.is_async:
|
272 |
+
response = await self.fn(*inputs)
|
273 |
+
else:
|
274 |
+
response = await anyio.to_thread.run_sync(
|
275 |
+
self.fn, *inputs, limiter=self.limiter
|
276 |
+
)
|
277 |
+
|
278 |
+
history.append([message, response])
|
279 |
+
return history, history
|
280 |
+
|
281 |
+
chat_interface = ChatInterface(
|
282 |
generate,
|
283 |
chatbot=chatbot,
|
284 |
textbox=textbox,
|