| from transformers import AutoModelForSequenceClassification,AutoTokenizer | |
| #import tensorflow as tf | |
| #print(tf.__version__) | |
| # replace "path/to/model/directory" with the path to the directory containing the model files | |
| tokenizer = AutoTokenizer.from_pretrained("ALANZI/imamu_arabic_sentimentAnalysis") | |
| model = AutoModelForSequenceClassification.from_pretrained("ALANZI/imamu_arabic_sentimentAnalysis") | |
| def predict_sentiment(text): | |
| # Tokenize input text | |
| inputs = tokenizer(text, return_tensors="pt") | |
| # Pass the tokenized inputs through the model | |
| outputs = model(**inputs) | |
| # Get predicted sentiment | |
| predictions = outputs.logits.argmax(dim=1) | |
| sentiment = "Negative" if predictions.item() == 1 else "Positive" | |
| return sentiment | |