Spaces:
Sleeping
Sleeping
File size: 985 Bytes
5573c04 96fae21 5573c04 |
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 |
import gradio as gr
from transformers import BertTokenizer, TFBertForSequenceClassification
import tensorflow as tf
# Load tokenizer
tokenizer = BertTokenizer.from_pretrained("nlpaueb/bert-base-greek-uncased-v1")
# Load model
model = TFBertForSequenceClassification.from_pretrained('lt12200028/Sarcasm-Detection-GR')
def check_sarcasm(sentence):
tf_batch = tokenizer(sentence, max_length=128, padding=True, truncation=True, return_tensors='tf')
tf_outputs = model(tf_batch.input_ids, tf_batch.token_type_ids)
tf_predictions = tf.nn.softmax(tf_outputs.logits, axis=-1)
pred_label = tf.argmax(tf_predictions, axis=1)
if pred_label == 1:
return "Sarcastic"
else:
return "Not sarcastic"
# Create a Gradio interface
iface = gr.Interface(
fn=check_sarcasm,
inputs="text",
outputs="text",
title="Sarcasm Detection",
description="Enter a headline and check if it's sarcastic."
)
# Launch the interface
iface.launch(share=True) |