MrOvkill commited on
Commit
54ca13d
1 Parent(s): 1de5e48

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +29 -42
app.py CHANGED
@@ -1,8 +1,10 @@
 
 
 
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
@@ -31,16 +33,19 @@ def enqueue(prompt: str):
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
 
@@ -58,11 +63,7 @@ def complete(data):
58
  f.flush()
59
  f.close()
60
  break
61
- return json.dumps({"status": "ok"})
62
-
63
- class ValueClass():
64
- def __init__(self, value):
65
- self.value = value
66
 
67
  def worker():
68
  while True:
@@ -71,44 +72,30 @@ def worker():
71
  pr["status"] = "progress"
72
  for w in WORKERS:
73
  if w["status"] == "idle":
74
- w["status"] = "busy"
75
  w["prompt"] = pr["prompt"]
76
  w["id"] = pr["id"]
77
  break
78
  else:
79
- q.put(json.dumps(pr))
80
  time.sleep(1)
 
 
81
 
82
- with gr.Blocks() as bl:
83
- with gr.Row("none"):
84
- shad_out = gr.Textbox(visible=False)
85
- shad_dequeue = gr.Button(value="Dequeue", visible=False)
86
- shad_in = gr.Textbox(visible=False)
87
- shad_complete = gr.Button(value="Complete", visible=False)
88
- shad_submitted = gr.Checkbox(visible=False)
89
- with gr.Row("panel"):
90
- gr.Label("Enter a prompt to generate an image. This is a work-in-progress. Release 1.")
91
- with gr.Row("panel"):
92
- prompt_input = gr.Textbox(placeholder="Enter a prompt here", visible=shad_complete.value)
93
- with gr.Row("panel"):
94
- submit_button = gr.Button(value="Generate", visible=True)
95
- with gr.Row("panel"):
96
- image_output = gr.Image(label="Generated Image")
97
- submit_button.click(enqueue, inputs=[prompt_input], api_name="enqueue")
98
- shad_dequeue.click(dequeue, outputs=[shad_out], api_name="dequeue")
99
- shad_complete.click(complete, inputs=[shad_in], outputs=[shad_out], api_name="complete")
100
-
101
- def kill_the_noise_skrillex(btn):
102
- prompt_input.visible = False
103
- prompt_input.value = ""
104
- submit_button.visible = False
105
- return btn
106
-
107
- prompt_input = gr.Textbox(label="Prompt")
108
- submit_button = gr.Button("Submit")
109
-
110
- demo = gr.Interface(fn=kill_the_noise_skrillex,
111
- inputs=[submit_button],
112
- outputs=[submit_button])
113
 
114
- demo.launch()
 
 
 
 
 
 
1
+ from flask import Flask, render_template, request, redirect, url_for, jsonify, Request, Response
2
+ import json
3
+
4
  import base64
5
  import hashlib
6
  import json
7
  import time
 
8
  import os
9
  import queue
10
  import zstandard as zstd
 
33
  }
34
  models.append(md)
35
  q.put(json.dumps(md))
36
+ return jsonify({
37
+ "status": "ok"
38
+ })
39
 
40
  def dequeue():
41
  if not q.empty():
42
  pr = json.loads(q.get_nowait())
43
+ return jsonify({
44
  "status": "ok",
45
  "prompt": pr["prompt"],
46
  "id": pr["id"]
47
  })
48
+ return jsonify({
49
  "status": "empty"
50
  })
51
 
 
63
  f.flush()
64
  f.close()
65
  break
66
+ return jsonify({"status": "ok"})
 
 
 
 
67
 
68
  def worker():
69
  while True:
 
72
  pr["status"] = "progress"
73
  for w in WORKERS:
74
  if w["status"] == "idle":
 
75
  w["prompt"] = pr["prompt"]
76
  w["id"] = pr["id"]
77
  break
78
  else:
79
+ q.put(jsonify(pr))
80
  time.sleep(1)
81
+
82
+ app = Flask(__name__)
83
 
84
+ if __name__ == "__main__":
85
+ app.add_url_rule("/enqueue/<prompt>", "enqueue", enqueue, methods=["POST"])
86
+ app.add_url_rule("/dequeue", "dequeue", dequeue, methods=["GET"])
87
+ app.add_url_rule("/complete", "complete", complete, methods=["POST"])
88
+ app.add_url_rule("/", "index", lambda: """
89
+ <html>
90
+ <head>
91
+ <title>Snail</title>
92
+ </head>
93
+ <body>
94
+ <h1>Snail</h1>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
 
96
+ </html>
97
+ """, methods=["GET"])
98
+
99
+ app.static_folder = "public"
100
+
101
+ app.run(port=7860, host="0.0.0.0")