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"""
{total}
Total Entities
""", unsafe_allow_html=True) c2.markdown(f"""
{completed}
Completed
""", unsafe_allow_html=True) c3.markdown(f"""
{pending}
Pending
""", 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'

๐Ÿ“Œ Entity ID: {entity_id}

', 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")