HedronCreeper commited on
Commit
b374e53
·
verified ·
1 Parent(s): 0b4e2ff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -49
app.py CHANGED
@@ -1,53 +1,14 @@
1
- from flask import Flask, request
2
- from PIL import Image, ImageDraw, ImageFont
3
- import io, base64
4
-
5
  app = Flask(__name__)
6
 
7
- HTML_TEMPLATE = """
8
- <!DOCTYPE html>
9
- <html>
10
- <head>
11
- <title>Docker Image Generator</title>
12
- </head>
13
- <body>
14
- <h2>Enter a prompt to generate an image</h2>
15
- <form method="POST">
16
- <input type="text" name="prompt" placeholder="Type your prompt here" required>
17
- <button type="submit">Generate</button>
18
- </form>
19
- {image_tag}
20
- </body>
21
- </html>
22
- """
23
-
24
- @app.route("/", methods=["GET", "POST"])
25
- def home():
26
- image_tag = ""
27
- if request.method == "POST":
28
- text = request.form.get("prompt", "Hello!")
29
-
30
- # Create blank image
31
- img = Image.new("RGB", (256, 256), color=(255, 255, 255))
32
- draw = ImageDraw.Draw(img)
33
-
34
- # Use Pillow default font (always works in slim Python)
35
- font = ImageFont.load_default()
36
-
37
- # Draw text centered
38
- w, h = draw.textsize(text, font=font)
39
- draw.text(((256 - w) / 2, (256 - h) / 2), text, fill="black", font=font)
40
-
41
- # Save image to bytes
42
- img_bytes = io.BytesIO()
43
- img.save(img_bytes, format="PNG")
44
- img_bytes.seek(0)
45
-
46
- # Encode to base64 for embedding
47
- img_b64 = base64.b64encode(img_bytes.getvalue()).decode()
48
- image_tag = f"<h3>Generated Image:</h3><img src='data:image/png;base64,{img_b64}' alt='Generated Image'>"
49
-
50
- return HTML_TEMPLATE.format(image_tag=image_tag)
51
 
52
  if __name__ == "__main__":
53
- app.run(host="0.0.0.0", port=7860)
 
 
 
 
 
 
1
+ from flask import Flask
 
 
 
2
  app = Flask(__name__)
3
 
4
+ @app.route("/")
5
+ def hello():
6
+ return "<h1>🟢 Docker Space is alive</h1><p>Hello from HedronCreeper's Space!</p>"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
  if __name__ == "__main__":
9
+ app.run(host="0.0.0.0", port=7860)
10
+ ```
11
+
12
+ **`requirements.txt`**
13
+ ```
14
+ flask