soiz commited on
Commit
2e4ca03
·
verified ·
1 Parent(s): a9b4580

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +91 -2
app.py CHANGED
@@ -68,7 +68,65 @@ 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
  <script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  async function generateImage() {
73
  const prompt = document.getElementById("prompt").value;
74
  const negative_prompt = document.getElementById("negative_prompt").value;
@@ -111,6 +169,18 @@ index_html = """
111
  const img = document.getElementById("generated-image");
112
  img.src = reader.result; // dataURLを設定
113
  img.style.display = 'block'; // 画像を表示
 
 
 
 
 
 
 
 
 
 
 
 
114
  };
115
  reader.readAsDataURL(imageBlob);
116
  } catch (error) {
@@ -152,7 +222,7 @@ index_html = """
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" " 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>
@@ -187,7 +257,26 @@ index_html = """
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
 
 
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
+ <style>
72
+ #canvas {
73
+ position: absolute;
74
+ top: 0;
75
+ left: 0;
76
+ cursor: crosshair;
77
+ }
78
+ #container {
79
+ position: relative;
80
+ display: inline-block;
81
+ }
82
+ </style>
83
  <script>
84
+ let isDrawing = false;
85
+ let x = 0;
86
+ let y = 0;
87
+ let penSize = 5;
88
+ let penColor = '#000000';
89
+
90
+ function startDrawing(event) {
91
+ isDrawing = true;
92
+ [x, y] = getMousePos(event);
93
+ }
94
+
95
+ function draw(event) {
96
+ if (!isDrawing) return;
97
+
98
+ const canvas = document.getElementById('canvas');
99
+ const ctx = canvas.getContext('2d');
100
+ const [newX, newY] = getMousePos(event);
101
+
102
+ ctx.beginPath();
103
+ ctx.moveTo(x, y);
104
+ ctx.lineTo(newX, newY);
105
+ ctx.strokeStyle = penColor;
106
+ ctx.lineWidth = penSize;
107
+ ctx.stroke();
108
+ ctx.closePath();
109
+
110
+ [x, y] = [newX, newY];
111
+ }
112
+
113
+ function stopDrawing() {
114
+ isDrawing = false;
115
+ }
116
+
117
+ function getMousePos(event) {
118
+ const rect = document.getElementById('canvas').getBoundingClientRect();
119
+ return [event.clientX - rect.left, event.clientY - rect.top];
120
+ }
121
+
122
+ function setPenSize(value) {
123
+ penSize = value;
124
+ }
125
+
126
+ function setPenColor(value) {
127
+ penColor = value;
128
+ }
129
+
130
  async function generateImage() {
131
  const prompt = document.getElementById("prompt").value;
132
  const negative_prompt = document.getElementById("negative_prompt").value;
 
169
  const img = document.getElementById("generated-image");
170
  img.src = reader.result; // dataURLを設定
171
  img.style.display = 'block'; // 画像を表示
172
+
173
+ // 画像をキャンバスに描画
174
+ const canvas = document.getElementById('canvas');
175
+ const ctx = canvas.getContext('2d');
176
+ ctx.clearRect(0, 0, canvas.width, canvas.height); // キャンバスをクリア
177
+ const imgElement = new Image();
178
+ imgElement.src = reader.result;
179
+ imgElement.onload = function () {
180
+ canvas.width = imgElement.width;
181
+ canvas.height = imgElement.height;
182
+ ctx.drawImage(imgElement, 0, 0);
183
+ };
184
  };
185
  reader.readAsDataURL(imageBlob);
186
  } catch (error) {
 
222
  <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>
223
 
224
  <label for="width">Width:</label>
225
+ <input type="number" id="width" name="width" value="1024" min="64" max="2048" step="8" style="width:250px" oninput="syncWidth(this.value)">
226
  <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>
227
 
228
  <label for="height">Height:</label>
 
257
  <div id="error-message" style="color: red;"></div>
258
 
259
  <h2>Generated Image:</h2>
260
+ <div id="container">
261
+ <canvas id="canvas"></canvas>
262
+ <img id="generated-image" src="" alt="Generated Image" style="max-width: 100%; height: auto; display: none;">
263
+ </div>
264
+
265
+ <h3>Draw on the Image:</h3>
266
+ <label for="penSize">Pen Size:</label>
267
+ <input type="range" id="penSize" name="penSize" min="1" max="50" value="5" oninput="setPenSize(this.value)">
268
+
269
+ <label for="penColor">Pen Color:</label>
270
+ <input type="color" id="penColor" name="penColor" value="#000000" onchange="setPenColor(this.value)">
271
+
272
+ <script>
273
+ // Canvasイベントリスナーを設定
274
+ const canvas = document.getElementById('canvas');
275
+ canvas.addEventListener('mousedown', startDrawing);
276
+ canvas.addEventListener('mousemove', draw);
277
+ canvas.addEventListener('mouseup', stopDrawing);
278
+ canvas.addEventListener('mouseleave', stopDrawing);
279
+ </script>
280
  </body>
281
  </html>
282