Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,26 +1,38 @@
|
|
| 1 |
-
from transformers import
|
| 2 |
-
|
| 3 |
-
import torch
|
| 4 |
import gradio as gr
|
| 5 |
|
| 6 |
-
repository_id = "PRAli22/AraBert-Arabic-Sentiment-Analysis"
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
|
| 12 |
|
| 13 |
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=");}'
|
| 14 |
|
| 15 |
demo = gr.Interface(
|
| 16 |
-
fn=
|
| 17 |
inputs=
|
| 18 |
gr.Textbox(label="sentence", placeholder=" Enter the sentence "),
|
| 19 |
|
| 20 |
|
| 21 |
-
outputs=[gr.Textbox(label="
|
| 22 |
-
title="Arabic
|
| 23 |
-
description= "This is Arabic
|
| 24 |
css = css_code
|
| 25 |
)
|
| 26 |
demo.launch()
|
|
|
|
| 1 |
+
from transformers import AutoConfig, AutoModelForTokenClassification, AutoTokenizer
|
| 2 |
+
import numpy as np
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
|
|
|
|
| 5 |
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained("PRAli22/AraBert-Arabic-Sentiment-Analysis" )
|
| 7 |
+
model = AutoModelForSequenceClassification.from_pretrained("PRAli22/AraBert-Arabic-Sentiment-Analysis")
|
| 8 |
+
|
| 9 |
+
def classify_sentiment(text):
|
| 10 |
+
|
| 11 |
+
# Tokenize the text
|
| 12 |
+
inputs = tokenizer(text, return_tensors="pt")
|
| 13 |
+
|
| 14 |
+
# Get model predictions
|
| 15 |
+
outputs = model(**inputs)
|
| 16 |
+
predicted_label_index = np.argmax(outputs[0].detach().numpy()).item()
|
| 17 |
+
|
| 18 |
+
# Retrieve label names from the model's config
|
| 19 |
+
label_names = {0: 'Positive', 1: 'Negative', 2: 'Neutral', 3: 'Mixed'}
|
| 20 |
+
|
| 21 |
+
predicted_label = label_names[predicted_label_index]
|
| 22 |
|
| 23 |
+
return predicted_label
|
| 24 |
|
| 25 |
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=");}'
|
| 26 |
|
| 27 |
demo = gr.Interface(
|
| 28 |
+
fn=classify_sentiment,
|
| 29 |
inputs=
|
| 30 |
gr.Textbox(label="sentence", placeholder=" Enter the sentence "),
|
| 31 |
|
| 32 |
|
| 33 |
+
outputs=[gr.Textbox(label="the sentiment")],
|
| 34 |
+
title="Arabic Sentiment Analyzer",
|
| 35 |
+
description= "This is Arabic Sentiment Analyzer, it takes an arabian sentence as input and returns the sentiment behind it",
|
| 36 |
css = css_code
|
| 37 |
)
|
| 38 |
demo.launch()
|