Spaces:
Runtime error
Runtime error
#!/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[ ]: | |