Spaces:
Sleeping
Sleeping
add login from huggingface_hub to use prompt guard model
Browse files
helper.py
CHANGED
@@ -41,7 +41,7 @@ def load_env():
|
|
41 |
def get_huggingface_api_key():
|
42 |
load_env()
|
43 |
huggingface_api_key = os.getenv("HUGGINGFACE_API_KEY")
|
44 |
-
|
45 |
if not huggingface_api_key:
|
46 |
logging.error("HUGGINGFACE_API_KEY not found in environment variables")
|
47 |
raise ValueError("HUGGINGFACE_API_KEY not found in environment variables")
|
@@ -115,11 +115,10 @@ def initialize_prompt_guard():
|
|
115 |
"""Initialize Prompt Guard model"""
|
116 |
try:
|
117 |
api_key = get_huggingface_api_key()
|
118 |
-
|
119 |
-
|
120 |
-
)
|
121 |
model = AutoModelForSequenceClassification.from_pretrained(
|
122 |
-
PROMPT_GUARD_CONFIG["model_id"]
|
123 |
)
|
124 |
return model, tokenizer
|
125 |
except Exception as e:
|
|
|
41 |
def get_huggingface_api_key():
|
42 |
load_env()
|
43 |
huggingface_api_key = os.getenv("HUGGINGFACE_API_KEY")
|
44 |
+
|
45 |
if not huggingface_api_key:
|
46 |
logging.error("HUGGINGFACE_API_KEY not found in environment variables")
|
47 |
raise ValueError("HUGGINGFACE_API_KEY not found in environment variables")
|
|
|
115 |
"""Initialize Prompt Guard model"""
|
116 |
try:
|
117 |
api_key = get_huggingface_api_key()
|
118 |
+
login(token=api_key)
|
119 |
+
tokenizer = AutoTokenizer.from_pretrained(PROMPT_GUARD_CONFIG["model_id"])
|
|
|
120 |
model = AutoModelForSequenceClassification.from_pretrained(
|
121 |
+
PROMPT_GUARD_CONFIG["model_id"]
|
122 |
)
|
123 |
return model, tokenizer
|
124 |
except Exception as e:
|