Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -44,6 +44,20 @@ os.chdir(repo_dir)
|
|
| 44 |
# # Add repo directory to sys.path so Python can find modules inside it
|
| 45 |
sys.path.append(repo_dir)
|
| 46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
# Download specific files (if snapshot_download wasn't used)
|
| 49 |
# app_path = hf_hub_download(
|
|
@@ -52,9 +66,9 @@ sys.path.append(repo_dir)
|
|
| 52 |
# repo_type=REPO_TYPE
|
| 53 |
# )
|
| 54 |
|
| 55 |
-
# Load and execute `app.py`
|
| 56 |
-
spec_app = importlib.util.spec_from_file_location("*", repo_dir)
|
| 57 |
-
app_module = importlib.util.module_from_spec(spec_app)
|
| 58 |
-
spec_app.loader.exec_module(app_module)
|
| 59 |
-
# Now you can use functions from utils_module
|
| 60 |
-
result = app_module.main()
|
|
|
|
| 44 |
# # Add repo directory to sys.path so Python can find modules inside it
|
| 45 |
sys.path.append(repo_dir)
|
| 46 |
|
| 47 |
+
# Ensure the correct path to app.py
|
| 48 |
+
app_path = os.path.join(repo_dir, "app.py")
|
| 49 |
+
if not os.path.exists(app_path):
|
| 50 |
+
raise FileNotFoundError(f"app.py not found in {repo_dir}")
|
| 51 |
+
|
| 52 |
+
# Load and execute `app.py`
|
| 53 |
+
spec_app = importlib.util.spec_from_file_location("app", app_path)
|
| 54 |
+
if spec_app is None or spec_app.loader is None:
|
| 55 |
+
raise ImportError(f"Could not load module from {app_path}")
|
| 56 |
+
|
| 57 |
+
app_module = importlib.util.module_from_spec(spec_app)
|
| 58 |
+
spec_app.loader.exec_module(app_module)
|
| 59 |
+
|
| 60 |
+
|
| 61 |
|
| 62 |
# Download specific files (if snapshot_download wasn't used)
|
| 63 |
# app_path = hf_hub_download(
|
|
|
|
| 66 |
# repo_type=REPO_TYPE
|
| 67 |
# )
|
| 68 |
|
| 69 |
+
# # Load and execute `app.py`
|
| 70 |
+
# spec_app = importlib.util.spec_from_file_location("*", repo_dir)
|
| 71 |
+
# app_module = importlib.util.module_from_spec(spec_app)
|
| 72 |
+
# spec_app.loader.exec_module(app_module)
|
| 73 |
+
# # Now you can use functions from utils_module
|
| 74 |
+
# result = app_module.main()
|