lt12200028 commited on
Commit
5573c04
·
1 Parent(s): aef6cf3

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ from transformers import BertTokenizer, TFBertForSequenceClassification
4
+ import tensorflow as tf
5
+
6
+ # Load tokenizer
7
+ tokenizer = BertTokenizer.from_pretrained("nlpaueb/bert-base-greek-uncased-v1")
8
+
9
+ # Load model
10
+ model = TFBertForSequenceClassification.from_pretrained('new_emdedding trial')
11
+
12
+ def check_sarcasm(sentence):
13
+ tf_batch = tokenizer(sentence, max_length=128, padding=True, truncation=True, return_tensors='tf')
14
+ tf_outputs = model(tf_batch.input_ids, tf_batch.token_type_ids)
15
+ tf_predictions = tf.nn.softmax(tf_outputs.logits, axis=-1)
16
+ pred_label = tf.argmax(tf_predictions, axis=1)
17
+
18
+ if pred_label == 1:
19
+ return "Sarcastic"
20
+ else:
21
+ return "Not sarcastic"
22
+
23
+ # Create a Gradio interface
24
+ iface = gr.Interface(
25
+ fn=check_sarcasm,
26
+ inputs="text",
27
+ outputs="text",
28
+ title="Sarcasm Detection",
29
+ description="Enter a headline and check if it's sarcastic."
30
+ )
31
+
32
+ # Launch the interface
33
+ iface.launch(share=True)