1212import tempfile
1313from pathlib import Path
1414
15+ import pandas as pd
1516import streamlit as st
1617import torch
1718from PIL import Image
@@ -76,9 +77,6 @@ def run_inference(
7677 img_processor = ImageProcessor (img_path = image_path , device = device )
7778 img_batch = img_processor .process_image ()
7879
79- # Create a placeholder for predictions
80- predictions_placeholder = st .empty ()
81-
8280 # ONNX inference
8381 if mode in ["onnx" , "all" ]:
8482 with st .spinner ("Running ONNX inference..." ):
@@ -169,8 +167,6 @@ def display_benchmark_results(results: dict[str, tuple[float, float]]):
169167 st .subheader ("Benchmark Results" )
170168
171169 # Create DataFrame for display
172- import pandas as pd
173-
174170 data = {
175171 "Model" : list (results .keys ()),
176172 "Avg Time (ms)" : [f"{ results [model ][0 ]:.2f} " for model in results .keys ()],
@@ -211,6 +207,7 @@ def main():
211207 image_source = st .sidebar .radio ("Select image source:" , ["Sample Images" , "Upload Image" ])
212208
213209 image_path = None
210+ is_temp_file = False # Track if file should be cleaned up
214211 if image_source == "Sample Images" :
215212 sample_images = []
216213 inference_dir = Path ("./inference" )
@@ -232,6 +229,7 @@ def main():
232229 with tempfile .NamedTemporaryFile (delete = False , suffix = ".jpg" ) as tmp_file :
233230 tmp_file .write (uploaded_file .read ())
234231 image_path = tmp_file .name
232+ is_temp_file = True
235233
236234 # Inference mode selection
237235 st .sidebar .subheader ("Inference Settings" )
@@ -304,7 +302,7 @@ def main():
304302 display_benchmark_results (results )
305303
306304 # Clean up temporary file if uploaded
307- if image_source == "Upload Image" and image_path . startswith ( "/tmp" ) :
305+ if is_temp_file :
308306 try :
309307 os .unlink (image_path )
310308 except Exception :
0 commit comments