Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,36 +1,33 @@
|
|
1 |
-
import os
|
2 |
import gradio as gr
|
3 |
import torch
|
4 |
-
from
|
5 |
-
from torchvision.transforms import ToTensor, ToPILImage
|
6 |
-
from torchvision import models
|
7 |
|
8 |
-
# Load the
|
9 |
-
model =
|
10 |
-
|
11 |
-
def upscale_image(image, scale_factor):
|
12 |
-
# Ensure image is in PIL format
|
13 |
-
if not isinstance(image, Image.Image):
|
14 |
-
image = Image.fromarray(image)
|
15 |
-
|
16 |
-
# Upscale using the model
|
17 |
-
with torch.no_grad():
|
18 |
-
upscaled_image = model(image, scale=scale_factor)
|
19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
return upscaled_image
|
21 |
|
22 |
-
# Create Gradio interface
|
23 |
iface = gr.Interface(
|
24 |
fn=upscale_image,
|
25 |
inputs=[
|
26 |
-
gr.inputs.Image(type="
|
27 |
-
gr.inputs.Slider(minimum=
|
28 |
],
|
29 |
-
outputs=gr.outputs.Image(type="
|
30 |
-
title="R-ESRGAN Anime 6B
|
31 |
-
description="Upload an image and select a scale factor to upscale
|
32 |
)
|
33 |
|
34 |
-
# Launch the
|
35 |
-
|
36 |
-
iface.launch()
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
+
from realesrgan import RealESRGAN
|
|
|
|
|
4 |
|
5 |
+
# Load the model
|
6 |
+
model = RealESRGAN('weights/RealESRGAN_x4plus_anime_6B.pth', scale=4) # Adjust scale if needed
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
+
def upscale_image(input_image, scale_factor):
|
9 |
+
# Ensure scale factor is an integer
|
10 |
+
scale_factor = int(scale_factor)
|
11 |
+
|
12 |
+
# Set the model scale
|
13 |
+
model.scale = scale_factor
|
14 |
+
|
15 |
+
# Perform the upscaling
|
16 |
+
upscaled_image = model.predict(input_image)
|
17 |
+
|
18 |
return upscaled_image
|
19 |
|
20 |
+
# Create the Gradio interface
|
21 |
iface = gr.Interface(
|
22 |
fn=upscale_image,
|
23 |
inputs=[
|
24 |
+
gr.inputs.Image(type="numpy", label="Input Image"),
|
25 |
+
gr.inputs.Slider(minimum=2, maximum=4, step=1, default=4, label="Scale Factor")
|
26 |
],
|
27 |
+
outputs=gr.outputs.Image(type="numpy", label="Upscaled Image"),
|
28 |
+
title="Image Upscaler using R-ESRGAN Anime 6B",
|
29 |
+
description="Upload an image and select a scale factor to upscale it using the R-ESRGAN Anime 6B model."
|
30 |
)
|
31 |
|
32 |
+
# Launch the app
|
33 |
+
iface.launch()
|
|