Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,7 @@ import inspect
|
|
| 5 |
from gradio import routes
|
| 6 |
from typing import List, Type
|
| 7 |
|
| 8 |
-
import requests, os, re, asyncio
|
| 9 |
import math
|
| 10 |
import time
|
| 11 |
import datetime
|
|
@@ -31,24 +31,19 @@ def get_types(cls_set: List[Type], component: str):
|
|
| 31 |
return docset, types
|
| 32 |
routes.get_types = get_types
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
_cdata = ""
|
| 37 |
-
_url = ""
|
| 38 |
-
_do = False
|
| 39 |
|
| 40 |
def chat():
|
| 41 |
-
global
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
global _cdata
|
| 45 |
-
if _do:
|
| 46 |
start = time.time()
|
| 47 |
result = gradio_client.predict(
|
| 48 |
-
|
| 49 |
# str representing input in 'User input' Textbox component
|
| 50 |
-
|
| 51 |
-
|
| 52 |
fn_index=0
|
| 53 |
)
|
| 54 |
result = str(result)
|
|
@@ -58,8 +53,7 @@ def chat():
|
|
| 58 |
|
| 59 |
sec = (end - start)
|
| 60 |
result_list = str(datetime.timedelta(seconds=sec)).split(".")
|
| 61 |
-
print("μλ΅ μκ° : " + result_list[0] +"\nx:"+
|
| 62 |
-
_do = False
|
| 63 |
return result
|
| 64 |
|
| 65 |
th_a = Thread(target = chat)
|
|
@@ -68,17 +62,10 @@ th_a.start()
|
|
| 68 |
|
| 69 |
# App code
|
| 70 |
def res(x, id, cdata, url):
|
| 71 |
-
global
|
| 72 |
-
global _x
|
| 73 |
-
global _id
|
| 74 |
-
global _cdata
|
| 75 |
-
global _url
|
| 76 |
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
_cdata = cdata
|
| 80 |
-
_url = url
|
| 81 |
-
_do = True
|
| 82 |
|
| 83 |
print("\n_Done\n\n")
|
| 84 |
return "Done"
|
|
|
|
| 5 |
from gradio import routes
|
| 6 |
from typing import List, Type
|
| 7 |
|
| 8 |
+
import requests, os, re, asyncio, queue
|
| 9 |
import math
|
| 10 |
import time
|
| 11 |
import datetime
|
|
|
|
| 31 |
return docset, types
|
| 32 |
routes.get_types = get_types
|
| 33 |
|
| 34 |
+
|
| 35 |
+
q = queue.Queue()
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
def chat():
|
| 38 |
+
global q
|
| 39 |
+
if !q.empty():
|
| 40 |
+
arr = q.get()
|
|
|
|
|
|
|
| 41 |
start = time.time()
|
| 42 |
result = gradio_client.predict(
|
| 43 |
+
arr[0],
|
| 44 |
# str representing input in 'User input' Textbox component
|
| 45 |
+
arr[1],
|
| 46 |
+
arr[2],
|
| 47 |
fn_index=0
|
| 48 |
)
|
| 49 |
result = str(result)
|
|
|
|
| 53 |
|
| 54 |
sec = (end - start)
|
| 55 |
result_list = str(datetime.timedelta(seconds=sec)).split(".")
|
| 56 |
+
print("μλ΅ μκ° : " + result_list[0] +"\nx:"+ arr[0] +"\nid:"+ arr[1] +"\ncdata:" + arr[2] +"\nresult:"+ result + "\ncollback_url : " + arr[3])
|
|
|
|
| 57 |
return result
|
| 58 |
|
| 59 |
th_a = Thread(target = chat)
|
|
|
|
| 62 |
|
| 63 |
# App code
|
| 64 |
def res(x, id, cdata, url):
|
| 65 |
+
global q
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
+
arr = [x, id, cdata, url]
|
| 68 |
+
q.put(arr)
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
print("\n_Done\n\n")
|
| 71 |
return "Done"
|