Spaces:
Runtime error
Runtime error
ffreemt
commited on
Commit
·
56cf38b
1
Parent(s):
291d572
Update using deepl-fastapi-pw 0.1.0a1
Browse files- 3.0 +2 -0
- app.py +51 -7
- hello.py +8 -0
- install-sw.sh +9 -4
- okteto.yml +1 -0
- requirements-bk.txt +7 -0
- requirements.txt +4 -2
- run-python-app.bat +3 -0
3.0
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
Requirement already satisfied: jinja2 in c:\mat-dir\pypi-projects\gradio-deepl\.venv\lib\site-packages (3.1.2)
|
2 |
+
Requirement already satisfied: MarkupSafe>=2.0 in c:\mat-dir\pypi-projects\gradio-deepl\.venv\lib\site-packages (from jinja2) (2.1.2)
|
app.py
CHANGED
@@ -12,12 +12,33 @@ if platform().lower().startswith("windows"):
|
|
12 |
print(exc)
|
13 |
raise SystemExit(1)
|
14 |
nest_asyncio.apply()
|
|
|
|
|
|
|
|
|
15 |
# """
|
16 |
-
from
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
import gradio as gr
|
|
|
18 |
import httpx
|
19 |
from logzero import logger
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
|
23 |
def deepl(text, from_lang, to_lang):
|
@@ -28,14 +49,26 @@ def deepl(text, from_lang, to_lang):
|
|
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:
|
34 |
-
resp = httpx.get(f"{url}?q={text}&from_lang={from_lang}&to_lang={to_lang}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
resp.raise_for_status()
|
36 |
except Exception as exc:
|
37 |
logger.error(exc)
|
38 |
return str(exc)
|
|
|
39 |
try:
|
40 |
jdata = resp.json()
|
41 |
except Exception as exc:
|
@@ -43,16 +76,27 @@ def deepl(text, from_lang, to_lang):
|
|
43 |
return str(exc)
|
44 |
|
45 |
try:
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
except Exception as exc:
|
48 |
logger.error(exc)
|
49 |
-
|
|
|
50 |
|
51 |
-
return
|
52 |
|
53 |
|
54 |
if __name__ == "__main__":
|
55 |
-
freeze_support()
|
56 |
Process(target=main).start()
|
57 |
|
58 |
iface = gr.Interface(
|
|
|
12 |
print(exc)
|
13 |
raise SystemExit(1)
|
14 |
nest_asyncio.apply()
|
15 |
+
|
16 |
+
from gevent import monkey
|
17 |
+
monkey.patch_all()
|
18 |
+
|
19 |
# """
|
20 |
+
# from gevent import monkey
|
21 |
+
# monkey.patch_all()
|
22 |
+
|
23 |
+
import nest_asyncio
|
24 |
+
# nest_asyncio.apply()
|
25 |
+
|
26 |
+
import asyncio
|
27 |
+
|
28 |
+
from multiprocessing import Process # , freeze_support
|
29 |
import gradio as gr
|
30 |
+
|
31 |
import httpx
|
32 |
from logzero import logger
|
33 |
+
|
34 |
+
# from deepl_fastapi.run_uvicorn import main
|
35 |
+
# from deepl_fastapi_pw.run_uvicorn_async import main
|
36 |
+
from deepl_fastapi_pw.deepl_server_async import main
|
37 |
+
|
38 |
+
# from deepl_scraper_pw.deepl_tr import deepl_tr
|
39 |
+
from deepl_fastapi_pw.deepl_tr import deepl_tr
|
40 |
+
|
41 |
+
arun = asyncio.get_event_loop().run_until_complete
|
42 |
|
43 |
|
44 |
def deepl(text, from_lang, to_lang):
|
|
|
49 |
if not text:
|
50 |
return "Put something there, man."
|
51 |
|
52 |
+
# _ = """
|
53 |
# "http://127.0.0.1:8000/text/?q=test%20me&to_lang=zh"
|
54 |
url = "http://127.0.0.1:8000/text/" # ?q=test%20me&to_lang=zh"
|
55 |
+
url = "http://127.0.0.1:8001/text/" # ?q=test%20me&to_lang=zh"
|
56 |
+
|
57 |
try:
|
58 |
+
# resp = httpx.get(f"{url}?q={text}&from_lang={from_lang}&to_lang={to_lang}")
|
59 |
+
resp = httpx.post(
|
60 |
+
url,
|
61 |
+
json={
|
62 |
+
"text": text,
|
63 |
+
"from_lang": from_lang,
|
64 |
+
"to_lang": to_lang,
|
65 |
+
},
|
66 |
+
)
|
67 |
resp.raise_for_status()
|
68 |
except Exception as exc:
|
69 |
logger.error(exc)
|
70 |
return str(exc)
|
71 |
+
|
72 |
try:
|
73 |
jdata = resp.json()
|
74 |
except Exception as exc:
|
|
|
76 |
return str(exc)
|
77 |
|
78 |
try:
|
79 |
+
# res = jdata.get("trtext")
|
80 |
+
res = jdata.get("result")
|
81 |
+
except Exception as exc:
|
82 |
+
logger.error(exc)
|
83 |
+
res = str(exc)
|
84 |
+
# """
|
85 |
+
|
86 |
+
_ = """
|
87 |
+
try:
|
88 |
+
# _ = deepl_tr(text, from_lang, to_lang)
|
89 |
+
_ = arun(deepl_tr(text, from_lang, to_lang))
|
90 |
except Exception as exc:
|
91 |
logger.error(exc)
|
92 |
+
return str(exc)
|
93 |
+
# """
|
94 |
|
95 |
+
return res
|
96 |
|
97 |
|
98 |
if __name__ == "__main__":
|
99 |
+
# freeze_support()
|
100 |
Process(target=main).start()
|
101 |
|
102 |
iface = gr.Interface(
|
hello.py
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
def greet(name):
|
4 |
+
return "Hello " + name + "!"
|
5 |
+
|
6 |
+
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
7 |
+
|
8 |
+
demo.launch()
|
install-sw.sh
CHANGED
@@ -9,15 +9,20 @@ curl -sSL -C- -o install-poetry.py https://install.python-poetry.org
|
|
9 |
python install-poetry.py
|
10 |
rm install-poetry.py
|
11 |
echo export PATH=~/.local/bin:$PATH > ~/.bashrc
|
12 |
-
|
13 |
# ~/.local/bin/poetry install
|
14 |
|
15 |
-
wget -c https://deb.nodesource.com/setup_14.x
|
16 |
-
|
|
|
|
|
17 |
apt-get install -y nodejs
|
18 |
npm install -g npm@latest
|
19 |
npm install -g nodemon
|
20 |
-
rm setup_14.x
|
|
|
21 |
|
22 |
# apt upate # alerady done in apt-get install -y nodejs
|
23 |
apt install byobu -y > /dev/null 2>&1
|
|
|
|
|
|
9 |
python install-poetry.py
|
10 |
rm install-poetry.py
|
11 |
echo export PATH=~/.local/bin:$PATH > ~/.bashrc
|
12 |
+
|
13 |
# ~/.local/bin/poetry install
|
14 |
|
15 |
+
# wget -c https://deb.nodesource.com/setup_14.x
|
16 |
+
wget -c https://deb.nodesource.com/setup_18.x
|
17 |
+
# bash setup_14.x
|
18 |
+
bash setup_18.x
|
19 |
apt-get install -y nodejs
|
20 |
npm install -g npm@latest
|
21 |
npm install -g nodemon
|
22 |
+
# rm setup_14.x
|
23 |
+
rm setup_18.x
|
24 |
|
25 |
# apt upate # alerady done in apt-get install -y nodejs
|
26 |
apt install byobu -y > /dev/null 2>&1
|
27 |
+
|
28 |
+
source ~/.bashrc
|
okteto.yml
CHANGED
@@ -39,6 +39,7 @@ dev:
|
|
39 |
- 7861:7861
|
40 |
- 7860:7860
|
41 |
- 8501:8501
|
|
|
42 |
reverse:
|
43 |
- 9000:9000
|
44 |
autocreate: true
|
|
|
39 |
- 7861:7861
|
40 |
- 7860:7860
|
41 |
- 8501:8501
|
42 |
+
- 22:22
|
43 |
reverse:
|
44 |
- 9000:9000
|
45 |
autocreate: true
|
requirements-bk.txt
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio==2.9.4
|
2 |
+
deepl-fastapi
|
3 |
+
logzero
|
4 |
+
httpx
|
5 |
+
jinja2==3.0.3
|
6 |
+
aiofiles
|
7 |
+
install
|
requirements.txt
CHANGED
@@ -1,5 +1,7 @@
|
|
1 |
-
gradio
|
2 |
-
|
|
|
|
|
3 |
logzero
|
4 |
httpx
|
5 |
jinja2==3.0.3
|
|
|
1 |
+
# gradio==2.9.4
|
2 |
+
gradio==3.1.1
|
3 |
+
# deepl-fastapi
|
4 |
+
deepl-fastapi-pw
|
5 |
logzero
|
6 |
httpx
|
7 |
jinja2==3.0.3
|
run-python-app.bat
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
set local
|
2 |
+
REM set PYTHONPATH=C:\mat-dir\pypi-projects\deepl-fastapi-playwright
|
3 |
+
python app.py
|