nsfwalex commited on
Commit
c08a54f
1 Parent(s): d37c7ab

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -25
app.py CHANGED
@@ -142,6 +142,17 @@ window.postMessageToParent = function(prompt, event, source, value) {
142
  };
143
  if (!prompt){
144
  prompt = window.g();
 
 
 
 
 
 
 
 
 
 
 
145
  }
146
  // Post the message to the parent window
147
  window.parent.postMessage(message, '*');
@@ -213,29 +224,6 @@ def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
213
  seed = random.randint(0, MAX_SEED)
214
  return seed
215
 
216
-
217
-
218
- with gr.Blocks(css=css,head=js,fill_height=True) as demo:
219
- with gr.Row(equal_height=False):
220
- with gr.Group():
221
- gr.HTML(value=desc_html, elem_id='desc_html_code')
222
- result = gr.Gallery(
223
- label="Result", show_label=False, columns=1, rows=1, show_share_button=True,
224
- show_download_button=True,allow_preview=True,interactive=False, min_width=cfg.get("window_min_width", 340),height=360
225
- )
226
- with gr.Row():
227
- prompt = gr.Text(
228
- show_label=False,
229
- max_lines=2,
230
- lines=2,
231
- placeholder="Enter what you want to see",
232
- container=False,
233
- scale=5,
234
- min_width=100,
235
- )
236
- random_button = gr.Button("Surprise Me", scale=1, min_width=10)
237
- run_button = gr.Button( "GO!", scale=1, min_width=20, variant="primary",icon="https://huggingface.co/spaces/nsfwalex/sd_card/resolve/main/hot.svg")
238
-
239
  @spaces.GPU(duration=60)
240
  def generate(p, progress=gr.Progress(track_tqdm=True)):
241
  negative_prompt = cfg.get("negative_prompt", "")
@@ -248,8 +236,6 @@ with gr.Blocks(css=css,head=js,fill_height=True) as demo:
248
  randomize_seed = True
249
  guidance_scale = cfg.get("guidance_scale", 7.5)
250
  prompt_str = cfg.get("prompt", "{prompt}").replace("{prompt}", p)
251
- if not prompt.value:
252
- prompt.value = p
253
  seed = int(randomize_seed_fn(seed, randomize_seed))
254
  generator = torch.Generator(pipe.device).manual_seed(seed)
255
 
@@ -268,6 +254,28 @@ with gr.Blocks(css=css,head=js,fill_height=True) as demo:
268
  image_paths = [i[1] for i in images]
269
  print(prompt_str, image_paths)
270
  return [i[0] for i in images]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
271
 
272
  def on_demo_load(request: gr.Request):
273
  current_domain = request.request.headers.get("Host", "")
 
142
  };
143
  if (!prompt){
144
  prompt = window.g();
145
+
146
+ // Find the prompt input element
147
+ const promptContainer = document.getElementById('prompt_input_box');
148
+ if (promptContainer) {
149
+ const promptInput = promptContainer.querySelector('input') || promptContainer.querySelector('textarea');
150
+ if (promptInput) {
151
+ promptInput.value = prompt;
152
+ // Trigger an input event to ensure Gradio recognizes the change
153
+ promptInput.dispatchEvent(new Event('input', { bubbles: true }));
154
+ }
155
+ }
156
  }
157
  // Post the message to the parent window
158
  window.parent.postMessage(message, '*');
 
224
  seed = random.randint(0, MAX_SEED)
225
  return seed
226
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
227
  @spaces.GPU(duration=60)
228
  def generate(p, progress=gr.Progress(track_tqdm=True)):
229
  negative_prompt = cfg.get("negative_prompt", "")
 
236
  randomize_seed = True
237
  guidance_scale = cfg.get("guidance_scale", 7.5)
238
  prompt_str = cfg.get("prompt", "{prompt}").replace("{prompt}", p)
 
 
239
  seed = int(randomize_seed_fn(seed, randomize_seed))
240
  generator = torch.Generator(pipe.device).manual_seed(seed)
241
 
 
254
  image_paths = [i[1] for i in images]
255
  print(prompt_str, image_paths)
256
  return [i[0] for i in images]
257
+
258
+ with gr.Blocks(css=css,head=js,fill_height=True) as demo:
259
+ with gr.Row(equal_height=False):
260
+ with gr.Group():
261
+ gr.HTML(value=desc_html, elem_id='desc_html_code')
262
+ result = gr.Gallery(
263
+ label="Result", show_label=False, columns=1, rows=1, show_share_button=True,
264
+ show_download_button=True,allow_preview=True,interactive=False, min_width=cfg.get("window_min_width", 340),height=360
265
+ )
266
+ with gr.Row():
267
+ prompt = gr.Text(
268
+ show_label=False,
269
+ max_lines=2,
270
+ lines=2,
271
+ placeholder="Enter what you want to see",
272
+ container=False,
273
+ scale=5,
274
+ min_width=100,
275
+ elem_id="prompt_input_box"
276
+ )
277
+ random_button = gr.Button("Surprise Me", scale=1, min_width=10)
278
+ run_button = gr.Button( "GO!", scale=1, min_width=20, variant="primary",icon="https://huggingface.co/spaces/nsfwalex/sd_card/resolve/main/hot.svg")
279
 
280
  def on_demo_load(request: gr.Request):
281
  current_domain = request.request.headers.get("Host", "")