Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -44,38 +44,17 @@ 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 |
-
# Now you can directly load and execute `app.py` from the snapshot directory
|
| 48 |
-
|
| 49 |
-
# List all files in the repo_dir to check where app.py is located
|
| 50 |
-
print(f"Files in downloaded repo directory: {os.listdir(repo_dir)}")
|
| 51 |
-
|
| 52 |
-
# Check if the app.py file exists
|
| 53 |
-
app_path = os.path.join(repo_dir, 'app.py')
|
| 54 |
-
if not os.path.exists(app_path):
|
| 55 |
-
print(f"Error: {app_path} does not exist.")
|
| 56 |
-
# You can also print out subdirectories if app.py is in a subfolder
|
| 57 |
-
subdirectories = [d for d in os.listdir(repo_dir) if os.path.isdir(os.path.join(repo_dir, d))]
|
| 58 |
-
print(f"Subdirectories in repo: {subdirectories}")
|
| 59 |
-
else:
|
| 60 |
-
# Load and execute `app.py`
|
| 61 |
-
spec_app = importlib.util.spec_from_file_location("*", app_path)
|
| 62 |
-
app_module = importlib.util.module_from_spec(spec_app)
|
| 63 |
-
spec_app.loader.exec_module(app_module)
|
| 64 |
-
|
| 65 |
-
# Now you can use functions from the app_module
|
| 66 |
-
result = app_module.main()
|
| 67 |
-
|
| 68 |
|
| 69 |
# Download specific files (if snapshot_download wasn't used)
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
|
| 76 |
-
#
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
#
|
| 81 |
-
|
|
|
|
| 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(
|
| 50 |
+
repo_id=REPO_ID,
|
| 51 |
+
filename="app.py",
|
| 52 |
+
repo_type=REPO_TYPE
|
| 53 |
+
)
|
| 54 |
|
| 55 |
+
# Load and execute `app.py`
|
| 56 |
+
spec_app = importlib.util.spec_from_file_location("*", app_path)
|
| 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()
|