File size: 2,023 Bytes
b2aa69e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8873a1c
b2aa69e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
765ac56
 
 
b2aa69e
 
 
 
 
 
 
 
765ac56
b2aa69e
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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()