wintergw commited on
Commit
44eef32
·
verified ·
1 Parent(s): 4ab71dc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -34
app.py CHANGED
@@ -1,43 +1,43 @@
1
- from huggingface_hub import hf_hub_download , snapshot_download
2
- import pandas as pd
3
- import importlib
4
  import importlib.util
5
- import streamlit as st
6
-
7
-
8
-
9
-
10
-
11
- # snapshot_downloading your private space
12
- snapshot_download(
13
- repo_id="wintergw/assignment_opt_gurobi",
14
- repo_type="space",
15
- cache_dir="private_space_cache"
 
16
  )
17
 
 
 
18
 
 
 
 
 
 
 
19
 
20
-
21
-
22
- # calling the app code
23
- app = hf_hub_download(
24
- repo_id="wintergw/assignment_opt_gurobi",
25
- filename="app.py",
26
- repo_type="space"
27
  )
28
 
29
- # executing the app file
30
- spec_app = importlib.util.spec_from_file_location("*",app)
31
- app = importlib.util.module_from_spec(spec_app)
32
- spec_app.loader.exec_module(app)
33
 
 
 
 
 
34
 
35
- #if you call functions from another file “importing files as modules”
36
- functions = hf_hub_download(
37
- repo_id="wintergw/assignment_opt_gurobi",
38
- filename="optmodel.py",
39
- repo_type="space",
40
- )
41
- spec = importlib.util.spec_from_file_location("*", functions)
42
- foo = importlib.util.module_from_spec(spec)
43
- spec.loader.exec_module(foo)
 
1
+ from huggingface_hub import hf_hub_download, snapshot_download
 
 
2
  import importlib.util
3
+ import sys
4
+ import os
5
+
6
+ # Define repo details
7
+ REPO_ID = "wintergw/assignment_opt_gurobi"
8
+ REPO_TYPE = "space"
9
+
10
+ # Download the entire space (optional, if needed)
11
+ repo_dir = snapshot_download(
12
+ repo_id=REPO_ID,
13
+ repo_type=REPO_TYPE,
14
+ cache_dir="private_space_cache"
15
  )
16
 
17
+ # Add repo directory to sys.path so Python can find modules inside it
18
+ sys.path.append(repo_dir)
19
 
20
+ # Download specific files (if snapshot_download wasn't used)
21
+ app_path = hf_hub_download(
22
+ repo_id=REPO_ID,
23
+ filename="app.py",
24
+ repo_type=REPO_TYPE
25
+ )
26
 
27
+ functions_path = hf_hub_download(
28
+ repo_id=REPO_ID,
29
+ filename="optmodel.py",
30
+ repo_type=REPO_TYPE
 
 
 
31
  )
32
 
33
+ # Load and execute `app.py`
34
+ spec_app = importlib.util.spec_from_file_location("app", app_path)
35
+ app_module = importlib.util.module_from_spec(spec_app)
36
+ spec_app.loader.exec_module(app_module)
37
 
38
+ # Load `optmodel.py` as a module
39
+ spec_func = importlib.util.spec_from_file_location("optmodel", functions_path)
40
+ optmodel_module = importlib.util.module_from_spec(spec_func)
41
+ spec_func.loader.exec_module(optmodel_module)
42
 
43
+ # Now, app.py should be able to import optmodel successfully