|
import streamlit as st
|
|
import matplotlib.pyplot as plt
|
|
import leafmap.foliumap as leafmap
|
|
from io import BytesIO
|
|
|
|
st.title("BEFORE-AFTER COMPARISON")
|
|
|
|
st.write("Please upload the 'Before' and 'After' images.")
|
|
|
|
before = st.file_uploader("Upload the before image.", type=["jpg", "jpeg", "png"])
|
|
|
|
if before is not None:
|
|
before_bytes = BytesIO(before.read())
|
|
before_array = plt.imread(before_bytes, format=before.type)
|
|
|
|
after = st.file_uploader("Upload the after image.", type=["jpg", "jpeg", "png"])
|
|
|
|
if after is not None:
|
|
after_bytes = BytesIO(after.read())
|
|
after_array = plt.imread(after_bytes, format=after.type)
|
|
|
|
|
|
comparison = st.button("Comparison")
|
|
|
|
|
|
if comparison:
|
|
|
|
leafmap.image_comparison(
|
|
before_array,
|
|
after_array,
|
|
label1="before",
|
|
label2="after",
|
|
starting_position=50,
|
|
out_html="image_comparison.html"
|
|
)
|
|
|
|
try:
|
|
|
|
with open("image_comparison.html", 'r', encoding='ISO-8859-1') as HtmlFile:
|
|
source_code = HtmlFile.read()
|
|
|
|
|
|
st.components.v1.html(source_code, height=600)
|
|
|
|
|
|
with open("image_comparison.html", "rb") as f:
|
|
st.download_button(
|
|
label="Download HTML File",
|
|
data=f,
|
|
file_name="image_comparison.html",
|
|
mime="text/html"
|
|
)
|
|
except Exception as e:
|
|
st.error(f"Error: {str(e)}") |