Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,37 +2,63 @@
|
|
2 |
|
3 |
# gr.Interface.load("models/Akbartus/Lora360").launch(show_api=True)
|
4 |
|
5 |
-
import
|
6 |
-
import
|
|
|
7 |
from PIL import Image
|
8 |
-
from
|
9 |
-
from
|
|
|
10 |
|
11 |
# Load the original model
|
12 |
-
original_model = gr.Interface.load("models/
|
13 |
|
14 |
# Load the super-resolution model from Hugging Face's model hub
|
15 |
-
super_resolution_model =
|
16 |
|
17 |
def process_image(input_image):
|
18 |
# Run the original model
|
19 |
output_image = original_model(input_image)
|
20 |
|
21 |
-
#
|
22 |
-
output_image =
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
-
#
|
25 |
-
|
26 |
-
|
27 |
-
super_res_image = super_resolution_model(output_image)
|
28 |
|
29 |
-
#
|
30 |
-
|
31 |
-
|
32 |
|
33 |
-
#
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
|
|
|
|
37 |
|
|
|
38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
# gr.Interface.load("models/Akbartus/Lora360").launch(show_api=True)
|
4 |
|
5 |
+
import tensorflow as tf
|
6 |
+
import math
|
7 |
+
import numpy as np
|
8 |
from PIL import Image
|
9 |
+
from tensorflow.keras.preprocessing.image import img_to_array
|
10 |
+
from huggingface_hub import from_pretrained_keras
|
11 |
+
import gradio as gr
|
12 |
|
13 |
# Load the original model
|
14 |
+
original_model = gr.Interface.load("models/Tester/Lora360")
|
15 |
|
16 |
# Load the super-resolution model from Hugging Face's model hub
|
17 |
+
super_resolution_model = from_pretrained_keras("keras-io/super-resolution")
|
18 |
|
19 |
def process_image(input_image):
|
20 |
# Run the original model
|
21 |
output_image = original_model(input_image)
|
22 |
|
23 |
+
# Resize the image to 100x100
|
24 |
+
output_image = output_image.resize((100,100))
|
25 |
+
|
26 |
+
# Convert the image to YCbCr color space
|
27 |
+
ycbcr = output_image.convert("YCbCr")
|
28 |
+
y, cb, cr = ycbcr.split()
|
29 |
+
y = img_to_array(y)
|
30 |
+
y = y.astype("float32") / 255.0
|
31 |
|
32 |
+
# Expand the dimensions of the image for model input
|
33 |
+
input = np.expand_dims(y, axis=0)
|
34 |
+
out = super_resolution_model.predict(input)
|
|
|
35 |
|
36 |
+
# Process the output
|
37 |
+
out_img_y = out[0]
|
38 |
+
out_img_y *= 255.0
|
39 |
|
40 |
+
# Restore the image in RGB color space.
|
41 |
+
out_img_y = out_img_y.clip(0, 255)
|
42 |
+
out_img_y = out_img_y.reshape((np.shape(out_img_y)[0], np.shape(out_img_y)[1]))
|
43 |
+
out_img_y = Image.fromarray(np.uint8(out_img_y), mode="L")
|
44 |
+
out_img_cb = cb.resize(out_img_y.size, Image.BICUBIC)
|
45 |
+
out_img_cr = cr.resize(out_img_y.size, Image.BICUBIC)
|
46 |
+
out_img = Image.merge("YCbCr", (out_img_y, out_img_cb, out_img_cr)).convert(
|
47 |
+
"RGB"
|
48 |
+
)
|
49 |
|
50 |
+
# Return the original resized image and the super-resolved image
|
51 |
+
return (output_image, out_img)
|
52 |
|
53 |
+
article = "<p style='text-align: center'><a href='https://arxiv.org/abs/1609.05158' target='_blank'>Real-Time Single Image and Video Super-Resolution Using an Efficient Sub-Pixel Convolutional Neural Network</a></p><center> <a href='https://keras.io/examples/vision/super_resolution_sub_pixel/' target='_blank'>Image Super-Resolution using an Efficient Sub-Pixel CNN</a></p> <center>Contributors: <a href='https://twitter.com/Cr0wley_zz'>Devjyoti Chakraborty</a>|<a href='https://twitter.com/ritwik_raha'>Ritwik Raha</a>|<a href='https://twitter.com/ariG23498'>Aritra Roy Gosthipaty</a></center>"
|
54 |
|
55 |
+
iface = gr.Interface(
|
56 |
+
fn=process_image,
|
57 |
+
title = " Image Super-resolution",
|
58 |
+
description = "This space is a demo of the keras tutorial 'Image Super-Resolution using an Efficient Sub-Pixel CNN' based on the paper 'Real-Time Single Image and Video Super-Resolution Using an Efficient Sub-Pixel Convolutional Neural Network' 👀",
|
59 |
+
article = article,
|
60 |
+
inputs=gr.inputs.Image(label="Input Image"),
|
61 |
+
outputs=[gr.outputs.Image(label="Resized 100x100 image"),
|
62 |
+
gr.outputs.Image(label="Super-resolution 300x300 image")
|
63 |
+
],
|
64 |
+
).launch()
|