leynessa commited on
Commit
8bcdd21
·
verified ·
1 Parent(s): e1abc85

Update streamlit_app.py

Browse files
Files changed (1) hide show
  1. streamlit_app.py +5 -12
streamlit_app.py CHANGED
@@ -25,20 +25,13 @@ except:
25
 
26
  @st.cache_resource
27
  def load_model():
28
- import os
29
- import urllib.request
30
-
31
- MODEL_URL = "https://huggingface.co/spaces/leynessa/libkamaja_id/resolve/main/butterfly_classifier.pth"
32
-
33
-
34
-
35
  MODEL_PATH = "butterfly_classifier.pth"
36
-
37
- # Download if not already present
38
  if not os.path.exists(MODEL_PATH):
39
- st.info("Downloading model...")
40
- urllib.request.urlretrieve(MODEL_URL, MODEL_PATH)
41
-
42
  # Load the model
43
  model = models.resnet18(pretrained=False)
44
  model.fc = torch.nn.Linear(model.fc.in_features, len(class_names))
 
25
 
26
  @st.cache_resource
27
  def load_model():
 
 
 
 
 
 
 
28
  MODEL_PATH = "butterfly_classifier.pth"
29
+
30
+ # Check if model exists locally
31
  if not os.path.exists(MODEL_PATH):
32
+ st.error("Model file not found. Please upload butterfly_classifier.pth to your space.")
33
+ return None
34
+
35
  # Load the model
36
  model = models.resnet18(pretrained=False)
37
  model.fc = torch.nn.Linear(model.fc.in_features, len(class_names))