-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpyhub.html
More file actions
69 lines (69 loc) · 3.3 KB
/
pyhub.html
File metadata and controls
69 lines (69 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PH LOGO Maker</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css">
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
<py-env>
- pillow
</py-env>
<py-script>
import asyncio
async def start():
from pyodide.http import pyfetch
from js import console
from io import BytesIO
neh = await pyfetch('https://files.pythonhosted.org/packages/7f/f5/1d3c11a2fe82308e312fbe8f93349c11a9e402edf8184172acfada297d24/phlogo-0.6.tar.gz')
await neh.unpack_archive()
sys.path.insert(0, __import__('os').getcwd()+'/phlogo-0.6')
import phlogo
def create(e):
s = BytesIO()
phlogo.generate(document.getElementById('x').value, document.getElementById('y').value).save(s, format='png')
document.getElementById('output').setAttribute('src', 'data:image/jpeg;base64,'+base64.b64encode(s.getvalue()).decode())
document.getElementById('footer').style=''
def download(e):
aEl = document.createElement('a')
aEl.href = document.getElementById('output').src
aEl.download = 'pythonhub.jpg'
aEl.click()
document.getElementById('generate').onclick = create
document.getElementById('download').onclick = download
loop = asyncio.get_event_loop()
loop.run_until_complete(start())
</py-script>
</head>
<body>
<div class="row mt-3">
<div class="col-10 offset-1 col-md-4 offset-md-4">
<div class="card">
<div class="card-title mt-2"><h1 class="text-center">PH LOGO</h1></div>
<div class="card-body">
<div class="row">
<div class="col-md-6 col-12"><input type="text" id="x" class="form-control" placeholder="Python" aria-describedby="basic-addon1"></div>
<div class="col-md-6 col-12 mt-2 mt-md-0"><input type="text" id="y" class="form-control" placeholder="HUB"aria-describedby="basic-addon1"></div>
<div class="col-12 mt-2">
<button type="button" class="btn btn-outline-danger btn-block w-100" id="generate">Generate</button>
</div>
</div>
<img id="output" class="mt-2" width="100%">
</div>
<div class="card-footer" style="display: none;" id="footer">
<button type="button" class="btn btn-outline-primary" id="download">Download</button>
</div>
</div>
</div>
</div>
<style>
.form-control:focus {
border-color: #ff80ff;
box-shadow: 0px 1px 1px rgba(0, 0, 0, 0.075) inset, 0px 0px 8px rgba(255, 100, 255, 0.5);
}
</style>
</body>
</html>