Update app.py
Browse files
app.py
CHANGED
@@ -21,6 +21,7 @@ demo = gr.Interface(fn=classify_sentiment,
|
|
21 |
|
22 |
demo.launch()
|
23 |
'''
|
|
|
24 |
import gradio as gr
|
25 |
from transformers import TFBertForSequenceClassification, BertTokenizer
|
26 |
import tensorflow as tf
|
@@ -45,3 +46,27 @@ demo = gr.Interface(fn=classify_sentiment,
|
|
45 |
description="Multilingual BERT-based Sentiment Analysis")
|
46 |
|
47 |
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
demo.launch()
|
23 |
'''
|
24 |
+
'''
|
25 |
import gradio as gr
|
26 |
from transformers import TFBertForSequenceClassification, BertTokenizer
|
27 |
import tensorflow as tf
|
|
|
46 |
description="Multilingual BERT-based Sentiment Analysis")
|
47 |
|
48 |
demo.launch()
|
49 |
+
'''
|
50 |
+
import gradio as gr
|
51 |
+
from transformers import TFBertForSequenceClassification, AutoTokenizer
|
52 |
+
import tensorflow as tf
|
53 |
+
|
54 |
+
model = TFBertForSequenceClassification.from_pretrained("shrish191/sentiment-bert")
|
55 |
+
tokenizer = AutoTokenizer.from_pretrained("shrish191/sentiment-bert")
|
56 |
+
|
57 |
+
def classify_sentiment(text):
|
58 |
+
text = text.lower().strip()
|
59 |
+
inputs = tokenizer(text, return_tensors="tf", padding=True, truncation=True)
|
60 |
+
predictions = model(inputs, training=False).logits # Prevent dropout at inference
|
61 |
+
label = tf.argmax(predictions, axis=1).numpy()[0]
|
62 |
+
labels = model.config.id2label
|
63 |
+
print(f"Text: {text} | Prediction: {label} | Logits: {predictions.numpy()}")
|
64 |
+
return labels[str(label)]
|
65 |
+
|
66 |
+
demo = gr.Interface(fn=classify_sentiment,
|
67 |
+
inputs=gr.Textbox(placeholder="Enter a tweet..."),
|
68 |
+
outputs="text",
|
69 |
+
title="Tweet Sentiment Classifier",
|
70 |
+
description="Multilingual BERT-based Sentiment Analysis")
|
71 |
+
|
72 |
+
demo.launch()
|