Update pages/3_Sketch_To_Image.py
Browse files93 unmodified lines94959697989799100989910010410510610110210310410911011111211311411511611711811910512112212310610710810912512612711011112911211311411513113213311611711811912012112212312412512612712812913013113213313413513613713813914014114214313513613714414514614714814915015115215315413914014115515615715815916016193 unmodified lines st.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)
# # Load model and query # 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 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) # 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") 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) 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 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) # 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}" # Display image and download link st.image(static_path, width=150, caption=f"Match {i+1}") st.markdown(f"[π Open or Download {filename}]({public_url})") # Link to the file relative to the server public_url = f"/static/{filename}" st.markdown(f"π **Match {i+1}:** [{filename}]({public_url})") # Clean up temporary sketch file if os.path.exists(temp_path): os.remove(temp_path)
# Clean up temporary sketch file if os.path.exists(temp_path):pages/3_Sketch_To_Image.py+51-34