Update app.py
Browse files
app.py
CHANGED
|
@@ -10,21 +10,21 @@ Original file is located at
|
|
| 10 |
import gradio as gr
|
| 11 |
from transformers import BertTokenizer, TFBertForSequenceClassification
|
| 12 |
import tensorflow as tf
|
| 13 |
-
from transformers import pipeline
|
| 14 |
|
| 15 |
# Load tokenizer
|
| 16 |
-
|
| 17 |
|
| 18 |
# Load model
|
| 19 |
-
|
| 20 |
|
| 21 |
-
pipeline= pipeline(task="text-classification", model="https://huggingface.co/spaces/Kleo/Sarcasm/blob/main/tf_model.h5")
|
| 22 |
def check_sarcasm(sentence):
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
pred_label=pipeline(sentence)
|
| 28 |
|
| 29 |
if pred_label == 1:
|
| 30 |
return "Sarcastic"
|
|
|
|
| 10 |
import gradio as gr
|
| 11 |
from transformers import BertTokenizer, TFBertForSequenceClassification
|
| 12 |
import tensorflow as tf
|
| 13 |
+
#from transformers import pipeline
|
| 14 |
|
| 15 |
# Load tokenizer
|
| 16 |
+
tokenizer = BertTokenizer.from_pretrained("nlpaueb/bert-base-greek-uncased-v1")
|
| 17 |
|
| 18 |
# Load model
|
| 19 |
+
model = TFBertForSequenceClassification.from_pretrained('https://huggingface.co/spaces/Kleo/Sarcasm/tree/main')
|
| 20 |
|
| 21 |
+
#pipeline= pipeline(task="text-classification", model="https://huggingface.co/spaces/Kleo/Sarcasm/blob/main/tf_model.h5")
|
| 22 |
def check_sarcasm(sentence):
|
| 23 |
+
tf_batch = tokenizer(sentence, max_length=128, padding=True, truncation=True, return_tensors='tf')
|
| 24 |
+
tf_outputs = model(tf_batch.input_ids, tf_batch.token_type_ids)
|
| 25 |
+
tf_predictions = tf.nn.softmax(tf_outputs.logits, axis=-1)
|
| 26 |
+
pred_label = tf.argmax(tf_predictions, axis=1)
|
| 27 |
+
#pred_label=pipeline(sentence)
|
| 28 |
|
| 29 |
if pred_label == 1:
|
| 30 |
return "Sarcastic"
|