jays009 commited on
Commit
0f694f1
·
verified ·
1 Parent(s): fa3ae41

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -0
app.py CHANGED
@@ -9,6 +9,23 @@ import os
9
  # Define the number of classes
10
  num_classes = 2
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  # Define transformation for image processing
13
  transform = transforms.Compose([
14
  transforms.Resize(256),
 
9
  # Define the number of classes
10
  num_classes = 2
11
 
12
+ # Download model from Hugging Face
13
+ def download_model():
14
+ model_path = hf_hub_download(repo_id="jays009/Restnet50", filename="pytorch_model.bin")
15
+ return model_path
16
+
17
+ # Load the model from Hugging Face
18
+ def load_model(model_path):
19
+ model = models.resnet50(pretrained=False)
20
+ model.fc = nn.Linear(model.fc.in_features, num_classes)
21
+ model.load_state_dict(torch.load(model_path, map_location=torch.device("cpu")))
22
+ model.eval()
23
+ return model
24
+
25
+ # Download the model and load it
26
+ model_path = download_model()
27
+ model = load_model(model_path)
28
+
29
  # Define transformation for image processing
30
  transform = transforms.Compose([
31
  transforms.Resize(256),