jiuface commited on
Commit
d718ec3
1 Parent(s): 6d9ca04

add image from url

Browse files
Files changed (2) hide show
  1. app.py +36 -2
  2. requirements.txt +2 -1
app.py CHANGED
@@ -16,7 +16,10 @@ from gradio_imageslider import ImageSlider
16
  from diffusers import FlowMatchEulerDiscreteScheduler, AutoencoderKL
17
  from diffusers.models.transformers.transformer_flux import FluxTransformer2DModel
18
  from transformers import CLIPTextModel, CLIPTokenizer,T5EncoderModel, T5TokenizerFast
19
-
 
 
 
20
 
21
  MARKDOWN = """
22
  # FLUX.1 Inpainting with lora
@@ -107,6 +110,8 @@ def resize_image_dimensions(
107
  @spaces.GPU(duration=100)
108
  def process(
109
  input_image_editor: dict,
 
 
110
  lora_path: str,
111
  lora_weights: str,
112
  lora_scale: float,
@@ -122,9 +127,24 @@ def process(
122
  gr.Info("Please enter a text prompt.")
123
  return None, None
124
 
 
125
  image = input_image_editor['background']
126
  mask = input_image_editor['layers'][0]
127
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
  if not image:
129
  gr.Info("Please upload an image.")
130
  return None, None
@@ -173,7 +193,19 @@ with gr.Blocks() as demo:
173
  image_mode='RGB',
174
  layers=False,
175
  brush=gr.Brush(colors=["#FFFFFF"], color_mode="fixed"))
176
-
 
 
 
 
 
 
 
 
 
 
 
 
177
 
178
  with gr.Accordion("Prompt Settings", open=True):
179
 
@@ -266,6 +298,8 @@ with gr.Blocks() as demo:
266
  fn=process,
267
  inputs=[
268
  input_image_editor_component,
 
 
269
  lora_path,
270
  lora_weights,
271
  lora_scale,
 
16
  from diffusers import FlowMatchEulerDiscreteScheduler, AutoencoderKL
17
  from diffusers.models.transformers.transformer_flux import FluxTransformer2DModel
18
  from transformers import CLIPTextModel, CLIPTokenizer,T5EncoderModel, T5TokenizerFast
19
+ import requests
20
+ from io import BytesIO
21
+ import PIL.Image
22
+ import requests
23
 
24
  MARKDOWN = """
25
  # FLUX.1 Inpainting with lora
 
110
  @spaces.GPU(duration=100)
111
  def process(
112
  input_image_editor: dict,
113
+ image_url: str,
114
+ mask_url: str,
115
  lora_path: str,
116
  lora_weights: str,
117
  lora_scale: float,
 
127
  gr.Info("Please enter a text prompt.")
128
  return None, None
129
 
130
+ # default image edtiro
131
  image = input_image_editor['background']
132
  mask = input_image_editor['layers'][0]
133
 
134
+ if image_url:
135
+ print("start to fetch image from url", image_url)
136
+ response = requests.get(image_url)
137
+ response.raise_for_status()
138
+ image = PIL.Image.open(BytesIO(response.content))
139
+ print("fetch image success")
140
+
141
+ if mask_url:
142
+ print("start to fetch mask from url", mask_url)
143
+ response = requests.get(mask_url)
144
+ response.raise_for_status()
145
+ mask = PIL.Image.open(BytesIO(response.content))
146
+ print("fetch mask success")
147
+
148
  if not image:
149
  gr.Info("Please upload an image.")
150
  return None, None
 
193
  image_mode='RGB',
194
  layers=False,
195
  brush=gr.Brush(colors=["#FFFFFF"], color_mode="fixed"))
196
+
197
+ image_url = gr.Textbox(
198
+ label="image url",
199
+ show_label=True,
200
+ max_lines=1,
201
+ placeholder="Enter your image url (Optional)",
202
+ )
203
+ mask_url = gr.Textbox(
204
+ label="Mask image url",
205
+ show_label=True,
206
+ max_lines=1,
207
+ placeholder="Enter your mask image url (Optional)",
208
+ )
209
 
210
  with gr.Accordion("Prompt Settings", open=True):
211
 
 
298
  fn=process,
299
  inputs=[
300
  input_image_editor_component,
301
+ image_url,
302
+ mask_url,
303
  lora_path,
304
  lora_weights,
305
  lora_scale,
requirements.txt CHANGED
@@ -6,4 +6,5 @@ sentencepiece
6
  git+https://github.com/Gothos/diffusers.git@flux-inpaint
7
  huggingface_hub
8
  peft
9
- gradio_imageslider
 
 
6
  git+https://github.com/Gothos/diffusers.git@flux-inpaint
7
  huggingface_hub
8
  peft
9
+ gradio_imageslider
10
+ requests