Skip to content
Snippets Groups Projects
Commit c7cd6ab8 authored by Sid Pothineni's avatar Sid Pothineni
Browse files

added website category classification

parent 455a4b10
No related branches found
No related tags found
No related merge requests found
......@@ -6,6 +6,9 @@ from transformers import pipeline
sentiment_analysis_model = "lxyuan/distilbert-base-multilingual-cased-sentiments-student"
sentiment_analyzer = pipeline("sentiment-analysis", model=sentiment_analysis_model)
website_class_model = "alimazhar-110/website_classification"
website_class_analyzer = pipeline("text-classification", model=website_class_model)
# History list to store past results
history = []
......@@ -13,22 +16,29 @@ def submit_for_analysis():
input_text = text_entry.get("1.0", tk.END).strip()
if input_text:
try:
res = sentiment_analyzer(input_text)
label = res[0]['label'].capitalize()
score = round(res[0]['score'], 3)
result_text.set(f"Result: {label} statement\nStatement's score: {score}")
color = "#FFCCCC" if label.lower() == "negative" else "#CCFFCC"
result_label.config(background=color)
# Update history by appending new entries
history.append((input_text, label, score))
# Update the history display
sentiment_result = sentiment_analyzer(input_text)
website_result = website_class_analyzer(input_text)
# Sentiment analysis results
sentiment_label = sentiment_result[0]["label"].capitalize()
sentiment_score = round(sentiment_result[0]["score"], 3)
sentiment_color = "#FFCCCC" if sentiment_label.lower() == "negative" else "#CCFFCC"
sentiment_result_text.set(f"Sentiment: {sentiment_label} statement\nScore: {sentiment_score}")
sentiment_result_label.config(background=sentiment_color)
# Website classification results
website_type = website_result[0]["label"]
website_confidence = round(website_result[0]["score"], 3)
website_results_text.set(f"Website Category: {website_type}\nConfidence: {website_confidence}")
# Update history
history.append((input_text, sentiment_label, sentiment_score, website_type, website_confidence))
update_history_display()
except Exception as e:
messagebox.showerror("Error", str(e))
result_text.set("")
sentiment_result_text.set("")
website_results_text.set("")
else:
messagebox.showinfo("Info", "Please enter some text to analyze.")
......@@ -36,14 +46,14 @@ def update_history_display():
history_text.config(state=tk.NORMAL) # Enable the widget before updating
history_text.delete("1.0", tk.END) # Clear the existing content
for i, entry in enumerate(reversed(history)):
input_text, label, score = entry
history_text.insert(tk.END, f"{i+1}. \"{input_text}\" - {label} ({score})\n\n")
input_text, sentiment_label, sentiment_score, website_type, website_confidence = entry
history_text.insert(tk.END, f"{i+1}. \"{input_text}\" - Sentiment: {sentiment_label} ({sentiment_score}), Website Category: {website_type} (Confidence: {website_confidence})\n\n")
history_text.config(state=tk.DISABLED) # Disable the widget after updating
# Create the main window
window = tk.Tk()
window.geometry("700x900") # Increased height to accommodate history area
window.title("Sentiment Analyzer")
window.geometry("700x1000") # Adjusted height to accommodate additional features
window.title("Sentiment and Website Category Analyzer")
# Styling
style = ttk.Style()
......@@ -52,24 +62,20 @@ style.theme_use('clam')
# Header Frame
header_frame = ttk.Frame(window, padding="10")
header_frame.pack(fill='x')
header_label = ttk.Label(header_frame, text="Sentiment Analyzer", font=("Helvetica", 16))
header_label = ttk.Label(header_frame, text="Sentiment and Website Category Analyzer", font=("Helvetica", 16))
header_label.pack()
# Text Entry Frame
text_frame = ttk.Frame(window, padding="10")
text_frame.pack(fill='x')
text_entry = tk.Text(text_frame, width=80, height=10)
text_entry.pack(padx=5, pady=5)
# Buttons Frame
buttons_frame = ttk.Frame(window, padding="10")
buttons_frame.pack(fill='x')
analyze_button = ttk.Button(buttons_frame, text="Analyze", command=submit_for_analysis)
analyze_button.pack(side='left', padx=5)
exit_button = ttk.Button(buttons_frame, text="Exit", command=window.quit)
exit_button.pack(side='right', padx=5)
......@@ -77,9 +83,13 @@ exit_button.pack(side='right', padx=5)
result_frame = ttk.Frame(window, padding="10")
result_frame.pack(fill='both', expand=True)
result_text = tk.StringVar()
result_label = ttk.Label(result_frame, textvariable=result_text, font=("Helvetica", 12), background="#DDDDDD", wraplength=500)
result_label.pack(padx=5, pady=5, fill='both')
sentiment_result_text = tk.StringVar()
sentiment_result_label = ttk.Label(result_frame, textvariable=sentiment_result_text, font=("Helvetica", 12), background="#DDDDDD", wraplength=500)
sentiment_result_label.pack(padx=5, pady=5, fill='both')
website_results_text = tk.StringVar()
website_results_label = ttk.Label(result_frame, textvariable=website_results_text, font=("Helvetica", 12), background="#DDDDDD", wraplength=500)
website_results_label.pack(padx=5, pady=5, fill='both')
# History Frame
history_frame = ttk.Frame(window, padding="10")
......@@ -95,4 +105,4 @@ history_text = tk.Text(history_frame, width=80, height=10, yscrollcommand=scroll
history_text.pack(side='left', padx=5, pady=5, fill='both', expand=True)
scrollbar.config(command=history_text.yview)
window.mainloop()
\ No newline at end of file
window.mainloop()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment