xyplon
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,73 +1,22 @@
|
|
1 |
-
|
2 |
-
import os
|
3 |
-
import json
|
4 |
-
from flask_cors import CORS
|
5 |
-
import time
|
6 |
-
from flask_limiter import Limiter
|
7 |
-
from flask_limiter.util import get_remote_address
|
8 |
-
import requests
|
9 |
-
app = Flask(__name__)
|
10 |
-
CORS(app)
|
11 |
|
12 |
-
|
13 |
-
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
app=app,
|
18 |
-
default_limits=["8 per minute"]
|
19 |
-
)
|
20 |
|
|
|
|
|
|
|
21 |
|
22 |
-
|
23 |
-
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
if(request.remote_addr not in userslist):
|
30 |
-
userslist.append(request.remote_addr)
|
31 |
-
users = len(userslist)
|
32 |
-
return render_template('models.html')
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
def users():
|
37 |
-
return {"total users : " : users}
|
38 |
-
|
39 |
-
@app.route('/gen', methods=['POST'])
|
40 |
-
@limiter.limit("8 per minute")
|
41 |
-
def Hf():
|
42 |
-
|
43 |
-
prompt = request.json.get('prompt', '')
|
44 |
-
negative = request.json.get('negative', '')
|
45 |
-
steps = request.json.get('steps', 20)
|
46 |
-
width = request.json.get('width',1024)
|
47 |
-
height = request.json.get('height',1024)
|
48 |
-
scale = request.json.get('scale',7)
|
49 |
-
model = request.json.get('model','sd3')
|
50 |
-
style = request.json.get('style', 'Cinematic')
|
51 |
-
def Gen(prompt,negative,steps,width,height,scale,style,model):
|
52 |
-
req = requests.post('https://xyplon-server2.hf.space/hf/img/gen',headers={
|
53 |
-
'Authorization' : os.getenv('auth')
|
54 |
-
},json={
|
55 |
-
'prompt': prompt,
|
56 |
-
'negative': negative,
|
57 |
-
'steps': steps,
|
58 |
-
'width': width,
|
59 |
-
'height': height,
|
60 |
-
'scale': scale,
|
61 |
-
'model' : model,
|
62 |
-
'style': style
|
63 |
-
}, stream=True)
|
64 |
-
if(req.status_code!=200):
|
65 |
-
return "an error occurred! ", 500
|
66 |
-
for chunk in req.iter_lines():
|
67 |
-
yield f'{chunk.decode()}\n'
|
68 |
-
|
69 |
-
return Response(Gen(prompt=prompt,negative=negative,steps=steps,width=width,height=height,scale=scale,style=style,model=model), mimetype="text/event-stream")
|
70 |
-
|
71 |
-
|
72 |
-
if __name__ == "__main__":
|
73 |
-
app.run(debug=True, host='0.0.0.0', port=7860, threaded=True)
|
|
|
1 |
+
FROM python:3.9-slim
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
+
# Set working directory
|
4 |
+
WORKDIR /app
|
5 |
|
6 |
+
# Copy the current directory contents into the container at /app
|
7 |
+
COPY . /app
|
|
|
|
|
|
|
8 |
|
9 |
+
# Install Gunicorn and your application dependencies
|
10 |
+
RUN pip install --no-cache-dir gunicorn && \
|
11 |
+
pip install --no-cache-dir -r requirements.txt
|
12 |
|
13 |
+
# Expose the port Gunicorn will listen on
|
14 |
+
EXPOSE 7860
|
15 |
|
16 |
+
# Define environment variables
|
17 |
+
ENV FLASK_APP=app.py
|
18 |
+
ENV FLASK_RUN_HOST=0.0.0.0
|
19 |
+
ENV FLASK_RUN_PORT=7860
|
|
|
|
|
|
|
|
|
20 |
|
21 |
+
# Run the Gunicorn server
|
22 |
+
CMD ["gunicorn", "--bind", "0.0.0.0:7860", "app:app"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|