Satyam0077 commited on
Commit
b836ff8
Β·
verified Β·
1 Parent(s): 5215fcd

Update app.py

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