Satyam0077 commited on
Commit
8e022d8
Β·
verified Β·
1 Parent(s): 8f0b219

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -10
app.py CHANGED
@@ -1,16 +1,23 @@
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)
@@ -27,8 +34,8 @@ 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:
@@ -36,9 +43,9 @@ if st.button("πŸ” Run Collaboration Search"):
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:
 
1
  import streamlit as st
2
  import pandas as pd
3
  import os
4
+ import sys
5
 
6
+ # βœ… Fix Python path for Hugging Face + VS Code (handling imports correctly)
7
+ sys.path.append(os.path.join(os.path.dirname(__file__), 'utils')) # Ensure the utils directory is found
8
+ from search import get_collaboration_data # Adjusted import for search.py from utils
9
 
10
+ # βœ… Hugging Face File Paths
11
+ base_path = os.path.dirname(os.path.abspath(__file__))
12
+ data_path = os.path.join(base_path, "data")
13
+ results_path = os.path.join(base_path, "results")
14
+
15
+ # βœ… Ensure the required directories exist (on Hugging Face Spaces, directories like "data" or "results" may not exist)
16
+ os.makedirs(data_path, exist_ok=True)
17
+ os.makedirs(results_path, exist_ok=True)
18
 
19
  # βœ… Load competitor list using absolute path
20
+ csv_path = os.path.join(data_path, "competitors.csv")
 
21
 
22
  try:
23
  competitors_df = pd.read_csv(csv_path)
 
34
  with st.spinner("Searching... This may take a few moments..."):
35
  result_df = get_collaboration_data(competitors)
36
  if not result_df.empty:
37
+ result_file_path = os.path.join(results_path, "virgin_collab_results.csv")
38
+ result_df.to_csv(result_file_path, index=False)
39
  st.success("βœ… Search Completed!")
40
  st.dataframe(result_df)
41
  else:
 
43
 
44
  # βœ… Show saved results
45
  if st.button("πŸ“‚ Show Saved Results"):
46
+ result_file_path = os.path.join(results_path, "virgin_collab_results.csv")
47
  try:
48
+ saved_df = pd.read_csv(result_file_path)
49
  if saved_df.empty:
50
  st.warning("⚠️ The saved file is empty. Try running the search again.")
51
  else: