Spaces:
Runtime error
Runtime error
Commit
β’
6c7bbb9
1
Parent(s):
9aa7621
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from openvino.inference_engine import IECore
|
3 |
+
import cv2
|
4 |
+
import numpy as np
|
5 |
+
from PIL import Image
|
6 |
+
|
7 |
+
# Load the OpenVINO model
|
8 |
+
model_xml = 'model.xml'
|
9 |
+
model_bin = 'model.bin'
|
10 |
+
|
11 |
+
ie = IECore()
|
12 |
+
net = ie.read_network(model=model_xml, weights=model_bin)
|
13 |
+
exec_net = ie.load_network(network=net, device_name="CPU")
|
14 |
+
|
15 |
+
# Define the function for image processing
|
16 |
+
def upscale_image(input_image):
|
17 |
+
# Convert Gradio PIL Image to numpy array
|
18 |
+
input_image = np.array(input_image)
|
19 |
+
|
20 |
+
# Preprocess the input image
|
21 |
+
image = cv2.cvtColor(input_image, cv2.COLOR_RGB2BGR)
|
22 |
+
image = cv2.resize(image, (224, 224))
|
23 |
+
image = image / 255.0
|
24 |
+
image = np.transpose(image, (2, 0, 1))
|
25 |
+
image = image.reshape(1, 3, 224, 224)
|
26 |
+
|
27 |
+
# Run inference
|
28 |
+
outputs = exec_net.infer(inputs={'input': image})
|
29 |
+
|
30 |
+
# Post-process the output
|
31 |
+
output_image = outputs['output'][0]
|
32 |
+
output_image = np.transpose(output_image, (1, 2, 0))
|
33 |
+
output_image = np.clip(output_image, 0, 1) * 255
|
34 |
+
output_image = output_image.astype(np.uint8)
|
35 |
+
output_image = cv2.cvtColor(output_image, cv2.COLOR_RGB2BGR)
|
36 |
+
return output_image
|
37 |
+
|
38 |
+
# Create the Gradio interface
|
39 |
+
inputs = gr.inputs.Image(type="pil", label="Input Image") # Use 'pil' type for uploaded images
|
40 |
+
outputs = gr.outputs.Image(type="pil", label="Upscaled Image")
|
41 |
+
|
42 |
+
title = "Image Upscaling App"
|
43 |
+
description = "Upload an image and see the upscaled result."
|
44 |
+
iface = gr.Interface(fn=upscale_image, inputs=inputs, outputs=outputs, title=title, description=description)
|
45 |
+
|
46 |
+
# Launch the Gradio interface
|
47 |
+
iface.launch()
|