Spaces:
Running
Running
pri2k
commited on
Commit
·
face833
1
Parent(s):
19cae7d
Add HF token login
Browse files
app.py
CHANGED
@@ -1,11 +1,20 @@
|
|
1 |
-
from fastapi import FastAPI
|
2 |
from pydantic import BaseModel
|
3 |
from sentence_transformers import SentenceTransformer
|
4 |
import torch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
app = FastAPI()
|
7 |
|
8 |
-
model = SentenceTransformer("mental/mental-bert-base-uncased")
|
9 |
|
10 |
class InputText(BaseModel):
|
11 |
text: str
|
|
|
1 |
+
from fastapi import FastAPI
|
2 |
from pydantic import BaseModel
|
3 |
from sentence_transformers import SentenceTransformer
|
4 |
import torch
|
5 |
+
import os
|
6 |
+
from huggingface_hub import login
|
7 |
+
|
8 |
+
# Log in using the HF_TOKEN environment variable
|
9 |
+
hf_token = os.getenv("HF_TOKEN")
|
10 |
+
if hf_token:
|
11 |
+
login(token=hf_token)
|
12 |
+
else:
|
13 |
+
raise ValueError("HF_TOKEN not found. Make sure it's set in your Space variables.")
|
14 |
|
15 |
app = FastAPI()
|
16 |
|
17 |
+
model = SentenceTransformer("mental/mental-bert-base-uncased")
|
18 |
|
19 |
class InputText(BaseModel):
|
20 |
text: str
|