-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
98 lines (92 loc) · 4.54 KB
/
index.html
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<!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">
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
<script defer src="https://pyscript.net/latest/pyscript.js"></script>
<py-config>
[[fetch]]
files = ["./request.py"]
</py-config>
<title>Image descriptor</title>
</head>
<py-script>
import asyncio
import json
from request import request # import our request function.
async def imageRequest(img):
#print("post")
baseurl = "https://jsonplaceholder.typicode.com"
# POST
headers = {"Content-type": "application/json"}
body = json.dumps({"image":img })
new_post = await request(f"{baseurl}/posts", body=body, method="POST", headers=headers)
data = await new_post.json()
#print(f"POST request=> status:{new_post.status}, json:{data}")
description_div = Element('about')
description_div.element.value = "some text"
def processImage(event,data,url):
manual_div = Element("image-display")
manual_div.element.innerHTML = '<img src="#" id="image-preview"/>'
img = Element("image-preview")
img.element.src = url
#print(url)
asyncio.ensure_future(imageRequest(data))
</py-script>
<py-script>
</py-script>
<script>
function mapImage(event){
const fileList = event.target.files;
const selectedFile = fileList[0];
const reader = new FileReader();
reader.onload = function(event) {
const fileURL = event.target.result;
const url = URL.createObjectURL(selectedFile);
const process = pyscript.interpreter.globals.get('processImage') //grab python's 'sorted' function
process(event,fileURL,url)
};
reader.readAsDataURL(selectedFile);
}
</script>
<body class="flex items-center justify-center bg-gray-100">
<div class="bg-white shadow-lg rounded-lg p-8 w-full m-5">
<div class="grid grid-cols-2 gap-4">
<div class="col">
<label for="cover-photo" class="block text-sm font-medium leading-6 text-gray-900">Upload the image to describe</label>
<div class="mt-2 flex justify-center rounded-lg border border-dashed border-gray-900/25 px-6 py-10">
<div class="text-center">
<svg class="mx-auto h-12 w-12 text-gray-300" viewBox="0 0 24 24" fill="currentColor"
aria-hidden="true">
<path fill-rule="evenodd"
d="M1.5 6a2.25 2.25 0 012.25-2.25h16.5A2.25 2.25 0 0122.5 6v12a2.25 2.25 0 01-2.25 2.25H3.75A2.25 2.25 0 011.5 18V6zM3 16.06V18c0 .414.336.75.75.75h16.5A.75.75 0 0021 18v-1.94l-2.69-2.689a1.5 1.5 0 00-2.12 0l-.88.879.97.97a.75.75 0 11-1.06 1.06l-5.16-5.159a1.5 1.5 0 00-2.12 0L3 16.061zm10.125-7.81a1.125 1.125 0 112.25 0 1.125 1.125 0 01-2.25 0z"
clip-rule="evenodd" />
</svg>
<div class="mt-4 flex text-sm leading-6 text-gray-600">
<label for="file-upload"
class="relative cursor-pointer rounded-md bg-white font-semibold text-indigo-600 focus-within:outline-none focus-within:ring-2 focus-within:ring-indigo-600 focus-within:ring-offset-2 hover:text-indigo-500">
<span>Upload a file</span>
<input id="file-upload" name="file-upload" type="file" class="sr-only" onchange="mapImage(event)" accept="image/*">
</label>
<p class="pl-1">or drag and drop</p>
</div>
<p class="text-xs leading-5 text-gray-600">PNG, JPG, GIF up to 10MB</p>
</div>
</div>
<div id="image-display">
</div>
</div>
<div class="col">
<label for="about" class="block text-sm font-medium leading-6 text-gray-900">Image description</label>
<div class="mt-2">
<textarea id="about" name="about" rows="7" class="p-2 block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6"></textarea>
</div>
<p class="mt-3 text-sm leading-6 text-gray-600"></p>
</div>
</div>
</div>
</body>
</html>