Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from flask import Flask, request, jsonify,
|
| 2 |
import requests
|
| 3 |
import io
|
| 4 |
import os
|
|
@@ -68,10 +68,39 @@ index_html = """
|
|
| 68 |
<meta charset="UTF-8">
|
| 69 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 70 |
<title>FLUX.1-Dev Image Generator</title>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
</head>
|
| 72 |
<body>
|
| 73 |
<h1>FLUX.1-Dev Image Generator</h1>
|
| 74 |
-
<form
|
| 75 |
<label for="prompt">Prompt:</label>
|
| 76 |
<input type="text" id="prompt" name="prompt" placeholder="Enter your prompt" required><br><br>
|
| 77 |
|
|
@@ -106,19 +135,17 @@ index_html = """
|
|
| 106 |
<label for="seed">Seed:</label>
|
| 107 |
<input type="number" id="seed" name="seed" value="-1" step="1"><br><br>
|
| 108 |
|
| 109 |
-
<button type="submit">Generate Image</button>
|
| 110 |
</form>
|
| 111 |
-
{% if image_url %}
|
| 112 |
<h2>Generated Image:</h2>
|
| 113 |
-
<img
|
| 114 |
-
{% endif %}
|
| 115 |
</body>
|
| 116 |
</html>
|
| 117 |
"""
|
| 118 |
|
| 119 |
@app.route('/')
|
| 120 |
def index():
|
| 121 |
-
return render_template_string(index_html
|
| 122 |
|
| 123 |
@app.route('/generate', methods=['GET'])
|
| 124 |
def generate_image():
|
|
@@ -150,9 +177,8 @@ def generate_image():
|
|
| 150 |
# Save the image to a file
|
| 151 |
image.save(os.path.join('static', image_filename))
|
| 152 |
|
| 153 |
-
# Return the
|
| 154 |
-
|
| 155 |
-
return render_template_string(index_html, image_url=image_url)
|
| 156 |
|
| 157 |
if __name__ == '__main__':
|
| 158 |
# Ensure the 'static' folder exists for saving images
|
|
|
|
| 1 |
+
from flask import Flask, request, jsonify, render_template_string
|
| 2 |
import requests
|
| 3 |
import io
|
| 4 |
import os
|
|
|
|
| 68 |
<meta charset="UTF-8">
|
| 69 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 70 |
<title>FLUX.1-Dev Image Generator</title>
|
| 71 |
+
<script>
|
| 72 |
+
function generateImage() {
|
| 73 |
+
const prompt = document.getElementById("prompt").value;
|
| 74 |
+
const negative_prompt = document.getElementById("negative_prompt").value;
|
| 75 |
+
const width = document.getElementById("width").value;
|
| 76 |
+
const height = document.getElementById("height").value;
|
| 77 |
+
const steps = document.getElementById("steps").value;
|
| 78 |
+
const cfgs = document.getElementById("cfgs").value;
|
| 79 |
+
const sampler = document.getElementById("sampler").value;
|
| 80 |
+
const strength = document.getElementById("strength").value;
|
| 81 |
+
const seed = document.getElementById("seed").value;
|
| 82 |
+
|
| 83 |
+
const img = document.getElementById("generated-image");
|
| 84 |
+
const button = document.getElementById("generate-button");
|
| 85 |
+
button.disabled = true; // ボタンを無効化
|
| 86 |
+
|
| 87 |
+
const imgSrc = `/generate?prompt=${encodeURIComponent(prompt)}&negative_prompt=${encodeURIComponent(negative_prompt)}&width=${width}&height=${height}&steps=${steps}&cfgs=${cfgs}&sampler=${sampler}&strength=${strength}&seed=${seed}`;
|
| 88 |
+
|
| 89 |
+
img.src = imgSrc; // 画像のsrcを設定
|
| 90 |
+
|
| 91 |
+
img.onload = function() {
|
| 92 |
+
button.disabled = false; // 画像が読み込まれたらボタンを再有効化
|
| 93 |
+
};
|
| 94 |
+
img.onerror = function() {
|
| 95 |
+
alert("画像の生成に失敗しました。");
|
| 96 |
+
button.disabled = false; // エラー時もボタンを再有効化
|
| 97 |
+
};
|
| 98 |
+
}
|
| 99 |
+
</script>
|
| 100 |
</head>
|
| 101 |
<body>
|
| 102 |
<h1>FLUX.1-Dev Image Generator</h1>
|
| 103 |
+
<form onsubmit="event.preventDefault(); generateImage();">
|
| 104 |
<label for="prompt">Prompt:</label>
|
| 105 |
<input type="text" id="prompt" name="prompt" placeholder="Enter your prompt" required><br><br>
|
| 106 |
|
|
|
|
| 135 |
<label for="seed">Seed:</label>
|
| 136 |
<input type="number" id="seed" name="seed" value="-1" step="1"><br><br>
|
| 137 |
|
| 138 |
+
<button type="submit" id="generate-button">Generate Image</button>
|
| 139 |
</form>
|
|
|
|
| 140 |
<h2>Generated Image:</h2>
|
| 141 |
+
<img id="generated-image" src="" alt="Generated Image" style="max-width: 100%; height: auto; display: none;" onload="this.style.display='block';" onerror="this.style.display='none';">
|
|
|
|
| 142 |
</body>
|
| 143 |
</html>
|
| 144 |
"""
|
| 145 |
|
| 146 |
@app.route('/')
|
| 147 |
def index():
|
| 148 |
+
return render_template_string(index_html)
|
| 149 |
|
| 150 |
@app.route('/generate', methods=['GET'])
|
| 151 |
def generate_image():
|
|
|
|
| 177 |
# Save the image to a file
|
| 178 |
image.save(os.path.join('static', image_filename))
|
| 179 |
|
| 180 |
+
# Return the image URL
|
| 181 |
+
return jsonify({"url": f"/static/{image_filename}"})
|
|
|
|
| 182 |
|
| 183 |
if __name__ == '__main__':
|
| 184 |
# Ensure the 'static' folder exists for saving images
|