File size: 1,356 Bytes
1c4f840
53f88bc
899f85a
 
 
53f88bc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
899f85a
53f88bc
899f85a
 
 
 
53f88bc
899f85a
 
 
 
53f88bc
 
 
899f85a
 
 
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
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()