File size: 3,036 Bytes
e9bb17f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
68
69
70
71
72
73
74
75
76
77
78
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.")