import gradio as gr import pickle from keras.utils import pad_sequences from keras.models import load_model import os os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' model = load_model('final.h5') with open('tokenizer.pickle', 'rb') as file: tokenizer = pickle.load(file) def decide(text): text = text.lower() tokenized_text = tokenizer.texts_to_sequences([text]) padded_tokens = pad_sequences(tokenized_text, maxlen=221, padding='post', truncating='post') result = model.predict(padded_tokens) print(result) if result >= 0.6: score = "Positive score: " + str(round(result[0][0] * 100, 2)) + "%" return score elif result <= 0.4: score = "Negative score: " + str(round(result[0][0] * 100, 2)) + "%" return score else: score = "Neutral score: " + str(round(result[0][0] * 100, 2)) + "%" return score example_sentence_1 = "Nothing to improve" example_sentence_2 = "Laging galit sa meet" example_sentence_3 = "nothing improve" example_sentence_4 = "he always make us happy when he teach us." example_sentence_5 = "goods naman po" example_sentence_6 = "always absent" example_sentence_7 = "no need improvement" example_sentence_8 = "he needs improvement" example_sentence_9 = "needs improvement" example_sentence_10 = "honestly, the course was really interesting. plus the instructor is approachable and willing to answer queries. but i think there should be at least more power and emphasis when she speaks. i really love the way she deliver her explanation for the sake of learning and i would really love if she manages to make us more focused." example_sentence_11 = "magaling magturo, no need to improve" example_sentence_12 = "maayos naman magturo, subalit parang nagbabasa siya sa way ng teaching okay lang naman pero parang nay kulang pa, ayun yung engagement sa students." example_sentence_13 = "these are the ff. reasons why he needs improvement: 1. he didn't attend to his class on the right schedule. 2. 2 or 3 weeks before the christmas break until the last week of class, he didn't attend in our class. all he gave is one power point presentations for finals. 3. during one of his discussions, he identified number zero in positive side of the number line. i am confused because i know that the zero is neutral number. i ask him about it, he insisted that the zero is only in the positive side. i searched it on google just to make sure and i realized that he is really wrong. i am concerned that the other students will receive this kind of false information. 4. i wish that he give more considerations to his students. 5. one time we ask him why he didn't follow our class schedule, he told us he has part time jobs in other schools. for this reason, we always adjusted our time for that reason. i suggests that he needs to make room also in adjustments. 6. we've waited for almost one month in his midterm exam, we always initiate the chat and i hope he take initiative sometimes about the exam. 7. i hope he will be a responsible professor because his students are always waiting for his classes and announcements." examples = [[example_sentence_1], [example_sentence_2], [example_sentence_3], [example_sentence_4], [example_sentence_5], [example_sentence_6], [example_sentence_7], [example_sentence_8], [example_sentence_9], [example_sentence_10], [example_sentence_11], [example_sentence_12], [example_sentence_13]] gr.Interface(decide, inputs=gr.inputs.Textbox(lines=1, placeholder=None, default="", label=None), outputs='text', examples=examples, title="Sentiment analysis of Evaluation Result", theme="grass", allow_flagging="auto", flagging_dir='flagging records').launch()