Kurumi commited on
Commit
67f5019
·
1 Parent(s): 2c7256c

feat: first commit

Browse files
Files changed (3) hide show
  1. Dockerfile +11 -0
  2. app.py +42 -0
  3. requirements.txt +1 -0
Dockerfile ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.12
2
+
3
+ WORKDIR /app
4
+
5
+ COPY --chown=1000 . /app
6
+
7
+ RUN chmod -R 777 /app
8
+
9
+ RUN pip install --break-system-packages --no-cache-dir --requirement requirements.txt
10
+
11
+ CMD ["python", "app.py"]
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import (
2
+ Flask,
3
+ jsonify,
4
+ request,
5
+ send_file,
6
+ )
7
+ from io import BytesIO
8
+ from diffusers import AutoPipelineForText2Image
9
+
10
+
11
+ app = Flask("ImageAPI")
12
+
13
+
14
+ @app.get("/")
15
+ def main():
16
+ prompt = request.args.get("prompt")
17
+
18
+ if not prompt:
19
+ return jsonify({
20
+ "status": "ERROR",
21
+ "message": "Prompt is not found!",
22
+ })
23
+
24
+ pipeline = AutoPipelineForText2Image.from_pretrained(pretrained_model_or_path="Lykon/DreamShaper")
25
+ pipeline.to("cuda")
26
+
27
+ image = pipeline(
28
+ prompt,
29
+ height=1024,
30
+ width=1024,
31
+ ).images[0]
32
+
33
+ return send_file(
34
+ path_or_file=BytesIO(image),
35
+ mimetype="image/png",
36
+ )
37
+
38
+
39
+ app.run(
40
+ host="localhost",
41
+ port=7860,
42
+ )
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ flask