File size: 2,114 Bytes
7d50134
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QLineEdit, QVBoxLayout, QPushButton
from PyQt5.QtGui import QFont
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QLineEdit, QVBoxLayout, QPushButton, QComboBox
import tensorflow as tf
import numpy as np
import tensorflow_hub as hub
import tensorflow_text as text

print ("Loading Models.....")
Model2=tf.keras.models.load_model("./Bert_uncased_model_Tiwtter.h5",custom_objects={'KerasLayer':hub.KerasLayer})

Model1=tf.keras.models.load_model("./Bert_uncased_model_Reddit.h5",custom_objects={'KerasLayer':hub.KerasLayer})
classes=['Neutral', 'Positive', 'Negative']

def show_message():
    message = input_box.text()
    selected_option = dropdown.currentIndex()
    Model=Model2
    if (selected_option==1):
        Model=Model1
    ans=Model.predict([message])
    i=np.argmax(ans)
    catagorie=classes[i]
    percentage=str(int(ans[0][i]*100))+" %"
    show_text=catagorie+" - "+percentage
    label.setText(show_text)

app = QApplication([])
window = QWidget()
window.setWindowTitle("Sentiment Analysis")
window.setFixedSize(600, 300)  # Set a fixed window size

layout = QVBoxLayout()

label1 = QLabel("Enter a text:")
label1.setFont(QFont("Arial", 14))  # Increase the font size
layout.addWidget(label1)

dropdown = QComboBox()
dropdown.addItem("Bert uncased model Tiwtter (Model 2)")
dropdown.addItem("Bert uncased model Reddit (Model 1)")
dropdown.setFont(QFont("Arial", 12))  # Increase the font size
layout.addWidget(dropdown)

input_box = QLineEdit()
input_box.setFont(QFont("Arial", 14))  # Increase the font size
layout.addWidget(input_box)

button = QPushButton("Classify")
button.clicked.connect(show_message)
button.setFont(QFont("Arial", 14))  # Increase the font size
layout.addWidget(button)

layout.addStretch()

label = QLabel("")
label.setFont(QFont("Arial", 12))  # Increase the font size
layout.addWidget(label)
label.setContentsMargins(150, 0, 250, 0)  # Add 15-pixel padding


layout.addStretch()  # Add a stretchable space at the end to center-align the widgets

window.setLayout(layout)
window.show()
app.exec_()