Spaces:
Sleeping
Sleeping
import gradio as gr | |
from openvino.runtime import Core | |
from PIL import Image | |
import numpy as np | |
core = Core() | |
model = core.read_model("openvino_model/best.xml") | |
compiled_model = core.compile_model(model, "CPU") | |
output_layer = compiled_model.output(0) | |
def preprocess_image(image): | |
image = image.resize((640, 640)) | |
input_data = np.array(image).transpose(2, 0, 1) | |
input_data = np.expand_dims(input_data, axis=0) | |
input_data = input_data.astype(np.float32) / 255.0 | |
return input_data | |
def predict(image): | |
input_data = preprocess_image(image) | |
results = compiled_model([input_data])[output_layer] | |
print("Raw results:", results) | |
output_image = image.copy() | |
return output_image | |
interface = gr.Interface( | |
fn=predict, | |
inputs=gr.Image(type="pil"), | |
outputs=gr.Image(type="pil"), | |
title="Object Detection", | |
description="Upload an image to detect objects using the OpenVINO 2024 model." | |
) | |
if __name__ == "__main__": | |
interface.launch() | |