File size: 1,113 Bytes
9a6b849
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6060814
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import os
from dotenv import load_dotenv
import torch
from transformers import AutoModelForSequenceClassification, AutoTokenizer

# Load environment variables
load_dotenv()

def load_model(model_path):
    model = AutoModelForSequenceClassification.from_pretrained(model_path)
    tokenizer = AutoTokenizer.from_pretrained(model_path)
    return model, tokenizer

def predict(text, model, tokenizer):
    inputs = tokenizer(text, return_tensors="pt")
    outputs = model(**inputs)
    return outputs

def main():
    model_path = os.getenv('MODEL_PATH')
    model, tokenizer = load_model(model_path)
    # Example usage
    text = "Sample input text"
    result = predict(text, model, tokenizer)
    print(result)

if __name__ == "__main__":
    main()
    from transformers import BertForSequenceClassification

# Load the TensorFlow model using from_tf=True
model = BertForSequenceClassification.from_pretrained(
    "Erfan11/Neuracraft", 
    from_tf=True, 
    use_auth_token="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"
)

# Additional code to run your app can go here (for example, Streamlit or Gradio interface)