Update app.py
Browse files
app.py
CHANGED
|
@@ -1,16 +1,23 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import os
|
| 4 |
-
|
| 5 |
|
| 6 |
-
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
# β
Load competitor list using absolute path
|
| 12 |
-
|
| 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 |
-
|
| 31 |
-
result_df.to_csv(
|
| 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 |
-
|
| 40 |
try:
|
| 41 |
-
saved_df = pd.read_csv(
|
| 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:
|