import streamlit as st import joblib import neattext.functions as nfx # Sayfa Ayarları / Page Settings st.set_page_config(page_title="Amazon Review AI", page_icon="🛒", layout="centered") # Modeli Yükle / Load the Model try: svm_model = joblib.load("svm_amazon.pkl") except: st.error("Model dosyası (svm_amazon.pkl) bulunamadı! / Model file not found!") # --- SOL MENÜ (SIDEBAR) --- with st.sidebar: st.title("💡 Sample Reviews / Örnek Yorumlar") st.write("Copy and paste to test: / Test etmek için kopyalayın:") st.subheader("✅ Positive / Pozitif") st.code("This product is fantastic and totally worth the buy!") st.code("Great quality, I am very satisfied with this purchase.") st.subheader("❌ Negative / Negatif") st.code("Worst product ever. It broke in one day, total waste of money.") st.code("Terrible experience. The quality is very poor and awful.") st.divider() # Teknik Not Bölümü / Technical Note Section st.info(""" **📊 Technical Note / Teknik Not:** This app uses the **SVM (Support Vector Machine)** model. During the training phase, **Random Forest (84.6%)** and **SVM (92.6%)** models were compared. The SVM model, which provided the highest accuracy, was deployed. --- Bu uygulama arka planda **SVM** modelini kullanmaktadır. Eğitim aşamasında **Random Forest (%84.6)** ve **SVM (%92.6)** modelleri karşılaştırılmış, en yüksek doğruluğu veren SVM modeli yayına alınmıştır. """) # --- ANA PANEL (MAIN PANEL) --- st.title("🛒 Amazon Review Sentiment Analysis") st.subheader("Sentiment Analysis Dashboard / Duygu Analizi Paneli") st.write("Enter a review, and AI will analyze it. / Yorumunuzu girin, yapay zeka analiz etsin.") # Kullanıcı Girişi / User Input user_input = st.text_area( "Your Review / Yorumunuz:", height=150, placeholder="Type here or paste a sample from the left... / Buraya yazın veya soldan bir örnek seçin..." ) # Analiz Butonu / Analysis Button predict_btn = st.button("🔍 Analyze Sentiment / Duyguyu Analiz Et", use_container_width=True) if predict_btn: if user_input.strip() == "": st.warning("Please enter a text for analysis! / Lütfen analiz için bir metin girin!") else: # Metni temizle / Clean the text clean_text = nfx.normalize(user_input) # Tahmin (SVM) / Prediction pred = svm_model.predict([clean_text])[0] # Sonuç Ekranı / Result Display st.divider() if pred == 1: st.success("### ✨ RESULT: POSITIVE / SONUÇ: POZİTİF 😊") st.balloons() else: st.error("### ⚠️ RESULT: NEGATIVE / SONUÇ: NEGATİF 😡") # Alt Bilgi / Footer Caption st.caption("Analysis performed with SVM algorithm (%92.6 Accuracy). / Analiz SVM algoritması ile %92.6 doğrulukla yapılmıştır.")