Spaces:
Build error
Build error
Trang Dang
commited on
Commit
•
70f7a82
1
Parent(s):
199a681
test
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
from pathlib import Path
|
2 |
from typing import List, Dict, Tuple
|
3 |
import matplotlib.colors as mpl_colors
|
4 |
-
|
5 |
import pandas as pd
|
6 |
import seaborn as sns
|
7 |
import shinyswatch
|
@@ -47,9 +47,15 @@ def server(input: Inputs, output: Outputs, session: Session):
|
|
47 |
src = input.image_input()[0]['datapath']
|
48 |
img = {"src": src, "width": "500px"}
|
49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
# Load the model configuration
|
51 |
-
model_config = SamConfig.from_pretrained("facebook/sam-vit-base"
|
52 |
-
processor = SamProcessor.from_pretrained("facebook/sam-vit-base"
|
53 |
|
54 |
# Create an instance of the model architecture with the loaded configuration
|
55 |
my_sam_model = SamModel(config=model_config)
|
|
|
1 |
from pathlib import Path
|
2 |
from typing import List, Dict, Tuple
|
3 |
import matplotlib.colors as mpl_colors
|
4 |
+
import os
|
5 |
import pandas as pd
|
6 |
import seaborn as sns
|
7 |
import shinyswatch
|
|
|
47 |
src = input.image_input()[0]['datapath']
|
48 |
img = {"src": src, "width": "500px"}
|
49 |
|
50 |
+
# Specify the cache directory
|
51 |
+
transformers_cache_dir = "/usr/local/lib/python3.9/site-packages/transformers"
|
52 |
+
|
53 |
+
# Set the TRANSFORMERS_CACHE environment variable
|
54 |
+
os.environ["TRANSFORMERS_CACHE"] = transformers_cache_dir
|
55 |
+
|
56 |
# Load the model configuration
|
57 |
+
model_config = SamConfig.from_pretrained("facebook/sam-vit-base")
|
58 |
+
processor = SamProcessor.from_pretrained("facebook/sam-vit-base")
|
59 |
|
60 |
# Create an instance of the model architecture with the loaded configuration
|
61 |
my_sam_model = SamModel(config=model_config)
|
run.py
CHANGED
@@ -1,19 +1,26 @@
|
|
1 |
-
from transformers import SamModel, SamConfig, SamProcessor
|
2 |
-
import torch
|
3 |
-
import numpy as np
|
4 |
-
import matplotlib.pyplot as plt
|
5 |
-
import app
|
6 |
|
7 |
-
# Load the model configuration
|
8 |
-
model_config = SamConfig.from_pretrained("facebook/sam-vit-base")
|
9 |
-
processor = SamProcessor.from_pretrained("facebook/sam-vit-base")
|
10 |
|
11 |
-
# Create an instance of the model architecture with the loaded configuration
|
12 |
-
my_sam_model = SamModel(config=model_config)
|
13 |
-
#Update the model by loading the weights from saved file.
|
14 |
-
my_sam_model.load_state_dict(torch.load("sam_model.pth", map_location=torch.device('cpu')))
|
15 |
|
16 |
|
17 |
# load image
|
18 |
# test_image = {"src": src, "width": "500px"}
|
19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# from transformers import SamModel, SamConfig, SamProcessor
|
2 |
+
# import torch
|
3 |
+
# import numpy as np
|
4 |
+
# import matplotlib.pyplot as plt
|
5 |
+
# import app
|
6 |
|
7 |
+
# # Load the model configuration
|
8 |
+
# model_config = SamConfig.from_pretrained("facebook/sam-vit-base")
|
9 |
+
# processor = SamProcessor.from_pretrained("facebook/sam-vit-base")
|
10 |
|
11 |
+
# # Create an instance of the model architecture with the loaded configuration
|
12 |
+
# my_sam_model = SamModel(config=model_config)
|
13 |
+
# #Update the model by loading the weights from saved file.
|
14 |
+
# my_sam_model.load_state_dict(torch.load("sam_model.pth", map_location=torch.device('cpu')))
|
15 |
|
16 |
|
17 |
# load image
|
18 |
# test_image = {"src": src, "width": "500px"}
|
19 |
|
20 |
+
import os
|
21 |
+
|
22 |
+
# Specify the cache directory
|
23 |
+
transformers_cache_dir = "/usr/local/lib/python3.9/site-packages/transformers"
|
24 |
+
|
25 |
+
# Set the TRANSFORMERS_CACHE environment variable
|
26 |
+
os.environ["TRANSFORMERS_CACHE"] = transformers_cache_dir
|