wintergw commited on
Commit
0d3c617
·
verified ·
1 Parent(s): 9453ee0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -10
app.py CHANGED
@@ -44,18 +44,33 @@ 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(
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
 
60
  # Now you can use functions from utils_module
61
  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
+ # Now you can directly load and execute `app.py` from the snapshot directory
48
+ app_path = os.path.join(repo_dir, 'app.py')
49
 
50
+ # Check if app.py exists in the directory
51
+ if os.path.exists(app_path):
52
+ # Load and execute `app.py`
53
+ spec_app = importlib.util.spec_from_file_location("*", app_path)
54
+ app_module = importlib.util.module_from_spec(spec_app)
55
+ spec_app.loader.exec_module(app_module)
56
 
57
+ # Now you can use functions from the app_module
58
+ result = app_module.main()
59
+ else:
60
+ print(f"Error: {app_path} does not exist.")
61
+
62
+
63
+ # Download specific files (if snapshot_download wasn't used)
64
+ # app_path = hf_hub_download(
65
+ # repo_id=REPO_ID,
66
+ # filename="app.py",
67
+ # repo_type=REPO_TYPE
68
+ # )
69
+
70
+ # # Load and execute `app.py`
71
+ # spec_app = importlib.util.spec_from_file_location("*", app_path)
72
+ # app_module = importlib.util.module_from_spec(spec_app)
73
+ # spec_app.loader.exec_module(app_module)
74
 
75
  # Now you can use functions from utils_module
76
  result = app_module.main()