myn0908 commited on
Commit
5044478
1 Parent(s): e2053b7

replace upload image by url input

Browse files
Files changed (2) hide show
  1. S2I/modules/utils.py +1 -2
  2. app.py +39 -17
S2I/modules/utils.py CHANGED
@@ -85,8 +85,7 @@ def get_s2i_home() -> str:
85
  def download_models():
86
  urls = {
87
  '350k-adapter': 'https://huggingface.co/myn0908/sk2ks/resolve/main/adapter_weights_large_sketch2image_lora.pkl?download=true',
88
- '350k': 'https://huggingface.co/myn0908/sk2ks/resolve/main/sketch_to_image_mixed_weights_350k_lora.pkl?download=true',
89
- '100k': 'https://huggingface.co/myn0908/sk2ks/resolve/main/model_16001.pkl?download=true',
90
  }
91
  # Get the current working directory
92
  home = get_s2i_home()
 
85
  def download_models():
86
  urls = {
87
  '350k-adapter': 'https://huggingface.co/myn0908/sk2ks/resolve/main/adapter_weights_large_sketch2image_lora.pkl?download=true',
88
+ '350k': 'https://huggingface.co/myn0908/sk2ks/resolve/main/sketch_to_image_mixed_weights_350k_lora.pkl?download=true'
 
89
  }
90
  # Get the current working directory
91
  home = get_s2i_home()
app.py CHANGED
@@ -82,11 +82,10 @@ def convert_to_pencil_sketch(image):
82
  def get_meta_from_image(input_img, type_image):
83
  if input_img is None:
84
  return gr.update(value=None)
 
 
85
 
86
- file_content, _ = read_temp_file(input_img)
87
-
88
  # Read the image using Pillow
89
- img = Image.open(io.BytesIO(file_content)).convert("RGB")
90
  img_np = np.array(img)
91
 
92
  if type_image == 'RGB':
@@ -97,10 +96,32 @@ def get_meta_from_image(input_img, type_image):
97
 
98
  # Convert the processed image back to PIL Image
99
  img_pil = Image.fromarray(processed_img.astype('uint8'))
100
-
101
  return img_pil
102
 
103
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
 
105
  with gr.Blocks(css=css, theme="NoCrypt/miku@1.2.1") as demo:
106
  gr.HTML(
@@ -200,7 +221,8 @@ with gr.Blocks(css=css, theme="NoCrypt/miku@1.2.1") as demo:
200
  canvas_size=(1024, 1024),
201
  layers=False
202
  )
203
- input_image = gr.File(label='Input image')
 
204
 
205
  download_sketch = gr.Button(
206
  "Download sketch", scale=1, elem_id="download_sketch"
@@ -263,8 +285,8 @@ with gr.Blocks(css=css, theme="NoCrypt/miku@1.2.1") as demo:
263
  label="Demo Speed",
264
  interactive=True)
265
  model_options = gr.Radio(
266
- choices=["100k", "350k", "350k-adapter"],
267
- value="350k",
268
  label="Type Sketch2Image models",
269
  interactive=True)
270
 
@@ -291,15 +313,15 @@ with gr.Blocks(css=css, theme="NoCrypt/miku@1.2.1") as demo:
291
  outputs = [result, download_sketch]
292
  prompt.submit(fn=assign_gpu, inputs=inputs, outputs=outputs, api_name=False)
293
 
294
- input_image.change(
295
- fn=get_meta_from_image,
296
- inputs=[
297
- input_image, type_image
298
- ],
299
- outputs=[
300
- image
301
- ]
302
- )
303
 
304
  style.change(
305
  lambda x: controller.styles[x],
@@ -322,7 +344,7 @@ with gr.Blocks(css=css, theme="NoCrypt/miku@1.2.1") as demo:
322
  val_r.change(assign_gpu, inputs=inputs, outputs=outputs, queue=False, api_name=False)
323
  run_button.click(fn=assign_gpu, inputs=inputs, outputs=outputs, api_name=False)
324
  image.change(assign_gpu, inputs=inputs, outputs=outputs, queue=False, api_name=False)
325
-
326
  if __name__ == '__main__':
327
  demo.queue()
328
  demo.launch(debug=True, share=False)
 
82
  def get_meta_from_image(input_img, type_image):
83
  if input_img is None:
84
  return gr.update(value=None)
85
+
86
+ img = Image.open(BytesIO(requests.get(input_img).content)).convert('RGB')
87
 
 
 
88
  # Read the image using Pillow
 
89
  img_np = np.array(img)
90
 
91
  if type_image == 'RGB':
 
96
 
97
  # Convert the processed image back to PIL Image
98
  img_pil = Image.fromarray(processed_img.astype('uint8'))
99
+
100
  return img_pil
101
 
102
 
103
+ # def get_meta_from_image(input_img, type_image):
104
+ # if input_img is None:
105
+ # return gr.update(value=None)
106
+
107
+ # file_content, _ = read_temp_file(input_img)
108
+
109
+ # # Read the image using Pillow
110
+ # img = Image.open(io.BytesIO(file_content)).convert("RGB")
111
+ # img_np = np.array(img)
112
+
113
+ # if type_image == 'RGB':
114
+ # sketch = convert_to_pencil_sketch(img_np)
115
+ # processed_img = 255 - sketch
116
+ # elif type_image == 'SKETCH':
117
+ # processed_img = 255 - img_np
118
+
119
+ # # Convert the processed image back to PIL Image
120
+ # img_pil = Image.fromarray(processed_img.astype('uint8'))
121
+
122
+ # return img_pil
123
+
124
+
125
 
126
  with gr.Blocks(css=css, theme="NoCrypt/miku@1.2.1") as demo:
127
  gr.HTML(
 
221
  canvas_size=(1024, 1024),
222
  layers=False
223
  )
224
+ # input_image = gr.File(label='Input image')
225
+ url_image = gr.Textbox(label="Image URLS", value="")
226
 
227
  download_sketch = gr.Button(
228
  "Download sketch", scale=1, elem_id="download_sketch"
 
285
  label="Demo Speed",
286
  interactive=True)
287
  model_options = gr.Radio(
288
+ choices=["350k", "350k-adapter"],
289
+ value="350k-adapter",
290
  label="Type Sketch2Image models",
291
  interactive=True)
292
 
 
313
  outputs = [result, download_sketch]
314
  prompt.submit(fn=assign_gpu, inputs=inputs, outputs=outputs, api_name=False)
315
 
316
+ # input_image.change(
317
+ # fn=get_meta_from_image,
318
+ # inputs=[
319
+ # input_image, type_image
320
+ # ],
321
+ # outputs=[
322
+ # image
323
+ # ]
324
+ # )
325
 
326
  style.change(
327
  lambda x: controller.styles[x],
 
344
  val_r.change(assign_gpu, inputs=inputs, outputs=outputs, queue=False, api_name=False)
345
  run_button.click(fn=assign_gpu, inputs=inputs, outputs=outputs, api_name=False)
346
  image.change(assign_gpu, inputs=inputs, outputs=outputs, queue=False, api_name=False)
347
+ url_image.submit(fn=get_meta_from_image, inputs=[url_image, type_image], outputs=[image])
348
  if __name__ == '__main__':
349
  demo.queue()
350
  demo.launch(debug=True, share=False)