在space中添加了环境变量token用于访问模型,还是报错
Browse files
app.py
CHANGED
|
@@ -2,10 +2,6 @@ import streamlit as st
|
|
| 2 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 3 |
import torch
|
| 4 |
import os
|
| 5 |
-
# from huggingface_hub import login
|
| 6 |
-
#
|
| 7 |
-
# login()
|
| 8 |
-
# 加载模型和tokenizer
|
| 9 |
from transformers import AutoTokenizer, AutoModel
|
| 10 |
|
| 11 |
# Assuming you have set the HF_TOKEN environment variable with your Hugging Face token
|
|
@@ -14,11 +10,13 @@ huggingface_token = os.getenv('HF_TOKEN')
|
|
| 14 |
# Set up the token to use with the Hugging Face API
|
| 15 |
if huggingface_token is not None:
|
| 16 |
os.environ['HUGGINGFACE_CO_API_TOKEN'] = huggingface_token
|
|
|
|
|
|
|
|
|
|
| 17 |
else:
|
| 18 |
print("error, no token")
|
| 19 |
exit(0)
|
| 20 |
-
|
| 21 |
-
model = AutoModelForSequenceClassification.from_pretrained("Tokymin/Mood_Anxiety_Disorder_Classify_Model", num_labels=8)
|
| 22 |
model.eval()
|
| 23 |
|
| 24 |
def predict(text):
|
|
|
|
| 2 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 3 |
import torch
|
| 4 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
from transformers import AutoTokenizer, AutoModel
|
| 6 |
|
| 7 |
# Assuming you have set the HF_TOKEN environment variable with your Hugging Face token
|
|
|
|
| 10 |
# Set up the token to use with the Hugging Face API
|
| 11 |
if huggingface_token is not None:
|
| 12 |
os.environ['HUGGINGFACE_CO_API_TOKEN'] = huggingface_token
|
| 13 |
+
tokenizer = AutoTokenizer.from_pretrained("Tokymin/Mood_Anxiety_Disorder_Classify_Model")
|
| 14 |
+
model = AutoModelForSequenceClassification.from_pretrained("Tokymin/Mood_Anxiety_Disorder_Classify_Model",
|
| 15 |
+
num_labels=8)
|
| 16 |
else:
|
| 17 |
print("error, no token")
|
| 18 |
exit(0)
|
| 19 |
+
|
|
|
|
| 20 |
model.eval()
|
| 21 |
|
| 22 |
def predict(text):
|