irebmann commited on
Commit
2912c27
·
verified ·
1 Parent(s): 98b524c

fixed errors

Browse files
Files changed (1) hide show
  1. app.py +27 -20
app.py CHANGED
@@ -21,6 +21,26 @@ model_ft = Swin2SRForImageSuperResolution.from_pretrained(FINETUNED_ID, local_f
21
  model_pre.eval()
22
  model_ft.eval()
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  # ---- Inference function ----
25
  def swin2sr_upscale(input_image: Image.Image, mode: str):
26
  """
@@ -29,7 +49,10 @@ def swin2sr_upscale(input_image: Image.Image, mode: str):
29
  """
30
  if input_image is None:
31
  return None
32
-
 
 
 
33
  if mode == "Smooth (fine-tuned)":
34
  model = model_ft
35
  processor = processor_ft
@@ -56,25 +79,9 @@ def swin2sr_upscale(input_image: Image.Image, mode: str):
56
  f"(scale factors: {w_sr / w_lr:.1f}×, {h_sr / h_lr:.1f}×)"
57
  )
58
 
59
- ABOUT_TEXT = """
60
- **About this tool**
61
-
62
- This is a free image enhancement tool that uses Swin2SR to reconstruct and refine image detail at the pixel level (“pixel refabrication”).
63
- I built it because many of my own photos are distorted or only exist as low‑quality copies on social media.
64
-
65
- **Tip for social media images**
66
-
67
- If your only copy is on Instagram, open Instagram on a computer, view the photo in full‑screen, take a screenshot, and crop it tightly around the image before uploading here.
68
-
69
- **Usage notes**
70
-
71
- Processing and queue times can occasionally exceed ten minutes, especially during heavy use.
72
- If this tool gets regular traffic, I plan to upgrade to a stronger GPU backend.
73
-
74
- Please reach out if you need any help or have questions.
75
- """
76
 
77
- return sr_image, msg, ABOUT_TEXT
78
 
79
  # ---- Gradio UI ----
80
  with gr.Blocks() as demo:
@@ -105,7 +112,7 @@ with gr.Blocks() as demo:
105
  run_btn.click(
106
  fn=swin2sr_upscale,
107
  inputs=[input_image, mode_dropdown],
108
- outputs=output_image,
109
  )
110
 
111
  if __name__ == "__main__":
 
21
  model_pre.eval()
22
  model_ft.eval()
23
 
24
+
25
+ ABOUT_TEXT = """
26
+ **About this tool**
27
+
28
+ This is a free image enhancement tool that uses Swin2SR to reconstruct and refine image detail at the pixel level (“pixel refabrication”).
29
+ I built it because many of my own photos are distorted or only exist as low‑quality copies on social media.
30
+
31
+ **Tip for social media images**
32
+
33
+ If your only copy is on Instagram, open Instagram on a computer, view the photo in full‑screen, take a screenshot, and crop it tightly around the image before uploading here.
34
+
35
+ **Usage notes**
36
+
37
+ Processing and queue times can occasionally exceed ten minutes, especially during heavy use.
38
+ If this tool gets regular traffic, I plan to upgrade to a stronger GPU backend.
39
+
40
+ Please reach out if you need any help or have questions.
41
+ """
42
+
43
+
44
  # ---- Inference function ----
45
  def swin2sr_upscale(input_image: Image.Image, mode: str):
46
  """
 
49
  """
50
  if input_image is None:
51
  return None
52
+
53
+ # original size
54
+ w_lr, h_lr = input_image.size
55
+
56
  if mode == "Smooth (fine-tuned)":
57
  model = model_ft
58
  processor = processor_ft
 
79
  f"(scale factors: {w_sr / w_lr:.1f}×, {h_sr / h_lr:.1f}×)"
80
  )
81
 
82
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
 
84
+ return sr_image, msg
85
 
86
  # ---- Gradio UI ----
87
  with gr.Blocks() as demo:
 
112
  run_btn.click(
113
  fn=swin2sr_upscale,
114
  inputs=[input_image, mode_dropdown],
115
+ outputs=[output_image, res_info]
116
  )
117
 
118
  if __name__ == "__main__":