Spaces:
Runtime error
Runtime error
Hoang Kha
commited on
Commit
·
3add779
1
Parent(s):
b608f06
disable huggingface cache completely for Spaces
Browse files- Dockerfile +1 -2
- main.py +20 -10
Dockerfile
CHANGED
|
@@ -9,7 +9,6 @@ RUN pip install --no-cache-dir -r requirements.txt
|
|
| 9 |
|
| 10 |
EXPOSE 7860
|
| 11 |
|
| 12 |
-
ENV
|
| 13 |
-
RUN mkdir -p /home/user/.cache/huggingface
|
| 14 |
|
| 15 |
CMD ["python", "main.py"]
|
|
|
|
| 9 |
|
| 10 |
EXPOSE 7860
|
| 11 |
|
| 12 |
+
ENV HF_HUB_DISABLE_CACHE=1
|
|
|
|
| 13 |
|
| 14 |
CMD ["python", "main.py"]
|
main.py
CHANGED
|
@@ -4,9 +4,9 @@ from langdetect import detect
|
|
| 4 |
import torch
|
| 5 |
import torch.nn.functional as F
|
| 6 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
|
| 7 |
-
|
| 8 |
-
os.
|
| 9 |
-
os.environ["
|
| 10 |
|
| 11 |
app = Flask(__name__)
|
| 12 |
|
|
@@ -20,17 +20,27 @@ device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
| 20 |
# vi_tokenizer = AutoTokenizer.from_pretrained(VI_MODEL_NAME, use_fast=False)
|
| 21 |
# vi_model = AutoModelForSequenceClassification.from_pretrained(VI_MODEL_NAME).to(device)
|
| 22 |
# vi_model.eval()
|
| 23 |
-
vi_tokenizer = AutoTokenizer.from_pretrained(VI_MODEL_NAME, use_fast=False)
|
| 24 |
-
vi_model = AutoModelForSequenceClassification.from_pretrained(VI_MODEL_NAME)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
vi_model.eval()
|
| 26 |
sentiment_pipeline = pipeline("sentiment-analysis", model=vi_model, tokenizer=vi_tokenizer)
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
en_model = AutoModelForSequenceClassification.from_pretrained(EN_MODEL_NAME).to(device)
|
| 32 |
en_model.eval()
|
| 33 |
-
|
| 34 |
# Label mapping cho PhoBERT
|
| 35 |
vi_label_map = {
|
| 36 |
0: ("NEGATIVE", "Tiêu cực"),
|
|
|
|
| 4 |
import torch
|
| 5 |
import torch.nn.functional as F
|
| 6 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
|
| 7 |
+
os.environ["HF_HUB_DISABLE_SYMLINKS_WARNING"] = "1"
|
| 8 |
+
os.environ["TRANSFORMERS_OFFLINE"] = "0"
|
| 9 |
+
os.environ["HF_HUB_DISABLE_CACHE"] = "1"
|
| 10 |
|
| 11 |
app = Flask(__name__)
|
| 12 |
|
|
|
|
| 20 |
# vi_tokenizer = AutoTokenizer.from_pretrained(VI_MODEL_NAME, use_fast=False)
|
| 21 |
# vi_model = AutoModelForSequenceClassification.from_pretrained(VI_MODEL_NAME).to(device)
|
| 22 |
# vi_model.eval()
|
| 23 |
+
# vi_tokenizer = AutoTokenizer.from_pretrained(VI_MODEL_NAME, use_fast=False)
|
| 24 |
+
# vi_model = AutoModelForSequenceClassification.from_pretrained(VI_MODEL_NAME)
|
| 25 |
+
# vi_model.eval()
|
| 26 |
+
# sentiment_pipeline = pipeline("sentiment-analysis", model=vi_model, tokenizer=vi_tokenizer)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
# # English model
|
| 30 |
+
# en_tokenizer = AutoTokenizer.from_pretrained(EN_MODEL_NAME)
|
| 31 |
+
# en_model = AutoModelForSequenceClassification.from_pretrained(EN_MODEL_NAME).to(device)
|
| 32 |
+
# en_model.eval()
|
| 33 |
+
|
| 34 |
+
print("🔄 Loading Vietnamese model from Hugging Face Hub (no cache)...")
|
| 35 |
+
vi_tokenizer = AutoTokenizer.from_pretrained(VI_MODEL_NAME, use_fast=False, local_files_only=False)
|
| 36 |
+
vi_model = AutoModelForSequenceClassification.from_pretrained(VI_MODEL_NAME, local_files_only=False)
|
| 37 |
vi_model.eval()
|
| 38 |
sentiment_pipeline = pipeline("sentiment-analysis", model=vi_model, tokenizer=vi_tokenizer)
|
| 39 |
|
| 40 |
+
print("🔄 Loading English model from Hugging Face Hub (no cache)...")
|
| 41 |
+
en_tokenizer = AutoTokenizer.from_pretrained(EN_MODEL_NAME, local_files_only=False)
|
| 42 |
+
en_model = AutoModelForSequenceClassification.from_pretrained(EN_MODEL_NAME, local_files_only=False)
|
|
|
|
| 43 |
en_model.eval()
|
|
|
|
| 44 |
# Label mapping cho PhoBERT
|
| 45 |
vi_label_map = {
|
| 46 |
0: ("NEGATIVE", "Tiêu cực"),
|