kishoreb4 commited on
Commit
15d674e
·
1 Parent(s): e8dad3c
Files changed (1) hide show
  1. app.py +7 -20
app.py CHANGED
@@ -27,33 +27,20 @@ STD = tf.constant([0.229, 0.224, 0.225])
27
  ID2LABEL = {0: "background", 1: "border", 2: "foreground/pet"}
28
  NUM_CLASSES = len(ID2LABEL)
29
 
 
30
  @st.cache_resource
31
  def download_model_from_drive():
32
- """
33
- Download model from Google Drive and return the local path.
34
- """
35
- model_dir = os.path.join("models", "saved_models")
36
- os.makedirs(model_dir, exist_ok=True)
37
- model_path = os.path.join(model_dir, "segformer_model")
38
-
39
- # Google Drive file ID
40
- file_id = "1XObpqG8qZ7YUyiRKbpVvxX11yQSK8Y_3"
41
- url = f"https://drive.google.com/uc?id={file_id}"
42
-
43
- if not os.path.exists(model_path):
44
  try:
45
- # Use gdown to download the file
46
- with st.spinner("Downloading model from Google Drive..."):
47
- gdown.download(url, model_path, quiet=False)
48
- if not os.path.exists(model_path) or os.path.getsize(model_path) == 0:
49
- raise Exception("Downloaded file is empty or missing.")
50
- st.success("Model downloaded successfully!")
51
  except Exception as e:
52
- st.error(f"Error downloading model: {e}")
53
  return None
54
  else:
55
  st.info("Model already exists locally.")
56
-
57
  return model_path
58
 
59
  @st.cache_resource
 
27
  ID2LABEL = {0: "background", 1: "border", 2: "foreground/pet"}
28
  NUM_CLASSES = len(ID2LABEL)
29
 
30
+
31
  @st.cache_resource
32
  def download_model_from_drive():
33
+ model_path = "tf_model.h5"
34
+ if not os.path.exists(model_path):
35
+ url = "https://drive.google.com/file/d/1XObpqG8qZ7YUyiRKbpVvxX11yQSK8Y_3/view?usp=sharing"
 
 
 
 
 
 
 
 
 
36
  try:
37
+ gdown.download(url, model_path, quiet=False)
38
+ st.success("Model downloaded successfully from Google Drive.")
 
 
 
 
39
  except Exception as e:
40
+ st.error(f"Failed to download model: {e}")
41
  return None
42
  else:
43
  st.info("Model already exists locally.")
 
44
  return model_path
45
 
46
  @st.cache_resource