GAP_SMALL_PROJECT2 / tabs /batch_processing.py
fatimaxa's picture
Update tabs/batch_processing.py
4a693a1 verified
import gradio as gr
from utils.predictions import predict_batch_visual
def create_batch_processing_tab(model, class_names, device):
"""Create the batch processing tab"""
def batch_predict_wrapper(files, progress=gr.Progress()):
if not files:
return None, "No files uploaded. Please select images to process."
progress(0, desc="Starting batch processing...")
gallery, results = predict_batch_visual(files, model, class_names, device, progress)
return gallery, results
gr.Markdown("""
### Upload multiple images for batch prediction
Upload several plant leaf images at once to get predictions for all of them.
Results will show each image with its prediction and confidence score.
""")
batch_input = gr.File(
file_count="multiple",
label="Upload Multiple Images",
file_types=["image"]
)
batch_btn = gr.Button("Process All Images", variant="primary", size="lg")
with gr.Row():
batch_gallery = gr.Gallery(
label="Processed Images",
columns=3,
height="auto",
object_fit="contain"
)
batch_output = gr.Markdown(label="Detailed Results")
batch_btn.click(
fn=batch_predict_wrapper,
inputs=batch_input,
outputs=[batch_gallery, batch_output]
)
return batch_input, batch_btn, batch_gallery, batch_output