Update app.py
Browse files
app.py
CHANGED
|
@@ -1,44 +1,50 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
import pandas as pd
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
st.
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
st.
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import os
|
| 4 |
+
from utils.search import get_collaboration_data
|
| 5 |
+
|
| 6 |
+
st.set_page_config(page_title="Virgin Media Collaboration Finder", layout="centered")
|
| 7 |
+
|
| 8 |
+
st.title("π΅οΈ Virgin Media - Competitor Collaboration Finder")
|
| 9 |
+
st.markdown("Use this tool to find which competitors have worked with **Virgin Media**.")
|
| 10 |
+
|
| 11 |
+
# β
Load competitor list using absolute path
|
| 12 |
+
base_path = os.path.dirname(os.path.abspath(__file__))
|
| 13 |
+
csv_path = os.path.join(base_path, "data", "competitors.csv")
|
| 14 |
+
|
| 15 |
+
try:
|
| 16 |
+
competitors_df = pd.read_csv(csv_path)
|
| 17 |
+
competitors = competitors_df['Company'].dropna().tolist()
|
| 18 |
+
except FileNotFoundError:
|
| 19 |
+
st.error("β File not found: data/competitors.csv")
|
| 20 |
+
st.stop()
|
| 21 |
+
except pd.errors.EmptyDataError:
|
| 22 |
+
st.error("β The competitors.csv file is empty.")
|
| 23 |
+
st.stop()
|
| 24 |
+
|
| 25 |
+
# β
Run search
|
| 26 |
+
if st.button("π Run Collaboration Search"):
|
| 27 |
+
with st.spinner("Searching... This may take a few moments..."):
|
| 28 |
+
result_df = get_collaboration_data(competitors)
|
| 29 |
+
if not result_df.empty:
|
| 30 |
+
results_path = os.path.join(base_path, "results", "virgin_collab_results.csv")
|
| 31 |
+
result_df.to_csv(results_path, index=False)
|
| 32 |
+
st.success("β
Search Completed!")
|
| 33 |
+
st.dataframe(result_df)
|
| 34 |
+
else:
|
| 35 |
+
st.warning("β οΈ No collaboration data found. Nothing was saved.")
|
| 36 |
+
|
| 37 |
+
# β
Show saved results
|
| 38 |
+
if st.button("π Show Saved Results"):
|
| 39 |
+
results_path = os.path.join(base_path, "results", "virgin_collab_results.csv")
|
| 40 |
+
try:
|
| 41 |
+
saved_df = pd.read_csv(results_path)
|
| 42 |
+
if saved_df.empty:
|
| 43 |
+
st.warning("β οΈ The saved file is empty. Try running the search again.")
|
| 44 |
+
else:
|
| 45 |
+
st.success("β
Loaded saved results.")
|
| 46 |
+
st.dataframe(saved_df)
|
| 47 |
+
except FileNotFoundError:
|
| 48 |
+
st.warning("β οΈ No saved results found. Please run the search first.")
|
| 49 |
+
except pd.errors.EmptyDataError:
|
| 50 |
+
st.warning("β οΈ The saved file exists but is empty or invalid.")
|