Spaces:
Runtime error
Runtime error
from transformers import AutoConfig, AutoModelForSequenceClassification, AutoTokenizer | |
import numpy as np | |
import gradio as gr | |
tokenizer = AutoTokenizer.from_pretrained("PRAli22/AraBert-Arabic-Sentiment-Analysis" ) | |
model = AutoModelForSequenceClassification.from_pretrained("PRAli22/AraBert-Arabic-Sentiment-Analysis") | |
def classify_sentiment(text): | |
# Tokenize the text | |
inputs = tokenizer(text, return_tensors="pt") | |
# Get model predictions | |
outputs = model(**inputs) | |
predicted_label_index = np.argmax(outputs[0].detach().numpy()).item() | |
# Retrieve label names from the model's config | |
label_names = {0: 'Positive', 1: 'Negative', 2: 'Neutral', 3: 'Mixed'} | |
predicted_label = label_names[predicted_label_index] | |
return predicted_label | |
css_code='body{background-image:url("https://media.istockphoto.com/id/1256252051/vector/people-using-online-translation-app.jpg?s=612x612&w=0&k=20&c=aa6ykHXnSwqKu31fFR6r6Y1bYMS5FMAU9yHqwwylA94=");}' | |
demo = gr.Interface( | |
fn=classify_sentiment, | |
inputs= | |
gr.Textbox(label="sentence", placeholder=" Enter the sentence "), | |
outputs=[gr.Textbox(label="the sentiment")], | |
title="Arabic Sentiment Analyzer", | |
description= "This is Arabic Sentiment Analyzer, it takes an arabian sentence as input and returns the sentiment behind it", | |
css = css_code | |
) | |
demo.launch() |