Yaron Koresh commited on
Commit
c009b83
·
verified ·
1 Parent(s): 03241e9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -34
app.py CHANGED
@@ -21,17 +21,16 @@ from diffusers.utils import load_image
21
  #import jax
22
  #import jax.numpy as jnp
23
 
24
- os.environ["GRADIO_SERVER_PORT"]="7860"
25
-
26
  def port_inc():
27
- os.environ["GRADIO_SERVER_PORT"]=str(int(os.getenv("GRADIO_SERVER_PORT"))+1)
 
 
 
 
28
 
29
  def init_pool():
30
  port_inc()
31
 
32
- _dynamo.config.suppress_errors = True
33
- mp.set_start_method("spawn", force=True)
34
-
35
  #pipe = DiffusionPipeline.from_pretrained("black-forest-labs/FLUX.1-schnell", torch_dtype=torch.bfloat16, token=os.getenv("hf_token")).to(device)
36
  #pipe2 = StableDiffusionXLImg2ImgPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0", torch_dtype=torch.float16, variant="fp16", use_safetensors=True).to(device)
37
  #pipe2.unet = torch.compile(pipe2.unet, mode="reduce-overhead", fullgraph=True)
@@ -209,32 +208,38 @@ function custom(){
209
  }
210
  """
211
 
212
- with gr.Blocks(theme=gr.themes.Soft(),css=css,js=js) as demo:
 
 
 
 
213
  result = []
214
- with gr.Column(elem_id="col-container"):
215
- gr.Markdown(f"""
216
- # MULTI-LANGUAGE IMAGE GENERATOR
217
- """)
218
- with gr.Row():
219
- prompt = gr.Textbox(
220
- elem_id="prompt",
221
- placeholder="INCLUDE",
222
- container=False,
223
- max_lines=1
224
- )
225
- with gr.Row():
226
- prompt2 = gr.Textbox(
227
- elem_id="prompt2",
228
- placeholder="EXCLUDE",
229
- container=False,
230
- max_lines=1
231
- )
232
- with gr.Row():
233
- run_button = gr.Button("START",elem_classes="btn",scale=0)
234
- with gr.Row():
235
- result.append(gr.Image(interactive=False,elem_classes="image-container", label="Result", show_label=False, type='filepath', show_share_button=False))
236
- result.append(gr.Image(interactive=False,elem_classes="image-container", label="Result", show_label=False, type='filepath', show_share_button=False))
237
- result.append(gr.Image(interactive=False,elem_classes="image-container", label="Result", show_label=False, type='filepath', show_share_button=False))
238
-
239
- run_button.click(fn=main,inputs=[prompt,prompt2],outputs=result)
240
- demo.queue().launch()
 
 
 
21
  #import jax
22
  #import jax.numpy as jnp
23
 
 
 
24
  def port_inc():
25
+ env = os.getenv("CUSTOM_PORT")
26
+ if env == None:
27
+ os.environ["CUSTOM_PORT"]="8000"
28
+ else:
29
+ os.environ["CUSTOM_PORT"]=str(int(env)+1)
30
 
31
  def init_pool():
32
  port_inc()
33
 
 
 
 
34
  #pipe = DiffusionPipeline.from_pretrained("black-forest-labs/FLUX.1-schnell", torch_dtype=torch.bfloat16, token=os.getenv("hf_token")).to(device)
35
  #pipe2 = StableDiffusionXLImg2ImgPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0", torch_dtype=torch.float16, variant="fp16", use_safetensors=True).to(device)
36
  #pipe2.unet = torch.compile(pipe2.unet, mode="reduce-overhead", fullgraph=True)
 
208
  }
209
  """
210
 
211
+ if __name__ == "__main__":
212
+
213
+ port_inc()
214
+ _dynamo.config.suppress_errors = True
215
+ mp.set_start_method("spawn", force=True)
216
  result = []
217
+
218
+ with gr.Blocks(theme=gr.themes.Soft(),css=css,js=js) as demo:
219
+ with gr.Column(elem_id="col-container"):
220
+ gr.Markdown(f"""
221
+ # MULTI-LANGUAGE IMAGE GENERATOR
222
+ """)
223
+ with gr.Row():
224
+ prompt = gr.Textbox(
225
+ elem_id="prompt",
226
+ placeholder="INCLUDE",
227
+ container=False,
228
+ max_lines=1
229
+ )
230
+ with gr.Row():
231
+ prompt2 = gr.Textbox(
232
+ elem_id="prompt2",
233
+ placeholder="EXCLUDE",
234
+ container=False,
235
+ max_lines=1
236
+ )
237
+ with gr.Row():
238
+ run_button = gr.Button("START",elem_classes="btn",scale=0)
239
+ with gr.Row():
240
+ result.append(gr.Image(interactive=False,elem_classes="image-container", label="Result", show_label=False, type='filepath', show_share_button=False))
241
+ result.append(gr.Image(interactive=False,elem_classes="image-container", label="Result", show_label=False, type='filepath', show_share_button=False))
242
+ result.append(gr.Image(interactive=False,elem_classes="image-container", label="Result", show_label=False, type='filepath', show_share_button=False))
243
+
244
+ run_button.click(fn=main,inputs=[prompt,prompt2],outputs=result)
245
+ demo.queue().launch(server_port=os.getenv("CUSTOM_PORT"))