Sadjad Alikhani commited on
Commit
c7b6b77
·
verified ·
1 Parent(s): 759ebd3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -9
app.py CHANGED
@@ -32,16 +32,39 @@ class PrintCapture(io.StringIO):
32
  return ''.join(self.output)
33
 
34
  # Function to load and display predefined images based on user selection
 
 
 
 
 
 
 
 
 
 
 
35
  def display_predefined_images(percentage_idx, complexity_idx):
 
36
  percentage = percentage_values[percentage_idx]
37
  complexity = complexity_values[complexity_idx]
 
 
38
  raw_image_path = os.path.join(RAW_PATH, f"percentage_{percentage}_complexity_{complexity}.png")
39
  embeddings_image_path = os.path.join(EMBEDDINGS_PATH, f"percentage_{percentage}_complexity_{complexity}.png")
40
 
 
 
 
 
 
 
 
41
  raw_image = Image.open(raw_image_path)
42
  embeddings_image = Image.open(embeddings_image_path)
43
 
 
44
  return raw_image, embeddings_image
 
45
 
46
  # Function to load the pre-trained model from your cloned repository
47
  def load_custom_model():
@@ -63,14 +86,14 @@ def process_p_file(uploaded_file, percentage_idx, complexity_idx):
63
  print(f"Cloning model repository from {model_repo_url}...")
64
  subprocess.run(["git", "clone", model_repo_url, model_repo_dir], check=True)
65
 
66
- # Debugging: Check if the directory exists and print contents
67
- if os.path.exists(model_repo_dir):
68
- os.chdir(model_repo_dir)
69
- print(f"Changed working directory to {os.getcwd()}")
70
- print(f"Directory content: {os.listdir(os.getcwd())}") # Debugging: Check repo content
71
- else:
72
- print(f"Directory {model_repo_dir} does not exist.")
73
- return
74
 
75
  ## Step 2: Add the cloned repo to sys.path for imports
76
  #if model_repo_dir not in sys.path:
@@ -78,7 +101,7 @@ def process_p_file(uploaded_file, percentage_idx, complexity_idx):
78
 
79
  ## Debugging: Print sys.path to ensure the cloned repo is in the path
80
  #print(f"sys.path: {sys.path}")
81
- sys.path.append('./')
82
 
83
  from lwm_model import LWM
84
  device = 'cpu'
 
32
  return ''.join(self.output)
33
 
34
  # Function to load and display predefined images based on user selection
35
+ #def display_predefined_images(percentage_idx, complexity_idx):
36
+ # percentage = percentage_values[percentage_idx]
37
+ # complexity = complexity_values[complexity_idx]
38
+ # raw_image_path = os.path.join(RAW_PATH, f"percentage_{percentage}_complexity_{complexity}.png")
39
+ # embeddings_image_path = os.path.join(EMBEDDINGS_PATH, f"percentage_{percentage}_complexity_{complexity}.png")
40
+
41
+ # raw_image = Image.open(raw_image_path)
42
+ # embeddings_image = Image.open(embeddings_image_path)
43
+
44
+ # return raw_image, embeddings_image
45
+
46
  def display_predefined_images(percentage_idx, complexity_idx):
47
+ # Map the slider index to the actual value
48
  percentage = percentage_values[percentage_idx]
49
  complexity = complexity_values[complexity_idx]
50
+
51
+ # Generate the paths to the images
52
  raw_image_path = os.path.join(RAW_PATH, f"percentage_{percentage}_complexity_{complexity}.png")
53
  embeddings_image_path = os.path.join(EMBEDDINGS_PATH, f"percentage_{percentage}_complexity_{complexity}.png")
54
 
55
+ # Check if the images exist
56
+ if not os.path.exists(raw_image_path):
57
+ return None, None # Or handle the error appropriately
58
+ if not os.path.exists(embeddings_image_path):
59
+ return None, None # Or handle the error appropriately
60
+
61
+ # Load images using PIL
62
  raw_image = Image.open(raw_image_path)
63
  embeddings_image = Image.open(embeddings_image_path)
64
 
65
+ # Return the loaded images
66
  return raw_image, embeddings_image
67
+
68
 
69
  # Function to load the pre-trained model from your cloned repository
70
  def load_custom_model():
 
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()}")
93
+ # print(f"Directory content: {os.listdir(os.getcwd())}") # Debugging: Check repo content
94
+ #else:
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:
 
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
  from lwm_model import LWM
107
  device = 'cpu'