Delete application.py
Browse files- application.py +0 -120
application.py
DELETED
@@ -1,120 +0,0 @@
|
|
1 |
-
# -*- coding: utf-8 -*-
|
2 |
-
"""Application.ipynb
|
3 |
-
|
4 |
-
Automatically generated by Colaboratory.
|
5 |
-
|
6 |
-
Original file is located at
|
7 |
-
https://colab.research.google.com/drive/148du8431_JkTaH-totdocC2aUXzOWimL
|
8 |
-
"""
|
9 |
-
|
10 |
-
from google.colab import drive
|
11 |
-
drive.mount('/content/drive')
|
12 |
-
|
13 |
-
pip install transformers
|
14 |
-
|
15 |
-
pip install gradio
|
16 |
-
|
17 |
-
from transformers import BertTokenizer, TFBertForSequenceClassification
|
18 |
-
import tensorflow as tf
|
19 |
-
|
20 |
-
# Load tokenizer
|
21 |
-
tokenizer = BertTokenizer.from_pretrained("nlpaueb/bert-base-greek-uncased-v1")
|
22 |
-
|
23 |
-
# Load model
|
24 |
-
model = TFBertForSequenceClassification.from_pretrained('/content/drive/MyDrive/Mini_Project/new_emdedding trial')
|
25 |
-
|
26 |
-
def check_sarcasm(sentence):
|
27 |
-
tf_batch = tokenizer(sentence, max_length=128, padding=True, truncation=True, return_tensors='tf')
|
28 |
-
tf_outputs = model(tf_batch.input_ids, tf_batch.token_type_ids)
|
29 |
-
tf_predictions = tf.nn.softmax(tf_outputs.logits, axis=-1)
|
30 |
-
pred_label = tf.argmax(tf_predictions, axis=1)
|
31 |
-
|
32 |
-
if pred_label == 1:
|
33 |
-
return "Sarcastic"
|
34 |
-
else:
|
35 |
-
return "Not sarcastic"
|
36 |
-
|
37 |
-
# Example usage
|
38 |
-
sentence = "Μεξικό: 25 νεκροί από την πτώση λεωφορείου στον γκρεμό"
|
39 |
-
result = check_sarcasm(sentence)
|
40 |
-
print(result)
|
41 |
-
|
42 |
-
import gradio as gr
|
43 |
-
|
44 |
-
def check_sarcasm(sentence):
|
45 |
-
tf_batch = tokenizer(sentence, max_length=128, padding=True, truncation=True, return_tensors='tf')
|
46 |
-
tf_outputs = model(tf_batch.input_ids, tf_batch.token_type_ids)
|
47 |
-
tf_predictions = tf.nn.softmax(tf_outputs.logits, axis=-1)
|
48 |
-
pred_label = tf.argmax(tf_predictions, axis=1)
|
49 |
-
|
50 |
-
if pred_label == 1:
|
51 |
-
return "Sarcastic"
|
52 |
-
else:
|
53 |
-
return "Not sarcastic"
|
54 |
-
|
55 |
-
# Create a Gradio interface
|
56 |
-
iface = gr.Interface(
|
57 |
-
fn=check_sarcasm,
|
58 |
-
inputs="text",
|
59 |
-
outputs="text",
|
60 |
-
title="Sarcasm Detection",
|
61 |
-
description="Enter a headline and check if it's sarcastic."
|
62 |
-
)
|
63 |
-
|
64 |
-
# Launch the interface
|
65 |
-
iface.launch(share=True)
|
66 |
-
|
67 |
-
from transformers import pipeline
|
68 |
-
import gradio as gr
|
69 |
-
|
70 |
-
model = pipeline("Sarcasm Detection" , model="/content/drive/MyDrive/Mini_Project/new_emdedding trial/tf_model.h5")
|
71 |
-
def check_sarcasm(sentence):
|
72 |
-
tf_batch = tokenizer(sentence, max_length=128, padding=True, truncation=True, return_tensors='tf')
|
73 |
-
tf_outputs = model(tf_batch.input_ids, tf_batch.token_type_ids)
|
74 |
-
tf_predictions = tf.nn.softmax(tf_outputs.logits, axis=-1)
|
75 |
-
pred_label = tf.argmax(tf_predictions, axis=1)
|
76 |
-
|
77 |
-
if pred_label == 1:
|
78 |
-
return "Sarcastic"
|
79 |
-
else:
|
80 |
-
return "Not sarcastic"
|
81 |
-
# Create a Gradio interface
|
82 |
-
iface = gr.Interface(
|
83 |
-
fn=check_sarcasm,
|
84 |
-
inputs="text",
|
85 |
-
outputs="text",
|
86 |
-
title="Sarcasm Detection",
|
87 |
-
description="Enter a headline and check if it's sarcastic."
|
88 |
-
)
|
89 |
-
|
90 |
-
# Launch the interface
|
91 |
-
iface.launch()
|
92 |
-
|
93 |
-
import gradio as gr
|
94 |
-
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
95 |
-
|
96 |
-
tokenizer = AutoTokenizer.from_pretrained("nlpaueb/bert-base-greek-uncased-v1")
|
97 |
-
model = AutoModelForSequenceClassification.from_pretrained("/content/drive/MyDrive/Mini_Project/new_emdedding trial",from_tf=True)
|
98 |
-
def check_sarcasm(sentence):
|
99 |
-
tf_batch = tokenizer(sentence, max_length=128, padding=True, truncation=True, return_tensors='tf')
|
100 |
-
tf_outputs = model(tf_batch.input_ids, tf_batch.token_type_ids)
|
101 |
-
tf_predictions = tf.nn.softmax(tf_outputs.logits, axis=-1)
|
102 |
-
pred_label = tf.argmax(tf_predictions, axis=1)
|
103 |
-
|
104 |
-
if pred_label == 1:
|
105 |
-
return "Sarcastic"
|
106 |
-
else:
|
107 |
-
return "Not sarcastic"
|
108 |
-
|
109 |
-
# Create a Gradio interface
|
110 |
-
iface = gr.Interface(
|
111 |
-
fn=check_sarcasm,
|
112 |
-
inputs="text",
|
113 |
-
outputs="text",
|
114 |
-
title="Sarcasm Detection",
|
115 |
-
description="Enter a headline and check if it's sarcastic."
|
116 |
-
)
|
117 |
-
|
118 |
-
# Launch the interface
|
119 |
-
iface.launch(share=True)
|
120 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|