Spaces:
Runtime error
Runtime error
freemt
commited on
Commit
·
38b7815
1
Parent(s):
39d4f47
Update minor fix
Browse files- app.py +29 -1
- requirements.txt +2 -1
app.py
CHANGED
@@ -1,3 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from multiprocessing import Process, freeze_support
|
2 |
import gradio as gr
|
3 |
import httpx
|
@@ -6,6 +21,13 @@ from deepl_fastapi.run_uvicorn import main
|
|
6 |
|
7 |
|
8 |
def deepl(text, from_lang, to_lang):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
# "http://127.0.0.1:8000/text/?q=test%20me&to_lang=zh"
|
10 |
url = "http://127.0.0.1:8000/text/" # ?q=test%20me&to_lang=zh"
|
11 |
try:
|
@@ -20,7 +42,13 @@ def deepl(text, from_lang, to_lang):
|
|
20 |
logger.error(exc)
|
21 |
return str(exc)
|
22 |
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
|
26 |
if __name__ == "__main__":
|
|
|
1 |
+
"""Failed attempt to fix "This event loop is already running" in Widows:
|
2 |
+
from platform import platform
|
3 |
+
if platform().lower().startswith("windows"):
|
4 |
+
from install import install
|
5 |
+
try:
|
6 |
+
import nest_asyncio
|
7 |
+
except ModuleNotFoundError:
|
8 |
+
try:
|
9 |
+
install("nest-asyncio")
|
10 |
+
import nest_asyncio
|
11 |
+
except Exception as exc:
|
12 |
+
print(exc)
|
13 |
+
raise SystemExit(1)
|
14 |
+
nest_asyncio.apply()
|
15 |
+
# """
|
16 |
from multiprocessing import Process, freeze_support
|
17 |
import gradio as gr
|
18 |
import httpx
|
|
|
21 |
|
22 |
|
23 |
def deepl(text, from_lang, to_lang):
|
24 |
+
try:
|
25 |
+
text = str(text).strip()
|
26 |
+
except Exception:
|
27 |
+
text = ""
|
28 |
+
if not text:
|
29 |
+
return "Put something there, man."
|
30 |
+
|
31 |
# "http://127.0.0.1:8000/text/?q=test%20me&to_lang=zh"
|
32 |
url = "http://127.0.0.1:8000/text/" # ?q=test%20me&to_lang=zh"
|
33 |
try:
|
|
|
42 |
logger.error(exc)
|
43 |
return str(exc)
|
44 |
|
45 |
+
try:
|
46 |
+
_ = jdata.get("trtext")
|
47 |
+
except Exception as exc:
|
48 |
+
logger.error(exc)
|
49 |
+
_ = str(exc)
|
50 |
+
|
51 |
+
return _
|
52 |
|
53 |
|
54 |
if __name__ == "__main__":
|
requirements.txt
CHANGED
@@ -2,4 +2,5 @@ deepl-fastapi
|
|
2 |
logzero
|
3 |
httpx
|
4 |
jinja2==3.0.3
|
5 |
-
aiofiles
|
|
|
|
2 |
logzero
|
3 |
httpx
|
4 |
jinja2==3.0.3
|
5 |
+
aiofiles
|
6 |
+
install
|