Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import TFBertForSequenceClassification, BertTokenizer
|
3 |
+
import tensorflow as tf
|
4 |
+
|
5 |
+
# Load model and tokenizer from your HF model repo
|
6 |
+
model = TFBertForSequenceClassification.from_pretrained("Shrish191/sentiment-classifier")
|
7 |
+
tokenizer = BertTokenizer.from_pretrained("Shrish191/sentiment-classifier")
|
8 |
+
|
9 |
+
def classify_sentiment(text):
|
10 |
+
inputs = tokenizer(text, return_tensors="tf", padding=True, truncation=True)
|
11 |
+
predictions = model(inputs).logits
|
12 |
+
label = tf.argmax(predictions, axis=1).numpy()[0]
|
13 |
+
labels = {0: "Negative", 1: "Neutral", 2: "Positive"}
|
14 |
+
return labels[label]
|
15 |
+
|
16 |
+
demo = gr.Interface(fn=classify_sentiment,
|
17 |
+
inputs=gr.Textbox(placeholder="Enter a tweet..."),
|
18 |
+
outputs="text",
|
19 |
+
title="Tweet Sentiment Classifier",
|
20 |
+
description="Multilingual BERT-based Sentiment Analysis")
|
21 |
+
|
22 |
+
demo.launch()
|