Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -20,9 +20,9 @@ model.load_state_dict(torch.load("retinanet_best_model.pth", map_location=device
|
|
| 20 |
model.eval()
|
| 21 |
|
| 22 |
# Prediction function
|
| 23 |
-
def predict_image(image,
|
| 24 |
|
| 25 |
-
if
|
| 26 |
# Preprocess the image
|
| 27 |
img = Image.fromarray(image).convert('RGB') # Convert Gradio input to PIL Image
|
| 28 |
input_tensor = image_transform(img).unsqueeze(0).to(device)
|
|
@@ -76,8 +76,13 @@ with gr.Blocks() as demo:
|
|
| 76 |
with gr.Row():
|
| 77 |
image_input = gr.Image(label="Upload Image", type="numpy")
|
| 78 |
output_text = gr.Textbox(label="Prediction Result")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
predict_button = gr.Button("Predict")
|
| 80 |
-
predict_button.click(predict_image, inputs=image_input, outputs=output_text)
|
| 81 |
|
| 82 |
# Launch the app
|
| 83 |
demo.launch()
|
|
|
|
| 20 |
model.eval()
|
| 21 |
|
| 22 |
# Prediction function
|
| 23 |
+
def predict_image(image, is_frame):
|
| 24 |
|
| 25 |
+
if is_frame == "No":
|
| 26 |
# Preprocess the image
|
| 27 |
img = Image.fromarray(image).convert('RGB') # Convert Gradio input to PIL Image
|
| 28 |
input_tensor = image_transform(img).unsqueeze(0).to(device)
|
|
|
|
| 76 |
with gr.Row():
|
| 77 |
image_input = gr.Image(label="Upload Image", type="numpy")
|
| 78 |
output_text = gr.Textbox(label="Prediction Result")
|
| 79 |
+
is_frame_radio = gr.Radio(
|
| 80 |
+
choices=["Yes", "No"], # Options for the radio button
|
| 81 |
+
label="Is this a frame from a video?", # Label for the radio button
|
| 82 |
+
value="Not a Frame" # Default selected option
|
| 83 |
+
)
|
| 84 |
predict_button = gr.Button("Predict")
|
| 85 |
+
predict_button.click(predict_image, inputs=[image_input, is_frame_radio], outputs=output_text)
|
| 86 |
|
| 87 |
# Launch the app
|
| 88 |
demo.launch()
|