nsfwalex commited on
Commit
a455f3b
1 Parent(s): 065e315

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -5
app.py CHANGED
@@ -279,7 +279,7 @@ with gr.Blocks(css=css,head=js,fill_height=True) as demo:
279
  with gr.Group():
280
  gr.HTML(value=desc_html, elem_id='desc_html_code')
281
  result = gr.Gallery(
282
- label="Result", show_label=False, columns=1, rows=1, show_share_button=True,
283
  show_download_button=True,allow_preview=False,interactive=False, min_width=cfg.get("window_min_width", 340),height=360
284
  )
285
  with gr.Row():
@@ -328,16 +328,24 @@ with gr.Blocks(css=css,head=js,fill_height=True) as demo:
328
  else:
329
  default_image = None
330
  print(f"load_demo, urlparams={params},cover={default_image},domain={current_domain},iframe={iframe_parent_domain}")
 
 
 
 
 
 
331
  if params.get("e", "0") == "1" or "nsfwais.io" in current_domain or "nsfwais.io" in iframe_parent_domain or "127.0.0.1" in current_domain or "127.0.0.1" in iframe_parent_domain:
332
  #update the image
333
  #bind events
334
- return [Image.open(default_image)]
335
- return []
336
-
337
 
 
 
 
 
338
  result.change(fn=lambda x,y:None , inputs=[prompt,result], outputs=[], js=f'''(p,img)=>window.uploadImage(p, img,"process_finished","demo_hf_{cfg.get("name")}_card", "{cfg["model_id"]}")''')
339
  run_button.click(generate, inputs=[prompt], outputs=[result],trigger_mode="once",js=f'''(p)=>window.postMessageToParent(p,"process_started","demo_hf_{cfg.get("name")}_card", "click_go")''')
340
  random_button.click(fn=lambda x:x, inputs=[prompt], outputs=[prompt], js='''(p)=>window.g(p)''')
341
- demo.load(fn=on_demo_load, inputs=[], outputs=[result], js='''()=>onDemoLoad()''')
342
  if __name__ == "__main__":
343
  demo.queue(max_size=100).launch(show_api=False,show_error=False)
 
279
  with gr.Group():
280
  gr.HTML(value=desc_html, elem_id='desc_html_code')
281
  result = gr.Gallery(
282
+ label="Result", show_label=False, columns=1, rows=1, show_share_button=True,elem_id=cfg["model_id"].replace("/", "-"),
283
  show_download_button=True,allow_preview=False,interactive=False, min_width=cfg.get("window_min_width", 340),height=360
284
  )
285
  with gr.Row():
 
328
  else:
329
  default_image = None
330
  print(f"load_demo, urlparams={params},cover={default_image},domain={current_domain},iframe={iframe_parent_domain}")
331
+ session_data = {
332
+ "params": params,
333
+ "client_ip": request.client.host,
334
+ "refer": referer,
335
+ "host": current_domain
336
+ }
337
  if params.get("e", "0") == "1" or "nsfwais.io" in current_domain or "nsfwais.io" in iframe_parent_domain or "127.0.0.1" in current_domain or "127.0.0.1" in iframe_parent_domain:
338
  #update the image
339
  #bind events
340
+ return [Image.open(default_image)], session_data
 
 
341
 
342
+
343
+ return [], session_data
344
+
345
+ session_state = gr.State()
346
  result.change(fn=lambda x,y:None , inputs=[prompt,result], outputs=[], js=f'''(p,img)=>window.uploadImage(p, img,"process_finished","demo_hf_{cfg.get("name")}_card", "{cfg["model_id"]}")''')
347
  run_button.click(generate, inputs=[prompt], outputs=[result],trigger_mode="once",js=f'''(p)=>window.postMessageToParent(p,"process_started","demo_hf_{cfg.get("name")}_card", "click_go")''')
348
  random_button.click(fn=lambda x:x, inputs=[prompt], outputs=[prompt], js='''(p)=>window.g(p)''')
349
+ demo.load(fn=on_demo_load, inputs=[], outputs=[result, session_state], js='''()=>onDemoLoad()''')
350
  if __name__ == "__main__":
351
  demo.queue(max_size=100).launch(show_api=False,show_error=False)