Spaces:
Sleeping
Sleeping
import gradio as gr | |
import cv2 | |
import requests | |
import os | |
import tensorflow as tf | |
import numpy as np | |
file_urls = [ | |
'https://drive.google.com/file/d/1dxNKawyagazR9TbxT6Fbla0opLqkROFG/view?usp=sharing', | |
'https://drive.google.com/file/d/109cc23-4HEyH9hFwenJjY7ZEVXj1-ZjW/view?usp=sharing', | |
'https://drive.google.com/file/d/1GLdsfug6n1tohqSAPmIzvCWZZSYIaHXj/view?usp=sharing' | |
] | |
def download_file(url, save_name): | |
if not os.path.exists(save_name): | |
file = requests.get(url) | |
open(save_name, 'wb').write(file.content) | |
for i, url in enumerate(file_urls): | |
if 'mp4' in file_urls[i]: | |
download_file( | |
file_urls[i], | |
f"video.mp4" | |
) | |
else: | |
download_file( | |
file_urls[i], | |
f"image_{i}.jpg" | |
) | |
# Load the TensorFlow model | |
model_path = 'saved_model' # Replace with your TensorFlow model path | |
model = tf.saved_model.load(model_path) | |
# Placeholder values for input dimensions | |
input_width = 640 # Replace with the actual input width of your model | |
input_height = 640 # Replace with the actual input height of your model | |
def predict_with_tf_model(image): | |
# Preprocess the image | |
image = cv2.resize(image, (input_width, input_height)) | |
image = np.expand_dims(image, axis=0) | |
image = image / 255.0 | |
# Run inference | |
output = model(image) | |
# Post-process the output if needed | |
return output | |
def show_preds_image(image_path): | |
image = cv2.imread(image_path) | |
# Perform inference using the TensorFlow model | |
output = predict_with_tf_model(image) | |
# Post-process the output and draw on the image if needed | |
return cv2.cvtColor(image, cv2.COLOR_BGR2RGB) | |
inputs_image = [ | |
gr.Image(type="filepath", label="Input Image"), | |
] | |
outputs_image = [ | |
gr.Image(type="numpy", label="Output Image"), | |
] | |
interface_image = gr.Interface( | |
fn=show_preds_image, | |
inputs=inputs_image, | |
outputs=outputs_image, | |
title="Gregg Detector", | |
) | |
interface_image.launch() | |