Spaces:
Sleeping
Sleeping
import os | |
from dotenv import load_dotenv | |
from transformers import TFBertForSequenceClassification, BertTokenizerFast | |
import tensorflow as tf | |
# Directly specify model and API key | |
MODEL_NAME = "Erfan11/Neuracraft" | |
API_KEY = "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" | |
def load_model(model_name): | |
# Load the TensorFlow model from Hugging Face Hub | |
model = TFBertForSequenceClassification.from_pretrained(model_name, use_auth_token=API_KEY) | |
return model | |
def load_tokenizer(model_name): | |
tokenizer = BertTokenizerFast.from_pretrained(model_name, use_auth_token=API_KEY) | |
return tokenizer | |
def predict(text, model, tokenizer): | |
inputs = tokenizer(text, return_tensors="tf") | |
outputs = model(**inputs) | |
return outputs | |
def main(): | |
model_name = MODEL_NAME | |
model = load_model(model_name) | |
tokenizer = load_tokenizer(model_name) | |
# Example usage | |
text = "Sample input text" | |
result = predict(text, model, tokenizer) | |
print(result) | |
if __name__ == "__main__": | |
main() |