MrOvkill commited on
Commit
d1d2aa6
1 Parent(s): c225ca5

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +2 -8
  2. app.py +80 -0
  3. requirements.txt +2 -0
README.md CHANGED
@@ -1,12 +1,6 @@
1
  ---
2
  title: Snail
3
- emoji: 🌍
4
- colorFrom: gray
5
- colorTo: yellow
6
- sdk: gradio
7
- sdk_version: 4.19.1
8
  app_file: app.py
9
- pinned: false
 
10
  ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
  title: Snail
 
 
 
 
 
3
  app_file: app.py
4
+ sdk: gradio
5
+ sdk_version: 4.18.0
6
  ---
 
 
app.py ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import base64
2
+ import hashlib
3
+ import json
4
+ import time
5
+ import gradio as gr
6
+ import os
7
+ import queue
8
+ import zstandard as zstd
9
+
10
+ q = queue.Queue()
11
+
12
+ """
13
+ Format:
14
+ {
15
+ "status": "queue" | "progress" | "done"
16
+ "prompt": "Some ducks..."
17
+ "id": "abc123"
18
+ }
19
+ """
20
+ models = []
21
+
22
+ WORKERS = []
23
+
24
+ def enqueue(prompt: str):
25
+ tm = time.time()
26
+ hsh = hashlib.sha256(prompt.encode("utf-8")).hexdigest()
27
+ md = {
28
+ "status": "queue",
29
+ "prompt": prompt,
30
+ "id": f"{hsh}.{tm}"
31
+ }
32
+ models.append(md)
33
+ q.put(json.dumps(md))
34
+
35
+ def dequeue():
36
+ if not q.empty():
37
+ pr = json.loads(q.get_nowait())
38
+ return json.dumps({
39
+ "status": "ok",
40
+ "prompt": pr["prompt"],
41
+ "id": pr["id"]
42
+ })
43
+ return json.dumps({
44
+ "status": "empty"
45
+ })
46
+
47
+ def complete(data):
48
+ jsn = json.loads(data)
49
+ for i in range(len(models)):
50
+ if models[i]["id"] == jsn["_id"]:
51
+ models[i]["status"] = "done"
52
+ for fl in jsn["files"]:
53
+ rd = zstd.decompress(base64.b64decode(fl["data"]))
54
+ os.makedirs(f"files/{fl['path']}", exist_ok=True)
55
+ os.rmdir(f"files/{fl['path']}")
56
+ with open(f"files/{fl['path']}", "wb") as f:
57
+ f.write(rd)
58
+ f.flush()
59
+ f.close()
60
+ break
61
+ return json.dumps({"status": "ok"})
62
+
63
+ with gr.Blocks() as bl:
64
+ with gr.Row("panel"):
65
+ gr.Label("Enter a prompt to generate an image. This is a work-in-progress. Release 1.")
66
+ with gr.Row("panel"):
67
+ prompt_input = gr.Textbox(placeholder="Enter a prompt here")
68
+ with gr.Row("panel"):
69
+ submit_button = gr.Button(value="Generate")
70
+ with gr.Row("panel"):
71
+ image_output = gr.Image(label="Generated Image")
72
+ with gr.Row("none"):
73
+ shad_out = gr.Textbox(visible=False)
74
+ shad_dequeue = gr.Button(value="Dequeue", visible=False)
75
+ shad_in = gr.Textbox(visible=False)
76
+ shad_complete = gr.Button(value="Complete", visible=False)
77
+ submit_button.click(enqueue, inputs=[prompt_input], api_name="enqueue")
78
+ shad_dequeue.click(dequeue, outputs=[shad_out], api_name="dequeue")
79
+ shad_complete.click(complete, inputs=[shad_in], outputs=[shad_out], api_name="complete")
80
+ bl.launch(share=False, debug=True)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio
2
+ zstandard