mlnotes commited on
Commit
3c3573c
·
1 Parent(s): 697bbe5

FIX loading super resolution repo

Browse files
Files changed (1) hide show
  1. app.py +20 -3
app.py CHANGED
@@ -1,4 +1,20 @@
1
  # %%
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  import gradio as gr
3
 
4
  example_generated_ape_super = "examples/generated_ape_super_resolution.jpg"
@@ -13,7 +29,8 @@ examples = [
13
  ]
14
 
15
  ape_gen = gr.Interface.load("spaces/ykilcher/apes")
16
- super_resolution = gr.Interface.load("spaces/akhaliq/SwinIR")
 
17
  style_transfer = gr.Interface.load("spaces/aravinds1811/neural-style-transfer")
18
 
19
  def generate_ape(num_images=1, interpolate=False):
@@ -28,12 +45,12 @@ def perform_style_transfer(content_image, style_image, is_super_resolution=False
28
  # %%
29
  with gr.Blocks() as demo:
30
  button_generate_ape = gr.Button("Generate Ape")
31
-
32
  generated_ape = gr.Image(example_generated_ape, label="Generated Ape", type="filepath")
33
  style_image_input = gr.Image(example_style_starry_night, label="Stylish Image", type="filepath")
34
  style_in_super_resolution = gr.Checkbox(True, label="Super resolution!")
35
  stylish_ape = gr.Image(example_stylish_ape, label="Stylish Ape")
36
-
37
  gr.Interface(
38
  fn=perform_style_transfer,
39
  inputs=[generated_ape, style_image_input, style_in_super_resolution],
 
1
  # %%
2
+ import os
3
+
4
+ from PIL import Image
5
+
6
+ os.system('wget https://github.com/JingyunLiang/SwinIR/releases/download/v0.0/003_realSR_BSRGAN_DFO_s64w8_SwinIR-M_x4_GAN.pth -P experiments/pretrained_models')
7
+
8
+ def super_resolution_inference(img):
9
+ os.system('mkdir test')
10
+ basewidth = 256
11
+ wpercent = (basewidth/float(img.size[0]))
12
+ hsize = int((float(img.size[1])*float(wpercent)))
13
+ img = img.resize((basewidth,hsize), Image.ANTIALIAS)
14
+ img.save("test/1.jpg", "JPEG")
15
+ os.system('python main_test_swinir.py --task real_sr --model_path experiments/pretrained_models/003_realSR_BSRGAN_DFO_s64w8_SwinIR-M_x4_GAN.pth --folder_lq test --scale 4')
16
+ return 'results/swinir_real_sr_x4/1_SwinIR.png'
17
+ # %%
18
  import gradio as gr
19
 
20
  example_generated_ape_super = "examples/generated_ape_super_resolution.jpg"
 
29
  ]
30
 
31
  ape_gen = gr.Interface.load("spaces/ykilcher/apes")
32
+ # super_resolution = gr.Interface.load("spaces/akhaliq/SwinIR")
33
+ super_resolution = super_resolution_inference
34
  style_transfer = gr.Interface.load("spaces/aravinds1811/neural-style-transfer")
35
 
36
  def generate_ape(num_images=1, interpolate=False):
 
45
  # %%
46
  with gr.Blocks() as demo:
47
  button_generate_ape = gr.Button("Generate Ape")
48
+
49
  generated_ape = gr.Image(example_generated_ape, label="Generated Ape", type="filepath")
50
  style_image_input = gr.Image(example_style_starry_night, label="Stylish Image", type="filepath")
51
  style_in_super_resolution = gr.Checkbox(True, label="Super resolution!")
52
  stylish_ape = gr.Image(example_stylish_ape, label="Stylish Ape")
53
+
54
  gr.Interface(
55
  fn=perform_style_transfer,
56
  inputs=[generated_ape, style_image_input, style_in_super_resolution],