Update pages/3_Sketch_To_Image.py
Browse files93 unmodified lines94959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314493 unmodified linesst.image(generated_image.resize((784, 784)))# else:# st.warning(f"β οΈ Pix2Pix skipped (face count β 1 or face < {FACE_AREA_THRESHOLD*100:.0f}%). Showing similar images.")# # top_images = query_custom_model(image=sketch, k=5)# # st.subheader("Top 5 Similar Images (Custom Model)")# # st.image(top_images, width=150, caption=[f"Match {i+1}" for i in range(len(top_images))])# # Save the uploaded sketch temporarily# temp_path = "temp_sketch.jpg"# sketch.save(temp_path)# # results = query_by_image(temp_path, nn_model, image_paths)# nn_model, _, image_paths = load_custom_model()# results = query_by_image(temp_path, nn_model, image_paths)# st.subheader("Similar Images Using Custom Model")# for i, path in enumerate(results):# st.markdown(f"π **Match {i+1}:** [{os.path.basename(path)}]({path})")# if os.path.exists(temp_path):# os.remove(temp_path)else:st.warning(f"β οΈ Pix2Pix skipped (face count β 1 or face < {FACE_AREA_THRESHOLD*100:.0f}%). Showing similar images.")# Save the uploaded sketch temporarilytemp_path = "temp_sketch.jpg"sketch.save(temp_path)# Load model and querynn_model, _, image_paths = load_custom_model()results = query_by_image(temp_path, nn_model, image_paths)# Create static/ dir to store publicly accessible filesSTATIC_DIR = "static"os.makedirs(STATIC_DIR, exist_ok=True)st.subheader("π Similar Images Using Custom Model")for i, path in enumerate(results):filename = os.path.basename(path)static_path = os.path.join(STATIC_DIR, filename)# Copy file to static/ so it can be servedif not os.path.exists(static_path):shutil.copy(path, static_path)# Link to the file relative to the serverpublic_url = f"/static/{filename}"st.markdown(f"π **Match {i+1}:** [{filename}]({public_url})")# Clean up temporary sketch fileif os.path.exists(temp_path):93 unmodified lines94959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016193 unmodified linesst.image(generated_image.resize((784, 784)))# else:# st.warning(f"β οΈ Pix2Pix skipped (face count β 1 or face < {FACE_AREA_THRESHOLD*100:.0f}%). Showing similar images.")# # Save the uploaded sketch temporarily# temp_path = "temp_sketch.jpg"# sketch.save(temp_path)# # Load model and query# nn_model, _, image_paths = load_custom_model()# results = query_by_image(temp_path, nn_model, image_paths)# # Create static/ dir to store publicly accessible files# STATIC_DIR = "static"# os.makedirs(STATIC_DIR, exist_ok=True)# st.subheader("π Similar Images Using Custom Model")# for i, path in enumerate(results):# filename = os.path.basename(path)# static_path = os.path.join(STATIC_DIR, filename)# # Copy file to static/ so it can be served# if not os.path.exists(static_path):# shutil.copy(path, static_path)# # Link to the file relative to the server# public_url = f"/static/{filename}"# st.markdown(f"π **Match {i+1}:** [{filename}]({public_url})")else:st.warning(f"β οΈ Pix2Pix skipped (face count β 1 or face < {FACE_AREA_THRESHOLD*100:.0f}%). Showing similar images.")# Save the uploaded sketch temporarilytemp_path = "temp_sketch.jpg"sketch.save(temp_path)# Load model and querynn_model, _, image_paths = load_custom_model()results = query_by_image(temp_path, nn_model, image_paths)# Create static/ dir to store publicly accessible filesSTATIC_DIR = "static"os.makedirs(STATIC_DIR, exist_ok=True)st.subheader("πΌοΈ Similar Images Using Custom Model")for i, path in enumerate(results):filename = os.path.basename(path)static_path = os.path.join(STATIC_DIR, filename)# Copy file to static/ so it can be servedif not os.path.exists(static_path):shutil.copy(path, static_path)# Link to the file relative to the serverpublic_url = f"/static/{filename}"# Display image and download linkst.image(static_path, width=150, caption=f"Match {i+1}")st.markdown(f"[π Open or Download {filename}]({public_url})")# Clean up temporary sketch fileif os.path.exists(temp_path):os.remove(temp_path)# Clean up temporary sketch fileif os.path.exists(temp_path):
pages/3_Sketch_To_Image.py+51-34