Update app.py
Browse files
app.py
CHANGED
@@ -79,10 +79,11 @@ index_html = """
|
|
79 |
const sampler = document.getElementById("sampler").value;
|
80 |
const strength = document.getElementById("strength").value;
|
81 |
const seed = document.getElementById("seed").value;
|
82 |
-
|
83 |
const button = document.getElementById("generate-button");
|
|
|
84 |
button.disabled = true; // ボタンを無効化
|
85 |
-
|
|
|
86 |
const params = new URLSearchParams({
|
87 |
prompt,
|
88 |
negative_prompt,
|
@@ -95,14 +96,16 @@ index_html = """
|
|
95 |
seed
|
96 |
});
|
97 |
|
|
|
|
|
|
|
98 |
try {
|
99 |
-
const response = await fetch(
|
100 |
if (!response.ok) {
|
101 |
-
|
|
|
102 |
}
|
103 |
const imageBlob = await response.blob();
|
104 |
-
|
105 |
-
// Convert Blob to Data URL
|
106 |
const reader = new FileReader();
|
107 |
reader.onloadend = function () {
|
108 |
const img = document.getElementById("generated-image");
|
@@ -111,7 +114,8 @@ index_html = """
|
|
111 |
};
|
112 |
reader.readAsDataURL(imageBlob);
|
113 |
} catch (error) {
|
114 |
-
|
|
|
115 |
} finally {
|
116 |
button.disabled = false; // ボタンを再有効化
|
117 |
}
|
@@ -142,25 +146,25 @@ index_html = """
|
|
142 |
<h1>FLUX.1-Dev Image Generator</h1>
|
143 |
<form onsubmit="event.preventDefault(); generateImage();">
|
144 |
<label for="prompt">Prompt:</label><br>
|
145 |
-
<textarea id="prompt" name="prompt" rows="4" cols="50" placeholder="Enter your prompt" required
|
146 |
|
147 |
<label for="negative_prompt">Negative Prompt:</label><br>
|
148 |
-
<textarea id="negative_prompt" name="negative_prompt" rows="4" cols="50" placeholder="Enter negative prompt (optional)"
|
149 |
-
|
150 |
<label for="width">Width:</label>
|
151 |
-
<input type="number" id="width" name="width" value="1024" min="64" max="2048" step="8" oninput="syncWidth(this.value)">
|
152 |
-
<input type="range" id="width-slider" name="width-slider" min="64" max="2048" value="1024" step="8" oninput="updateWidthInput()"><br><br>
|
153 |
-
|
154 |
<label for="height">Height:</label>
|
155 |
<input type="number" id="height" name="height" value="1024" min="64" max="2048" step="8" oninput="syncHeight(this.value)">
|
156 |
-
<input type="range" id="height-slider" name="height-slider" min="64" max="2048" value="1024" step="8" oninput="updateHeightInput()"><br><br>
|
157 |
-
|
158 |
<label for="steps">Sampling Steps:</label>
|
159 |
<input type="number" id="steps" name="steps" value="35"><br><br>
|
160 |
-
|
161 |
<label for="cfgs">CFG Scale:</label>
|
162 |
<input type="number" id="cfgs" name="cfgs" value="7"><br><br>
|
163 |
-
|
164 |
<label for="sampler">Sampling Method:</label>
|
165 |
<select id="sampler" name="sampler">
|
166 |
<option value="DPM++ 2M Karras">DPM++ 2M Karras</option>
|
@@ -170,19 +174,23 @@ index_html = """
|
|
170 |
<option value="Heun">Heun</option>
|
171 |
<option value="DDIM">DDIM</option>
|
172 |
</select><br><br>
|
173 |
-
|
174 |
<label for="strength">Strength:</label>
|
175 |
<input type="number" id="strength" name="strength" value="0.7" step="0.01" min="0" max="1"><br><br>
|
176 |
-
|
177 |
<label for="seed">Seed:</label>
|
178 |
<input type="number" id="seed" name="seed" value="-1" step="1"><br><br>
|
179 |
-
|
180 |
<button type="submit" id="generate-button">Generate Image</button>
|
181 |
</form>
|
|
|
|
|
|
|
182 |
<h2>Generated Image:</h2>
|
183 |
<img id="generated-image" src="" alt="Generated Image" style="max-width: 100%; height: auto; display: none;">
|
184 |
</body>
|
185 |
</html>
|
|
|
186 |
"""
|
187 |
|
188 |
@app.route('/')
|
|
|
79 |
const sampler = document.getElementById("sampler").value;
|
80 |
const strength = document.getElementById("strength").value;
|
81 |
const seed = document.getElementById("seed").value;
|
|
|
82 |
const button = document.getElementById("generate-button");
|
83 |
+
const errorMessage = document.getElementById("error-message");
|
84 |
button.disabled = true; // ボタンを無効化
|
85 |
+
errorMessage.textContent = ''; // エラーメッセージをクリア
|
86 |
+
|
87 |
const params = new URLSearchParams({
|
88 |
prompt,
|
89 |
negative_prompt,
|
|
|
96 |
seed
|
97 |
});
|
98 |
|
99 |
+
const reqURL = `https://soiz-flux-1-dev-serverless.hf.space/generate?${params.toString()}`;
|
100 |
+
document.getElementById("reqURL").value = reqURL; // URLを設定
|
101 |
+
|
102 |
try {
|
103 |
+
const response = await fetch(reqURL);
|
104 |
if (!response.ok) {
|
105 |
+
const errorText = await response.text(); // エラーメッセージを取得
|
106 |
+
throw new Error(`画像生成に失敗しました: ${errorText}`);
|
107 |
}
|
108 |
const imageBlob = await response.blob();
|
|
|
|
|
109 |
const reader = new FileReader();
|
110 |
reader.onloadend = function () {
|
111 |
const img = document.getElementById("generated-image");
|
|
|
114 |
};
|
115 |
reader.readAsDataURL(imageBlob);
|
116 |
} catch (error) {
|
117 |
+
errorMessage.textContent = error.message; // エラーメッセージを表示
|
118 |
+
console.error(error); // エラーをコンソールに出力
|
119 |
} finally {
|
120 |
button.disabled = false; // ボタンを再有効化
|
121 |
}
|
|
|
146 |
<h1>FLUX.1-Dev Image Generator</h1>
|
147 |
<form onsubmit="event.preventDefault(); generateImage();">
|
148 |
<label for="prompt">Prompt:</label><br>
|
149 |
+
<textarea id="prompt" name="prompt" rows="4" cols="50" placeholder="Enter your prompt" required>real, sky, blue, clouds, light blue, light blue sky, sun, 32K, many islands floating in the sky, Ghibli, many islands, many islands in the sky, islands in the clouds, old islands, fog, high quality, cool</textarea><br><br>
|
150 |
|
151 |
<label for="negative_prompt">Negative Prompt:</label><br>
|
152 |
+
<textarea id="negative_prompt" name="negative_prompt" rows="4" cols="50" placeholder="Enter negative prompt (optional)">(deformed, distorted, disfigured), poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, (mutated hands and fingers), disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation, misspellings, typos</textarea><br><br>
|
153 |
+
|
154 |
<label for="width">Width:</label>
|
155 |
+
<input type="number" id="width" name="width" value="1024" min="64" max="2048" step="8" style="width:250px" oninput="syncWidth(this.value)">
|
156 |
+
<input type="range" id="width-slider" name="width-slider" min="64" max="2048" value="1024" step="8" style="width:250px; display: inline-block;" oninput="updateWidthInput()"><br><br>
|
157 |
+
|
158 |
<label for="height">Height:</label>
|
159 |
<input type="number" id="height" name="height" value="1024" min="64" max="2048" step="8" oninput="syncHeight(this.value)">
|
160 |
+
<input type="range" id="height-slider" name="height-slider" min="64" max="2048" value="1024" step="8" style="width:250px; display: inline-block;" oninput="updateHeightInput()"><br><br>
|
161 |
+
|
162 |
<label for="steps">Sampling Steps:</label>
|
163 |
<input type="number" id="steps" name="steps" value="35"><br><br>
|
164 |
+
|
165 |
<label for="cfgs">CFG Scale:</label>
|
166 |
<input type="number" id="cfgs" name="cfgs" value="7"><br><br>
|
167 |
+
|
168 |
<label for="sampler">Sampling Method:</label>
|
169 |
<select id="sampler" name="sampler">
|
170 |
<option value="DPM++ 2M Karras">DPM++ 2M Karras</option>
|
|
|
174 |
<option value="Heun">Heun</option>
|
175 |
<option value="DDIM">DDIM</option>
|
176 |
</select><br><br>
|
177 |
+
|
178 |
<label for="strength">Strength:</label>
|
179 |
<input type="number" id="strength" name="strength" value="0.7" step="0.01" min="0" max="1"><br><br>
|
180 |
+
|
181 |
<label for="seed">Seed:</label>
|
182 |
<input type="number" id="seed" name="seed" value="-1" step="1"><br><br>
|
183 |
+
|
184 |
<button type="submit" id="generate-button">Generate Image</button>
|
185 |
</form>
|
186 |
+
<p id="reqURL"></p>
|
187 |
+
<div id="error-message" style="color: red;"></div>
|
188 |
+
|
189 |
<h2>Generated Image:</h2>
|
190 |
<img id="generated-image" src="" alt="Generated Image" style="max-width: 100%; height: auto; display: none;">
|
191 |
</body>
|
192 |
</html>
|
193 |
+
|
194 |
"""
|
195 |
|
196 |
@app.route('/')
|