Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,32 +7,30 @@ from pdf2image import convert_from_path
|
|
| 7 |
|
| 8 |
logging.basicConfig(level=logging.INFO)
|
| 9 |
|
| 10 |
-
# Name of the default CSV file.
|
| 11 |
DEFAULT_CSV = "default.csv"
|
| 12 |
-
cwd = os.getcwd()
|
| 13 |
-
logging.info(f"Working directory: {cwd}")
|
| 14 |
-
|
| 15 |
-
if not os.path.isfile(DEFAULT_CSV):
|
| 16 |
-
logging.info(f"{DEFAULT_CSV} not found. Creating a default CSV file.")
|
| 17 |
-
with open(DEFAULT_CSV, "w") as f:
|
| 18 |
-
f.write("Name,Role,Reporting To\nAlice,CEO,\nBob,Manager,Alice\nCharlie,Engineer,Bob")
|
| 19 |
|
| 20 |
def load_csv(file):
|
| 21 |
"""
|
| 22 |
-
|
| 23 |
-
|
| 24 |
"""
|
| 25 |
cwd = os.getcwd()
|
| 26 |
logging.info(f"load_csv received: {file}")
|
| 27 |
-
|
| 28 |
-
|
|
|
|
| 29 |
logging.info("No valid file provided; using default CSV.")
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
if os.path.isfile(file):
|
| 33 |
logging.info(f"Loading uploaded CSV: {file}")
|
| 34 |
return pd.read_csv(file)
|
| 35 |
-
|
| 36 |
logging.warning(f"Provided file path '{file}' is not valid. Using default CSV.")
|
| 37 |
return pd.read_csv(DEFAULT_CSV)
|
| 38 |
|
|
|
|
| 7 |
|
| 8 |
logging.basicConfig(level=logging.INFO)
|
| 9 |
|
| 10 |
+
# Name of the default CSV file. Ensure this file exists in your repository.
|
| 11 |
DEFAULT_CSV = "default.csv"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
def load_csv(file):
|
| 14 |
"""
|
| 15 |
+
Load a CSV file from the given file path.
|
| 16 |
+
If the file is missing, empty, or is a directory, load the default CSV.
|
| 17 |
"""
|
| 18 |
cwd = os.getcwd()
|
| 19 |
logging.info(f"load_csv received: {file}")
|
| 20 |
+
|
| 21 |
+
# If file is empty, None, or a directory, use the default CSV.
|
| 22 |
+
if not file or file.strip() == "" or os.path.isdir(file) or os.path.abspath(file) == cwd:
|
| 23 |
logging.info("No valid file provided; using default CSV.")
|
| 24 |
+
if os.path.isfile(DEFAULT_CSV):
|
| 25 |
+
return pd.read_csv(DEFAULT_CSV)
|
| 26 |
+
else:
|
| 27 |
+
raise FileNotFoundError("Default CSV not found.")
|
| 28 |
+
|
| 29 |
+
# If the file exists and is not a directory, load it.
|
| 30 |
if os.path.isfile(file):
|
| 31 |
logging.info(f"Loading uploaded CSV: {file}")
|
| 32 |
return pd.read_csv(file)
|
| 33 |
+
|
| 34 |
logging.warning(f"Provided file path '{file}' is not valid. Using default CSV.")
|
| 35 |
return pd.read_csv(DEFAULT_CSV)
|
| 36 |
|