Update inference.py
Browse files- inference.py +4 -3
inference.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import torch
|
| 2 |
import json
|
| 3 |
-
import
|
| 4 |
import re
|
| 5 |
import emoji
|
| 6 |
from transformers import BertForSequenceClassification, BertTokenizer
|
|
@@ -24,9 +24,10 @@ def load_model_and_resources():
|
|
| 24 |
except Exception as e:
|
| 25 |
raise RuntimeError(f"Error loading model/tokenizer: {str(e)}")
|
| 26 |
|
| 27 |
-
thresholds_url = f"https://huggingface.co/{repo_id}/raw/main/optimized_thresholds.json"
|
| 28 |
try:
|
| 29 |
-
|
|
|
|
|
|
|
| 30 |
if not (isinstance(thresholds_data, dict) and "emotion_labels" in thresholds_data and "thresholds" in thresholds_data):
|
| 31 |
raise ValueError("Unexpected format in optimized_thresholds.json. Expected a dictionary with keys 'emotion_labels' and 'thresholds'.")
|
| 32 |
emotion_labels = thresholds_data["emotion_labels"]
|
|
|
|
| 1 |
import torch
|
| 2 |
import json
|
| 3 |
+
from huggingface_hub import hf_hub_download
|
| 4 |
import re
|
| 5 |
import emoji
|
| 6 |
from transformers import BertForSequenceClassification, BertTokenizer
|
|
|
|
| 24 |
except Exception as e:
|
| 25 |
raise RuntimeError(f"Error loading model/tokenizer: {str(e)}")
|
| 26 |
|
|
|
|
| 27 |
try:
|
| 28 |
+
thresholds_file = hf_hub_download(repo_id=repo_id, filename="optimized_thresholds.json")
|
| 29 |
+
with open(thresholds_file, "r") as f:
|
| 30 |
+
thresholds_data = json.load(f)
|
| 31 |
if not (isinstance(thresholds_data, dict) and "emotion_labels" in thresholds_data and "thresholds" in thresholds_data):
|
| 32 |
raise ValueError("Unexpected format in optimized_thresholds.json. Expected a dictionary with keys 'emotion_labels' and 'thresholds'.")
|
| 33 |
emotion_labels = thresholds_data["emotion_labels"]
|