Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -41,21 +41,50 @@ class ComprehensiveSocialMediaAnalyzer:
|
|
| 41 |
try:
|
| 42 |
# Load the dataset
|
| 43 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
# Try multiple possible paths
|
| 45 |
possible_paths = [
|
| 46 |
"data/Students Social Media Addiction.csv",
|
| 47 |
"./data/Students Social Media Addiction.csv",
|
| 48 |
"../data/Students Social Media Addiction.csv",
|
|
|
|
| 49 |
os.path.join(os.path.dirname(__file__), "data", "Students Social Media Addiction.csv")
|
| 50 |
]
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
for path in possible_paths:
|
|
|
|
| 53 |
if os.path.exists(path):
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
else:
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
# Create binary features for categorical variables
|
| 61 |
self.df['Is_Female'] = (self.df['Gender'] == 'Female').astype(int)
|
|
@@ -584,6 +613,7 @@ with gr.Blocks(title="Social Media Addiction Analysis - Comprehensive", theme=gr
|
|
| 584 |
### Data Source
|
| 585 |
Analysis based on comprehensive student social media usage survey data.
|
| 586 |
""")
|
|
|
|
| 587 |
# Launch the app
|
| 588 |
if __name__ == "__main__":
|
| 589 |
demo.launch(share=True)
|
|
|
|
| 41 |
try:
|
| 42 |
# Load the dataset
|
| 43 |
import os
|
| 44 |
+
import glob
|
| 45 |
+
|
| 46 |
+
# Get current working directory
|
| 47 |
+
cwd = os.getcwd()
|
| 48 |
+
print(f"π Current working directory: {cwd}")
|
| 49 |
+
|
| 50 |
# Try multiple possible paths
|
| 51 |
possible_paths = [
|
| 52 |
"data/Students Social Media Addiction.csv",
|
| 53 |
"./data/Students Social Media Addiction.csv",
|
| 54 |
"../data/Students Social Media Addiction.csv",
|
| 55 |
+
os.path.join(cwd, "data", "Students Social Media Addiction.csv"),
|
| 56 |
os.path.join(os.path.dirname(__file__), "data", "Students Social Media Addiction.csv")
|
| 57 |
]
|
| 58 |
|
| 59 |
+
# Also try to find any CSV file in data directory
|
| 60 |
+
data_files = glob.glob("data/*.csv")
|
| 61 |
+
print(f"π Found CSV files in data/: {data_files}")
|
| 62 |
+
|
| 63 |
for path in possible_paths:
|
| 64 |
+
print(f"π Trying path: {path}")
|
| 65 |
if os.path.exists(path):
|
| 66 |
+
try:
|
| 67 |
+
self.df = pd.read_csv(path)
|
| 68 |
+
print(f"β
Data loaded from: {path}")
|
| 69 |
+
print(f" Shape: {self.df.shape}")
|
| 70 |
+
print(f" Columns: {list(self.df.columns)}")
|
| 71 |
+
break
|
| 72 |
+
except Exception as e:
|
| 73 |
+
print(f"β Error reading {path}: {e}")
|
| 74 |
+
continue
|
| 75 |
else:
|
| 76 |
+
# If no file found, try to use any CSV in data directory
|
| 77 |
+
if data_files:
|
| 78 |
+
try:
|
| 79 |
+
self.df = pd.read_csv(data_files[0])
|
| 80 |
+
print(f"β
Data loaded from fallback: {data_files[0]}")
|
| 81 |
+
print(f" Shape: {self.df.shape}")
|
| 82 |
+
print(f" Columns: {list(self.df.columns)}")
|
| 83 |
+
except Exception as e:
|
| 84 |
+
print(f"β Error reading fallback file: {e}")
|
| 85 |
+
raise FileNotFoundError("Could not load any data file")
|
| 86 |
+
else:
|
| 87 |
+
raise FileNotFoundError("Could not find the data file in any expected location")
|
| 88 |
|
| 89 |
# Create binary features for categorical variables
|
| 90 |
self.df['Is_Female'] = (self.df['Gender'] == 'Female').astype(int)
|
|
|
|
| 613 |
### Data Source
|
| 614 |
Analysis based on comprehensive student social media usage survey data.
|
| 615 |
""")
|
| 616 |
+
|
| 617 |
# Launch the app
|
| 618 |
if __name__ == "__main__":
|
| 619 |
demo.launch(share=True)
|