Skip to content

Commit

Permalink
Merge pull request #30 from Eidenz/main
Browse files Browse the repository at this point in the history
updated web version with fixed image output
  • Loading branch information
zyddnys authored Dec 13, 2021
2 parents 11325fe + d5f29b8 commit 8cbbebe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
12 changes: 10 additions & 2 deletions ui.html
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
if (STATE !== "error") {
document.getElementById("translated-image-div").style.visibility = "";
document.getElementById("translated-image").src = "";
document.getElementById("translated-image").src = BASE_URI + "result/" + TASKID + "/final.jpg";
document.getElementById("translated-image").src = BASE_URI + "result/" + TASKID;
}
status.innerHTML = '';
ProgressBar.end();
Expand Down Expand Up @@ -213,6 +213,14 @@ <h3>Image/Manga translator</h3>
<input type="radio" id="translator-baidu" name="translator-sel" value="baidu">
<span>Baidu</span>
</label>
<label>
<input type="radio" id="translator-google" name="translator-sel" value="google">
<span>Google</span>
</label>
<label>
<input type="radio" id="translator-deepl" name="translator-sel" value="deepl">
<span>DeepL</span>
</label>
</div>
<div style="padding-bottom: 0.5rem;">
<span>Target language:</span>
Expand Down Expand Up @@ -489,4 +497,4 @@ <h3>Translated image</h3>
ease: 'ease' // DEFAULT, YOU CAN SKIP IT
});
</script>
</html>
</html>
12 changes: 10 additions & 2 deletions web_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from oscrypto import util as crypto_utils
from aiohttp import web
from aiohttp import ClientSession
from io import BytesIO

from collections import deque

Expand Down Expand Up @@ -45,6 +46,13 @@ async def index_async(request):
with open('ui.html', 'r') as fp :
return web.Response(text=fp.read(), content_type='text/html')

@routes.get("/result/{taskid}")
async def result_async(request):
im = Image.open("result/" + request.match_info.get('taskid') + "/final.png")
stream = BytesIO()
im.save(stream, "PNG")
return web.Response(body=stream.getvalue(), content_type='image/png')

@routes.post("/run")
async def run_async(request):
data = await request.post()
Expand All @@ -57,7 +65,7 @@ async def run_async(request):
target_language = 'CHS'
if 'translator' in data :
selected_translator = data['translator'].lower()
if selected_translator not in ['youdao', 'baidu', 'null'] :
if selected_translator not in ['youdao', 'baidu', 'google', 'deepl', 'null'] :
selected_translator = 'youdao'
if 'size' in data :
size = data['size'].upper()
Expand Down Expand Up @@ -211,7 +219,7 @@ async def submit_async(request):
target_language = 'CHS'
if 'translator' in data :
selected_translator = data['translator'].lower()
if selected_translator not in ['youdao', 'baidu', 'null'] :
if selected_translator not in ['youdao', 'baidu', 'google', 'deepl', 'null'] :
selected_translator = 'youdao'
if 'size' in data :
size = data['size'].upper()
Expand Down

0 comments on commit 8cbbebe

Please sign in to comment.