Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pandas as pd
|
3 |
+
import tensorflow as tf
|
4 |
+
from tensorflow.keras.layers import TextVectorization
|
5 |
+
|
6 |
+
df = pd.read_csv('train.csv')
|
7 |
+
|
8 |
+
X=df['comment_text']
|
9 |
+
|
10 |
+
vectorizer = TextVectorization(max_tokens=250000,
|
11 |
+
output_sequence_length=300,
|
12 |
+
output_mode='int')
|
13 |
+
vectorizer.adapt(X)
|
14 |
+
|
15 |
+
#load the model
|
16 |
+
model = tf.keras.models.load_model('CT_epoch_3.h5')
|
17 |
+
|
18 |
+
|
19 |
+
def score_comment(comment):
|
20 |
+
# Vectorize the input comment
|
21 |
+
vectorized_comment = vectorizer([comment])
|
22 |
+
# Predict using the loaded model
|
23 |
+
results = model.predict(vectorized_comment)
|
24 |
+
|
25 |
+
# Generate the output text based on predictions
|
26 |
+
text = ''
|
27 |
+
for idx, col in enumerate(df.columns[2:]): # Adjust the range if necessary
|
28 |
+
text += '{}: {}\n'.format(col, results[0][idx] > 0.5)
|
29 |
+
|
30 |
+
return text
|
31 |
+
|
32 |
+
interface = gr.Interface(
|
33 |
+
fn=score_comment,
|
34 |
+
inputs=gr.Textbox(lines=2, placeholder='Comment to score'),
|
35 |
+
outputs='text'
|
36 |
+
)
|
37 |
+
|
38 |
+
interface.launch()
|