Spaces:
Runtime error
Runtime error
File size: 1,990 Bytes
4863e5d d7f983a 4863e5d |
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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import gradio as gr
import tensorflow as tf
from tensorflow.keras.preprocessing.sequence import pad_sequences
import os
import pickle
from keras.preprocessing.text import Tokenizer
from keras.preprocessing import sequence
from keras.utils import to_categorical, pad_sequences
import numpy as np
# In[2]:
model = tf.keras.models.load_model('deep_learning_model_sentiment_analysis.h5', compile=False)
model.compile()
# In[3]:
with open('tokenizer_new.pickle', 'rb') as file:
tokenizer = pickle.load(file)
# In[11]:
def decide(text):
sentiment_classes = ['negative', 'neutral', 'positive']
max_len = 2000
# Tokenize the text
text = [text]
xt = tokenizer.texts_to_sequences(text)
xt = pad_sequences(xt, padding='post', maxlen=max_len)
# Make the prediction
prediction = model.predict(xt)
prediction_class = sentiment_classes[np.argmax(prediction)]
return prediction_class
# In[12]:
example_sentence_1 = "aduh mahasiswa sombong kasih kartu kuning belajar usahlah politik selesai kuliah nya politik telat dasar mahasiswa"
example_sentence_2 = "lokasi strategis jalan sumatra bandung nya nyaman sofa lantai paella nya enak pas dimakan minum bir dingin appetiser nya enak enak"
examples = [[example_sentence_1], [example_sentence_2]]
# In[13]:
title = "Sentiment Analysis dengan Deep Learning"
article = "<p style='text-align: center'><a href='https://www.linkedin.com/in/m-afif-rizky-a-a96048182/'>Created by @Vrooh933 Production</a> | <a href='https://github.com/afifrizkyandika11551100310'>GitHub Profile</a>"
# In[14]:
intfc = gr.Interface(fn=decide,
inputs=gr.Textbox(label="Input here", lines=2, placeholder="Input your text"),
outputs=gr.Label(label="Sentiment Analysis"),
examples=examples,
title=title,
article=article,)
intfc.launch(inline=False)
# In[ ]:
|