Spaces:
Sleeping
Sleeping
Pretrained cache directory
Browse files
main.py
CHANGED
@@ -7,14 +7,15 @@ import os
|
|
7 |
|
8 |
app = FastAPI()
|
9 |
os.environ["HF_HOME"] = "/tmp/huggingface"
|
|
|
10 |
os.makedirs(os.environ["HF_HOME"], exist_ok=True)
|
11 |
|
12 |
model_path = hf_hub_download(repo_id="MienOlle/sentiment_analysis_api",
|
13 |
filename="sentimentAnalysis.pth",
|
14 |
cache_dir=os.environ["HF_HOME"]
|
15 |
)
|
16 |
-
modelToken = token.from_pretrained("mdhugol/indonesia-bert-sentiment-classification")
|
17 |
-
model = modelSC.from_pretrained("mdhugol/indonesia-bert-sentiment-classification", num_labels=3)
|
18 |
|
19 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
20 |
model.load_state_dict(torch.load(model_path, map_location=torch.device(device)))
|
|
|
7 |
|
8 |
app = FastAPI()
|
9 |
os.environ["HF_HOME"] = "/tmp/huggingface"
|
10 |
+
os.environ["TRANSFORMERS_CACHE"] = "/tmp/huggingface"
|
11 |
os.makedirs(os.environ["HF_HOME"], exist_ok=True)
|
12 |
|
13 |
model_path = hf_hub_download(repo_id="MienOlle/sentiment_analysis_api",
|
14 |
filename="sentimentAnalysis.pth",
|
15 |
cache_dir=os.environ["HF_HOME"]
|
16 |
)
|
17 |
+
modelToken = token.from_pretrained("mdhugol/indonesia-bert-sentiment-classification", cache_dir=os.environ["TRANSFORMERS_CACHE"])
|
18 |
+
model = modelSC.from_pretrained("mdhugol/indonesia-bert-sentiment-classification", num_labels=3, cache_dir=os.environ["TRANSFORMERS_CACHE"])
|
19 |
|
20 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
21 |
model.load_state_dict(torch.load(model_path, map_location=torch.device(device)))
|