xyplon
commited on
Delete app.py
Browse files
app.py
DELETED
@@ -1,179 +0,0 @@
|
|
1 |
-
from flask import Flask, render_template,request,jsonify,Response
|
2 |
-
import sys
|
3 |
-
import os
|
4 |
-
import warnings
|
5 |
-
import logging
|
6 |
-
import urllib3
|
7 |
-
import json
|
8 |
-
import requests
|
9 |
-
from flask_cors import CORS
|
10 |
-
import time
|
11 |
-
from flask_limiter import Limiter
|
12 |
-
from flask_limiter.util import get_remote_address
|
13 |
-
|
14 |
-
from hf import *
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
app = Flask(__name__)
|
19 |
-
|
20 |
-
CORS(app)
|
21 |
-
import logging
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
total = 0
|
28 |
-
pending = 0
|
29 |
-
|
30 |
-
|
31 |
-
limiter = Limiter(
|
32 |
-
key_func=get_remote_address,
|
33 |
-
default_limits=["8 per minute"]
|
34 |
-
)
|
35 |
-
limiter.init_app(app)
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
@app.route("/index")
|
41 |
-
def index():
|
42 |
-
message = {'Total Requests: ': total, 'Pending Requests: ': pending}
|
43 |
-
return jsonify(message)
|
44 |
-
|
45 |
-
@app.route('/')
|
46 |
-
def home():
|
47 |
-
return render_template('models.html')
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
@limiter.limit("6 per minute")
|
53 |
-
@app.route('/gen', methods=['POST'])
|
54 |
-
def Hf():
|
55 |
-
|
56 |
-
global total, pending
|
57 |
-
total += 1
|
58 |
-
pending += 1
|
59 |
-
prompt = request.json.get('prompt', '')
|
60 |
-
negative = request.json.get('negative', '')
|
61 |
-
steps = request.json.get('steps', 20)
|
62 |
-
width = request.json.get('width',1024)
|
63 |
-
height = request.json.get('height',1024)
|
64 |
-
scale = request.json.get('scale',7)
|
65 |
-
model = request.json.get('model','sd3')
|
66 |
-
style = request.json.get('style', 'Cinematic')
|
67 |
-
shash = request.json.get('hash')
|
68 |
-
if model == 'rvs4':
|
69 |
-
def generator():
|
70 |
-
global pending
|
71 |
-
while True:
|
72 |
-
try:
|
73 |
-
for info in rvx(prompt=prompt, negative=negative, width=width, height=height, scale=scale, steps=steps, style=style, shash=shash):
|
74 |
-
if "error" in json.dumps(info):
|
75 |
-
|
76 |
-
raise ValueError("Error in response, retrying...")
|
77 |
-
else:
|
78 |
-
yield f'data: {json.dumps(info)}\n\n'
|
79 |
-
pending -= 1
|
80 |
-
break
|
81 |
-
except ValueError as e:
|
82 |
-
continue
|
83 |
-
return Response(generator(), mimetype="text/event-stream")
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
elif model == 'mobius':
|
88 |
-
def generator():
|
89 |
-
global pending
|
90 |
-
while True:
|
91 |
-
try:
|
92 |
-
for info in mobius(prompt=prompt, negative=negative, width=width, height=height, scale=scale, steps=steps, style=style, shash=shash):
|
93 |
-
if "error" in json.dumps(info):
|
94 |
-
raise ValueError("Error in response, retrying...")
|
95 |
-
else:
|
96 |
-
yield f'data: {json.dumps(info)}\n\n'
|
97 |
-
pending -= 1
|
98 |
-
break
|
99 |
-
except ValueError as e:
|
100 |
-
continue
|
101 |
-
return Response(generator(), mimetype="text/event-stream")
|
102 |
-
|
103 |
-
elif model == 'sd3':
|
104 |
-
def generator():
|
105 |
-
global pending
|
106 |
-
while True:
|
107 |
-
try:
|
108 |
-
for info in sd3(prompt=prompt, negative=negative, width=width, height=height, scale=scale, steps=steps, style=style, shash=shash):
|
109 |
-
if "error" in json.dumps(info):
|
110 |
-
raise ValueError("Error in response, retrying...")
|
111 |
-
else:
|
112 |
-
yield f'data: {json.dumps(info)}\n\n'
|
113 |
-
pending -= 1
|
114 |
-
break
|
115 |
-
except ValueError as e:
|
116 |
-
continue
|
117 |
-
return Response(generator(), mimetype="text/event-stream")
|
118 |
-
|
119 |
-
|
120 |
-
elif model == 'sdflash':
|
121 |
-
def generator():
|
122 |
-
global pending
|
123 |
-
while True:
|
124 |
-
try:
|
125 |
-
for info in sdflash(prompt=prompt, negative=negative, width=width, height=height, scale=scale, steps=steps, style=style, shash=shash):
|
126 |
-
if "error" in json.dumps(info):
|
127 |
-
raise ValueError("Error in response, retrying...")
|
128 |
-
else:
|
129 |
-
yield f'data: {json.dumps(info)}\n\n'
|
130 |
-
pending -= 1
|
131 |
-
break
|
132 |
-
except ValueError as e:
|
133 |
-
continue
|
134 |
-
return Response(generator(), mimetype="text/event-stream")
|
135 |
-
|
136 |
-
|
137 |
-
elif model == 'kivotos':
|
138 |
-
def generator():
|
139 |
-
global pending
|
140 |
-
while True:
|
141 |
-
try:
|
142 |
-
for info in kivotos(prompt=prompt, negative=negative, width=width, height=height, scale=scale, steps=steps, style=style, shash=shash):
|
143 |
-
if "error" in json.dumps(info):
|
144 |
-
raise ValueError("Error in response, retrying...")
|
145 |
-
else:
|
146 |
-
yield f'data: {json.dumps(info)}\n\n'
|
147 |
-
pending -= 1
|
148 |
-
break
|
149 |
-
except ValueError as e:
|
150 |
-
continue
|
151 |
-
return Response(generator(), mimetype="text/event-stream")
|
152 |
-
|
153 |
-
elif model == 'OpenDalle':
|
154 |
-
def generator():
|
155 |
-
global pending
|
156 |
-
while True:
|
157 |
-
try:
|
158 |
-
for info in OpenDalle(prompt=prompt, negative=negative, width=width, height=height, scale=scale, steps=steps, style=style, shash=shash):
|
159 |
-
if "error" in json.dumps(info):
|
160 |
-
raise ValueError("Error in response, retrying...")
|
161 |
-
else:
|
162 |
-
yield f'data: {json.dumps(info)}\n\n'
|
163 |
-
pending -= 1
|
164 |
-
break
|
165 |
-
except ValueError as e:
|
166 |
-
continue
|
167 |
-
return Response(generator(), mimetype="text/event-stream")
|
168 |
-
|
169 |
-
else:
|
170 |
-
pending-=1
|
171 |
-
return jsonify('model not found'), 404
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
if __name__ == '__main__':
|
178 |
-
#socketio.start_background_task(background_task)
|
179 |
-
app.run(debug=False, host='0.0.0.0', port=7860)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|