Spaces:
Build error
Build error
Allow choice from samples
Browse files
app.py
CHANGED
@@ -22,10 +22,22 @@ def load_model(repo_id):
|
|
22 |
detection_model = tf.saved_model.load(saved_model_dir)
|
23 |
return detection_model
|
24 |
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
image_np = pil_image_as_numpy_array(pilimg)
|
27 |
return predict_combined_models(image_np, detection_model_fin, detection_model_ini)
|
28 |
|
|
|
29 |
def predict_combined_models(image_np, model1, model2):
|
30 |
# Process with first model
|
31 |
results1 = model1(image_np)
|
@@ -79,7 +91,11 @@ detection_model_ini = load_model(REPO_ID2)
|
|
79 |
# Gradio interface
|
80 |
gr.Interface(
|
81 |
fn=predict,
|
82 |
-
inputs=
|
|
|
|
|
|
|
|
|
83 |
outputs=gr.Image(type="pil"),
|
84 |
title="Gramophone & Veena Detection with TensorFlow Models",
|
85 |
description="This app uses TensorFlow models to detect objects in images. Upload an image to see the detected gramophone and veena. Bounding boxes labeled Run1 = - Model 2, Run2= - Model 1"
|
|
|
22 |
detection_model = tf.saved_model.load(saved_model_dir)
|
23 |
return detection_model
|
24 |
|
25 |
+
# List of sample images in 'test_samples' folder
|
26 |
+
sample_images = [file for file in os.listdir('test_samples') if file.endswith(('.png', '.jpg', '.jpeg'))]
|
27 |
+
sample_images.sort() # Optional: sort the file names
|
28 |
+
|
29 |
+
def predict(uploaded_img, use_sample, sample_choice):
|
30 |
+
if use_sample:
|
31 |
+
# Use the selected sample image
|
32 |
+
pilimg = Image.open(os.path.join('test_samples', sample_choice))
|
33 |
+
else:
|
34 |
+
# Use the uploaded image
|
35 |
+
pilimg = uploaded_img
|
36 |
+
|
37 |
image_np = pil_image_as_numpy_array(pilimg)
|
38 |
return predict_combined_models(image_np, detection_model_fin, detection_model_ini)
|
39 |
|
40 |
+
|
41 |
def predict_combined_models(image_np, model1, model2):
|
42 |
# Process with first model
|
43 |
results1 = model1(image_np)
|
|
|
91 |
# Gradio interface
|
92 |
gr.Interface(
|
93 |
fn=predict,
|
94 |
+
inputs=[
|
95 |
+
gr.Image(type="pil"), # Image upload
|
96 |
+
gr.Checkbox(label="Use a sample image instead"), # Checkbox to choose a sample
|
97 |
+
gr.Dropdown(choices=sample_images, label="Select a Sample Image") # Dropdown to select a sample
|
98 |
+
],
|
99 |
outputs=gr.Image(type="pil"),
|
100 |
title="Gramophone & Veena Detection with TensorFlow Models",
|
101 |
description="This app uses TensorFlow models to detect objects in images. Upload an image to see the detected gramophone and veena. Bounding boxes labeled Run1 = - Model 2, Run2= - Model 1"
|