Sadjad Alikhani commited on
Commit
9185ad4
·
verified ·
1 Parent(s): 7edd1d9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -8
app.py CHANGED
@@ -82,11 +82,12 @@ def process_p_file(uploaded_file, percentage_idx, complexity_idx):
82
  model_repo_url = "https://huggingface.co/sadjadalikhani/LWM"
83
  model_repo_dir = "./LWM"
84
 
 
85
  if not os.path.exists(model_repo_dir):
86
  print(f"Cloning model repository from {model_repo_url}...")
87
  subprocess.run(["git", "clone", model_repo_url, model_repo_dir], check=True)
88
 
89
- ## Debugging: Check if the directory exists and print contents
90
  if os.path.exists(model_repo_dir):
91
  os.chdir(model_repo_dir)
92
  print(f"Changed working directory to {os.getcwd()}")
@@ -95,30 +96,40 @@ def process_p_file(uploaded_file, percentage_idx, complexity_idx):
95
  print(f"Directory {model_repo_dir} does not exist.")
96
  return
97
 
98
- # Step 2: Add the cloned repo to sys.path for imports
99
  if model_repo_dir not in sys.path:
100
  sys.path.append(model_repo_dir)
101
-
102
- # Debugging: Print sys.path to ensure the cloned repo is in the path
103
  print(f"sys.path: {sys.path}")
104
- #sys.path.append('./')
105
-
106
  lwm_model_dir = os.path.join(os.getcwd(), 'LWM')
107
  if lwm_model_dir not in sys.path:
108
  sys.path.append(lwm_model_dir)
109
-
 
 
 
 
 
 
 
 
 
110
  from lwm_model import LWM
111
  device = 'cpu'
112
  print(f"Loading the LWM model on {device}...")
113
  model = LWM.from_pretrained(device=device)
114
 
 
115
  from input_preprocess import tokenizer
116
-
117
  with open(uploaded_file.name, 'rb') as f:
118
  manual_data = pickle.load(f)
119
 
120
  preprocessed_chs = tokenizer(manual_data=manual_data)
121
 
 
122
  from inference import lwm_inference, create_raw_dataset
123
  output_emb = lwm_inference(preprocessed_chs, 'channel_emb', model)
124
  output_raw = create_raw_dataset(preprocessed_chs, device)
 
82
  model_repo_url = "https://huggingface.co/sadjadalikhani/LWM"
83
  model_repo_dir = "./LWM"
84
 
85
+ # Step 1: Clone the repository if not already done
86
  if not os.path.exists(model_repo_dir):
87
  print(f"Cloning model repository from {model_repo_url}...")
88
  subprocess.run(["git", "clone", model_repo_url, model_repo_dir], check=True)
89
 
90
+ # Step 2: Verify the repository was cloned
91
  if os.path.exists(model_repo_dir):
92
  os.chdir(model_repo_dir)
93
  print(f"Changed working directory to {os.getcwd()}")
 
96
  print(f"Directory {model_repo_dir} does not exist.")
97
  return
98
 
99
+ # Step 3: Add the cloned repo to sys.path for imports
100
  if model_repo_dir not in sys.path:
101
  sys.path.append(model_repo_dir)
102
+
103
+ # Step 4: Debugging - Print sys.path to ensure the cloned repo is in the path
104
  print(f"sys.path: {sys.path}")
105
+
106
+ # Ensure the 'LWM' directory is in the path
107
  lwm_model_dir = os.path.join(os.getcwd(), 'LWM')
108
  if lwm_model_dir not in sys.path:
109
  sys.path.append(lwm_model_dir)
110
+
111
+ # Step 5: Verify if lwm_model.py exists in the directory
112
+ lwm_model_path = os.path.join(lwm_model_dir, 'lwm_model.py')
113
+ if not os.path.exists(lwm_model_path):
114
+ print(f"Error: lwm_model.py not found at {lwm_model_path}")
115
+ return f"Error: lwm_model.py not found at {lwm_model_path}"
116
+ else:
117
+ print(f"lwm_model.py found at {lwm_model_path}")
118
+
119
+ # Step 6: Import lwm_model after ensuring path is set
120
  from lwm_model import LWM
121
  device = 'cpu'
122
  print(f"Loading the LWM model on {device}...")
123
  model = LWM.from_pretrained(device=device)
124
 
125
+ # Step 7: Import tokenizer and load data
126
  from input_preprocess import tokenizer
 
127
  with open(uploaded_file.name, 'rb') as f:
128
  manual_data = pickle.load(f)
129
 
130
  preprocessed_chs = tokenizer(manual_data=manual_data)
131
 
132
+ # Step 8: Perform inference
133
  from inference import lwm_inference, create_raw_dataset
134
  output_emb = lwm_inference(preprocessed_chs, 'channel_emb', model)
135
  output_raw = create_raw_dataset(preprocessed_chs, device)