import streamlit as st
import pandas as pd
import json
import io
st.set_page_config(page_title="URL Discovery Tool", layout="wide")
# โ
STYLE
st.markdown("""
""", unsafe_allow_html=True)
st.image("logo.png", width=80)
st.title("๐ท URL Discovery Tool")
# โ
SESSION STATES
if "index" not in st.session_state:
st.session_state.index = 0
if "df" not in st.session_state:
st.session_state.df = None
if "started" not in st.session_state:
st.session_state.started = False
if "stop" not in st.session_state:
st.session_state.stop = False
if "verified_added" not in st.session_state:
st.session_state.verified_added = False
if "reset_inputs" not in st.session_state:
st.session_state.reset_inputs = False
uploaded_file = st.file_uploader("Upload Excel File", type=["xlsx"])
if uploaded_file:
# โ
LOAD DATA
if st.session_state.df is None:
st.session_state.df = pd.read_excel(uploaded_file)
df = st.session_state.df
# โ
SUMMARY CARDS
st.markdown("## ๐ Summary")
total = len(df)
completed = df["Status"].eq("Completed").sum() if "Status" in df.columns else 0
pending = df["Status"].eq("Pending").sum() if "Status" in df.columns else 0
if "Verified URL Count" in df.columns:
total_urls = df["Verified URL Count"].fillna(0).sum()
else:
total_urls = 0
c1, c2, c3, c4 = st.columns(4)
c1.markdown(f"""
""", unsafe_allow_html=True)
c2.markdown(f"""
""", unsafe_allow_html=True)
c3.markdown(f"""
""", unsafe_allow_html=True)
c4.markdown(f"""
{int(total_urls)}
Total URLs Verified
""", unsafe_allow_html=True)
st.markdown("---")
# โ
START / STOP
col1, col2 = st.columns(2)
if col1.button("โถ Start Processing", disabled=st.session_state.started):
st.session_state.started = True
if col2.button("๐ Stop Processing"):
st.session_state.stop = True
st.session_state.started = False
# โ
STOP
if st.session_state.stop:
st.warning("โ ๏ธ Processing stopped")
buffer = io.BytesIO()
df.to_excel(buffer, index=False, engine="openpyxl")
st.download_button("โฌ Download Progress", buffer.getvalue(), "partial.xlsx")
st.stop()
if not st.session_state.started:
st.info("๐ Click Start Processing")
st.stop()
entity_list = df["Entity ID"].tolist()
# โ
ALL DONE
if st.session_state.index >= len(entity_list):
st.success("โ
All Done!")
buffer = io.BytesIO()
df.to_excel(buffer, index=False, engine="openpyxl")
st.download_button("โฌ Download Final File", buffer.getvalue(), "final.xlsx")
st.stop()
# โ
CURRENT ENTITY
entity_id = entity_list[st.session_state.index]
row = df[df["Entity ID"] == entity_id].iloc[0]
# โ
LINK
st.markdown(
f'',
unsafe_allow_html=True
)
# โ
ENTITY NAME
try:
payload = json.loads(row["Payload"])
entity_name = payload.get("name", "")
except:
entity_name = "N/A"
# โ
ENTITY DETAILS
st.markdown("### ๐งพ Entity Details")
c1, c2, c3 = st.columns(3)
with c1:
st.markdown(f"""
Entity Name: {entity_name}
Client Name: {row['Client Name']}
""", unsafe_allow_html=True)
with c2:
st.markdown(f"""
Industry: {row['Industry ID']}
Sync Partner: {row['Sync Partner']}
""", unsafe_allow_html=True)
with c3:
st.markdown(f"""
Products: {row['Client Products']}
Type: {row['Entity Type']}
""", unsafe_allow_html=True)
# โ
ERROR DETAILS
st.markdown("### ๐ Error Details")
cols = df.columns.tolist()
start = cols.index("Healthgrades")
end = cols.index("AppleMaps") + 1
sources = cols[start:end]
data = []
for col in sources:
val = str(row[col]).strip()
if val and val.lower() != "nan":
if "404" in val or "No URLs" in val:
action = "Add URL"
elif "500" in val:
action = "Retry"
elif "Different URL already exists" in val:
action = "Verify Duplicate"
else:
action = ""
data.append({
"Source": col,
"Value": val,
"Action": action
})
if data:
st.dataframe(pd.DataFrame(data), use_container_width=True)
# โ
PROGRESS
progress = (st.session_state.index + 1) / len(entity_list)
st.progress(progress)
st.caption(f"{st.session_state.index + 1} / {len(entity_list)}")
# โ
RESET INPUTS
if st.session_state.reset_inputs:
st.session_state["verified_input"] = ""
st.session_state["remarks_input"] = ""
st.session_state.reset_inputs = False
# โ
REMARKS
st.markdown("### ๐ Remarks")
remarks = st.text_area("Enter remarks", key="remarks_input")
# โ
URL COUNT
st.markdown("### ๐ข URL Verification")
col1, col2 = st.columns([2, 1])
verified_count = col1.text_input(
"No of URLs Verified",
key="verified_input"
)
if col2.button("โ Add"):
if verified_count.strip().isdigit():
df.loc[df["Entity ID"] == entity_id, "Verified URL Count"] = int(verified_count)
df.loc[df["Entity ID"] == entity_id, "Remarks"] = remarks
st.session_state.verified_added = True
st.success("โ
Added successfully")
else:
st.error("โ Enter valid number")
# โ
ACTION BUTTONS
col_done, col_pending = st.columns(2)
if st.session_state.verified_added:
if col_done.button("โ
Completed & Next"):
df.loc[df["Entity ID"] == entity_id, "Status"] = "Completed"
st.session_state.index += 1
st.session_state.verified_added = False
st.session_state.reset_inputs = True
st.rerun()
if col_pending.button("โณ Pending & Next"):
df.loc[df["Entity ID"] == entity_id, "Status"] = "Pending"
st.session_state.index += 1
st.session_state.verified_added = False
st.session_state.reset_inputs = True
st.rerun()
else:
st.info("๐ Add verified URL count to proceed")