File size: 1,365 Bytes
9f7f267
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#vader-lexicon model with NLTK
import pandas as pd
import matplotlib.pyplot as plt
import tkinter as tk
from tkinter import messagebox
from transformers import pipeline

model_id = "cardiffnlp/twitter-xlm-roberta-base-sentiment-multilingual"
classifier = pipeline("sentiment-analysis", model=model_id)

def process_string(input_string):
    result =  classifier(input_string)
    if result[0]['label'] == 'positive':
        return 'This comment is: positive 😃'
    elif result[0]['label'] == 'negative':
        return 'This  comment is: negative 😒'
    else: 
        return 'This comment is: positive 😃'

def process_input():
    input_string = entry.get()
    if input_string.strip() == "":
        messagebox.showerror("Error", "Please enter a text.")
    else:
        processed_string = process_string(input_string)
        messagebox.showinfo("Sentiment", f"Comment: {input_string}\n{processed_string}")
# Create the main application window
root = tk.Tk()
root.title("Sentiment Analyser: Hugging face 😃😒")

# Set the size of the window
root.geometry("500x100")

# Create and place widgets
label = tk.Label(root, text="Enter a text:")
label.pack()

entry = tk.Entry(root, width=80)
entry.pack()

button = tk.Button(root, text="Process", command=process_input, bg='green', fg='white')
button.pack()

# Run the Tkinter event loop
root.mainloop()