Profakerr commited on
Commit
acdd956
·
verified ·
1 Parent(s): d698fe3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -35
app.py CHANGED
@@ -2,7 +2,6 @@ import torch
2
  from PIL import Image
3
  from RealESRGAN import RealESRGAN
4
  import gradio as gr
5
- from gradio_imageslider import ImageSlider
6
  import spaces
7
 
8
  device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
@@ -13,7 +12,6 @@ model4.load_weights('weights/RealESRGAN_x4.pth', download=True)
13
  model8 = RealESRGAN(device, scale=8)
14
  model8.load_weights('weights/RealESRGAN_x8.pth', download=True)
15
 
16
-
17
  @spaces.GPU
18
  def inference(image, size):
19
  global model2
@@ -22,8 +20,6 @@ def inference(image, size):
22
  if image is None:
23
  raise gr.Error("Image not uploaded")
24
 
25
- # Store original image for comparison
26
- original_image = image.copy()
27
 
28
  if torch.cuda.is_available():
29
  torch.cuda.empty_cache()
@@ -47,7 +43,7 @@ def inference(image, size):
47
  else:
48
  try:
49
  width, height = image.size
50
- if width >= 5000 or height >= 5000:
51
  raise gr.Error("The image is too large.")
52
  result = model8.predict(image.convert('RGB'))
53
  except torch.cuda.OutOfMemoryError as e:
@@ -57,36 +53,21 @@ def inference(image, size):
57
  result = model2.predict(image.convert('RGB'))
58
 
59
  print(f"Image size ({device}): {size} ... OK")
60
- # Return tuple of original and processed images for the slider
61
- return (original_image, result)
62
-
63
 
64
- title = """<h1 align="center">ProFaker</h1>"""
65
 
66
- with gr.Blocks() as demo:
67
- gr.HTML(title)
68
-
69
- with gr.Row():
70
- with gr.Column():
71
- input_image = gr.Image(type="pil", label="Input Image")
72
- size_select = gr.Radio(
73
- ["2x", "4x", "8x"],
74
- type="value",
75
- value="2x",
76
- label="Resolution model"
77
- )
78
- process_btn = gr.Button("Upscale Image")
79
-
80
- with gr.Column():
81
- result_slider = ImageSlider(
82
- interactive=False,
83
- label="Before and After Comparison"
84
- )
85
-
86
- process_btn.click(
87
- fn=inference,
88
- inputs=[input_image, size_select],
89
- outputs=result_slider
90
- )
91
 
92
- demo.queue(api_open=True).launch(show_error=True, show_api=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  from PIL import Image
3
  from RealESRGAN import RealESRGAN
4
  import gradio as gr
 
5
  import spaces
6
 
7
  device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
 
12
  model8 = RealESRGAN(device, scale=8)
13
  model8.load_weights('weights/RealESRGAN_x8.pth', download=True)
14
 
 
15
  @spaces.GPU
16
  def inference(image, size):
17
  global model2
 
20
  if image is None:
21
  raise gr.Error("Image not uploaded")
22
 
 
 
23
 
24
  if torch.cuda.is_available():
25
  torch.cuda.empty_cache()
 
43
  else:
44
  try:
45
  width, height = image.size
46
+ if width >= 6000 or height >= 6000:
47
  raise gr.Error("The image is too large.")
48
  result = model8.predict(image.convert('RGB'))
49
  except torch.cuda.OutOfMemoryError as e:
 
53
  result = model2.predict(image.convert('RGB'))
54
 
55
  print(f"Image size ({device}): {size} ... OK")
56
+ return result
 
 
57
 
 
58
 
59
+ title = "ProFaker"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
 
61
+ gr.Interface(inference,
62
+ [gr.Image(type="pil"),
63
+ gr.Radio(["2x", "4x", "8x"],
64
+ type="value",
65
+ value="2x",
66
+ label="Resolution model")],
67
+ gr.Image(type="pil", label="Output"),
68
+ title=title,
69
+ flagging_mode="never",
70
+ cache_mode="lazy",
71
+ delete_cache=(44000, 44000),
72
+ ).queue(api_open=True).launch(show_error=True, show_api=True)
73
+