Compare commits

...

7 Commits

Author SHA1 Message Date
cc8b63f2a2 fix python version to 3.11 2024-01-21 13:48:12 +00:00
684177f0fb update model 2024-01-21 13:45:19 +00:00
9c248a194d use user uid 1000 2023-12-27 23:59:40 +00:00
109e06a5d6 fix: start processing thread 2023-12-27 23:48:37 +00:00
2b844a899f update webpage 2023-12-27 23:36:47 +00:00
d4b43b364a fix: include flask_cors in requirements.txt 2023-12-27 23:32:38 +00:00
46eb1e0045 impl rate limit 2023-12-27 23:32:23 +00:00
8 changed files with 39 additions and 11 deletions

View File

@@ -1,3 +1,4 @@
env env
.git .git
**/__pycache__ **/__pycache__
q

1
.gitignore vendored
View File

@@ -1,2 +1,3 @@
env env
**/__pycache__ **/__pycache__
q

View File

@@ -1,4 +1,4 @@
FROM python:3 FROM python:3.11
ENV PYTHONUNBUFFERED=value ENV PYTHONUNBUFFERED=value
@@ -13,4 +13,12 @@ RUN apt update && apt install -y ffmpeg libsm6 libxext6
COPY src . COPY src .
COPY best.pt /best.pt COPY best.pt /best.pt
CMD [ "gunicorn", "-b 0.0.0.0:80", "app:app" ] RUN chown -R 1000 /usr/src/app
RUN mkdir /.config
RUN mkdir /.cache
RUN chown -R 1000 /.config
RUN chown -R 1000 /.cache
USER 1000
CMD [ "gunicorn", "-b 0.0.0.0:80", "--workers", "1", "app:app" ]

BIN
best.pt

Binary file not shown.

View File

@@ -5,4 +5,4 @@ services:
build: . build: .
restart: unless-stopped restart: unless-stopped
ports: ports:
- 8759:8000 - 8759:80

View File

@@ -1,17 +1,29 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="https://alv.cx/styles.css" />
<title>glass | alv.cx</title>
</head>
<body>
<h1>find glass in an image!</h1>
<img id="img" src="" /> <img id="img" src="" />
<p id="statusline">submit an image to get started!</p> <p id="statusline">submit an image to get started!</p>
<form id="form" action="http://localhost:5000/submit" method="post"> <form id="form" action="https://glass.alv.cx/submit" method="post">
<input type="file" id="job" name="image" accept="image/png,image/jpeg" /><br> <input type="file" id="job" name="image" accept="image/png,image/jpeg" /><br>
<button type="submit" id="submit">submit</button> <button type="submit" id="submit">submit</button>
</form> </form>
<p> built with ❤ and adequate amounts of care by <a href="https://alv.cx">alv</a></p>
<script> <script>
const form = document.getElementById("form"); const form = document.getElementById("form");
const img = document.getElementById("img"); const img = document.getElementById("img");
const statusline = document.getElementById("statusline"); const statusline = document.getElementById("statusline");
async function handleSubmit(ev) { async function handleSubmit(ev) {
statusline.innerHTML = "SUBMITTING"
ev.preventDefault(); ev.preventDefault();
const form = ev.currentTarget; const form = ev.currentTarget;
const data = new FormData(form); const data = new FormData(form);
@@ -26,11 +38,11 @@
console.log(id); console.log(id);
while (true) { while (true) {
const resp = await fetch('http://localhost:5000/state/' + id); const resp = await fetch('https://glass.alv.cx/state/' + id);
const state = (await resp.json()).state; const state = (await resp.json()).state;
statusline.innerHTML = state; statusline.innerHTML = state;
if (state == "READY") { if (state == "READY") {
img.src = 'http://localhost:5000/result/' + id img.src = 'https://glass.alv.cx/result/' + id
return; return;
} }
} }
@@ -38,3 +50,4 @@
form.addEventListener('submit', handleSubmit) form.addEventListener('submit', handleSubmit)
</script> </script>
</body>

View File

@@ -6,6 +6,7 @@ contourpy==1.2.0
cycler==0.12.1 cycler==0.12.1
filelock==3.9.0 filelock==3.9.0
Flask==3.0.0 Flask==3.0.0
Flask-Cors==4.0.0
fonttools==4.47.0 fonttools==4.47.0
fsspec==2023.4.0 fsspec==2023.4.0
gunicorn==21.2.0 gunicorn==21.2.0

View File

@@ -33,7 +33,8 @@ def process():
print("created model") print("created model")
last = 0 last = 0
while True: while True:
if time.time() < last + 10: # wait x seconds before processing another task
if time.time() < last + 2:
print("aa") print("aa")
time.sleep(0.5) time.sleep(0.5)
continue continue
@@ -43,7 +44,7 @@ def process():
print("waiting for/getting job") print("waiting for/getting job")
job = q.get() job = q.get()
filepath = root.joinpath(job) filepath = root.joinpath(job)
print("got job") print("got job", flush=True)
state[job] = { state[job] = {
'state': QUEUE_STATE_PROCESSING, 'state': QUEUE_STATE_PROCESSING,
} }
@@ -61,6 +62,12 @@ def process():
filepath.unlink() filepath.unlink()
last = time.time()
p = Thread(target=process)
p.start()
@app.route("/submit", methods=['POST']) @app.route("/submit", methods=['POST'])
def render(): def render():
@@ -84,7 +91,4 @@ def get_result(i):
if __name__ == '__main__': if __name__ == '__main__':
p = Thread(target=process)
p.start()
app.run(debug=True) app.run(debug=True)
p.join()