jpjp9292 commited on
Commit
f3b13b5
โ€ข
1 Parent(s): a78ac24

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -11
app.py CHANGED
@@ -3,20 +3,14 @@ import cv2
3
  import numpy as np
4
 
5
  # ์ด๋ฏธ์ง€ ์—…์Šค์ผ€์ผ ํ•จ์ˆ˜
6
- def upscale_image(input_image, radio_input):
7
- upscale_factor = int(radio_input) # ์—…์Šค์ผ€์ผ ๋น„์œจ์„ ์ •์ˆ˜ํ˜•์œผ๋กœ ๋ณ€ํ™˜
8
- # ์ž…๋ ฅ ์ด๋ฏธ์ง€๋ฅผ ์ฃผ์–ด์ง„ ์—…์Šค์ผ€์ผ ๋น„์œจ๋กœ ํฌ๊ธฐ ๋ณ€๊ฒฝ (๋ณด๊ฐ„๋ฒ•: INTER_CUBIC)
9
- output_image = cv2.resize(input_image, None, fx=upscale_factor, fy=upscale_factor, interpolation=cv2.INTER_CUBIC)
10
- return output_image
11
-
12
- # ์—…์Šค์ผ€์ผ ์ด๋ฏธ์ง€๋ฅผ PNG๋กœ ์ €์žฅํ•˜๋Š” ํ•จ์ˆ˜
13
- def save_image_as_png(input_image, radio_input):
14
- upscale_factor = int(radio_input) # ์—…์Šค์ผ€์ผ ๋น„์œจ์„ ์ •์ˆ˜ํ˜•์œผ๋กœ ๋ณ€ํ™˜
15
  # ์ž…๋ ฅ ์ด๋ฏธ์ง€๋ฅผ ์ฃผ์–ด์ง„ ์—…์Šค์ผ€์ผ ๋น„์œจ๋กœ ํฌ๊ธฐ ๋ณ€๊ฒฝ (๋ณด๊ฐ„๋ฒ•: INTER_CUBIC)
16
  output_image = cv2.resize(input_image, None, fx=upscale_factor, fy=upscale_factor, interpolation=cv2.INTER_CUBIC)
17
  # ์ด๋ฏธ์ง€๋ฅผ PNG ํ˜•์‹์œผ๋กœ ์ €์žฅ
 
18
  output_filename = "upscaled_image.png"
19
- cv2.imwrite(output_filename, output_image)
20
  return output_filename
21
 
22
  # ์ธํ„ฐํŽ˜์ด์Šค ์„ค๋ช…
@@ -29,7 +23,7 @@ radio_input = gr.Radio(label="์—…์Šค์ผ€์ผ ๋ ˆ๋ฒจ ์„ ํƒ (Select Upscaling level
29
 
30
  # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ •์˜
31
  demo = gr.Interface(
32
- fn=save_image_as_png,
33
  inputs=[gr.Image(label="์ž…๋ ฅ ์ด๋ฏธ์ง€ (Input Image)", type="numpy"), radio_input],
34
  outputs=gr.File(label="์—…์Šค์ผ€์ผ๋œ ์ด๋ฏธ์ง€ ๋‹ค์šด๋กœ๋“œ (Download Upscaled Image)"),
35
  title="Image Upscaler",
 
3
  import numpy as np
4
 
5
  # ์ด๋ฏธ์ง€ ์—…์Šค์ผ€์ผ ํ•จ์ˆ˜
6
+ def upscale_image(input_image, upscale_factor):
7
+ upscale_factor = int(upscale_factor) # ์—…์Šค์ผ€์ผ ๋น„์œจ์„ ์ •์ˆ˜ํ˜•์œผ๋กœ ๋ณ€ํ™˜
 
 
 
 
 
 
 
8
  # ์ž…๋ ฅ ์ด๋ฏธ์ง€๋ฅผ ์ฃผ์–ด์ง„ ์—…์Šค์ผ€์ผ ๋น„์œจ๋กœ ํฌ๊ธฐ ๋ณ€๊ฒฝ (๋ณด๊ฐ„๋ฒ•: INTER_CUBIC)
9
  output_image = cv2.resize(input_image, None, fx=upscale_factor, fy=upscale_factor, interpolation=cv2.INTER_CUBIC)
10
  # ์ด๋ฏธ์ง€๋ฅผ PNG ํ˜•์‹์œผ๋กœ ์ €์žฅ
11
+ output_image_bgr = cv2.cvtColor(output_image, cv2.COLOR_RGB2BGR) # RGB์—์„œ BGR๋กœ ๋ณ€ํ™˜
12
  output_filename = "upscaled_image.png"
13
+ cv2.imwrite(output_filename, output_image_bgr)
14
  return output_filename
15
 
16
  # ์ธํ„ฐํŽ˜์ด์Šค ์„ค๋ช…
 
23
 
24
  # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ •์˜
25
  demo = gr.Interface(
26
+ fn=upscale_image,
27
  inputs=[gr.Image(label="์ž…๋ ฅ ์ด๋ฏธ์ง€ (Input Image)", type="numpy"), radio_input],
28
  outputs=gr.File(label="์—…์Šค์ผ€์ผ๋œ ์ด๋ฏธ์ง€ ๋‹ค์šด๋กœ๋“œ (Download Upscaled Image)"),
29
  title="Image Upscaler",