ESMATUGBA commited on
Commit
e9a03e0
·
verified ·
1 Parent(s): d1342bb

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +75 -38
src/streamlit_app.py CHANGED
@@ -1,40 +1,77 @@
1
- import altair as alt
2
- import numpy as np
3
- import pandas as pd
4
  import streamlit as st
 
 
5
 
6
- """
7
- # Welcome to Streamlit!
8
-
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
12
-
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
15
-
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
-
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
-
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
25
-
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
-
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
40
- ))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import joblib
3
+ import neattext.functions as nfx
4
 
5
+ # Sayfa Ayarları / Page Settings
6
+ st.set_page_config(page_title="Amazon Review AI", page_icon="🛒", layout="centered")
7
+
8
+ # Modeli Yükle / Load the Model
9
+ try:
10
+ svm_model = joblib.load("svm_amazon.pkl")
11
+ except:
12
+ st.error("Model dosyası (svm_amazon.pkl) bulunamadı! / Model file not found!")
13
+
14
+ # --- SOL MENÜ (SIDEBAR) ---
15
+ with st.sidebar:
16
+ st.title("💡 Sample Reviews / Örnek Yorumlar")
17
+ st.write("Copy and paste to test: / Test etmek için kopyalayın:")
18
+
19
+ st.subheader("✅ Positive / Pozitif")
20
+ st.code("This product is fantastic and totally worth the buy!")
21
+ st.code("Great quality, I am very satisfied with this purchase.")
22
+
23
+ st.subheader("❌ Negative / Negatif")
24
+ st.code("Worst product ever. It broke in one day, total waste of money.")
25
+ st.code("Terrible experience. The quality is very poor and awful.")
26
+
27
+ st.divider()
28
+
29
+ # Teknik Not Bölümü / Technical Note Section
30
+ st.info("""
31
+ **📊 Technical Note / Teknik Not:**
32
+
33
+ This app uses the **SVM (Support Vector Machine)** model.
34
+ During the training phase, **Random Forest (84.6%)** and **SVM (92.6%)** models were compared.
35
+ The SVM model, which provided the highest accuracy, was deployed.
36
+
37
+ ---
38
+
39
+ Bu uygulama arka planda **SVM** modelini kullanmaktadır.
40
+ 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.
41
+ """)
42
+
43
+ # --- ANA PANEL (MAIN PANEL) ---
44
+ st.title("🛒 Amazon Review Sentiment Analysis")
45
+ st.subheader("Sentiment Analysis Dashboard / Duygu Analizi Paneli")
46
+ st.write("Enter a review, and AI will analyze it. / Yorumunuzu girin, yapay zeka analiz etsin.")
47
+
48
+ # Kullanıcı Girişi / User Input
49
+ user_input = st.text_area(
50
+ "Your Review / Yorumunuz:",
51
+ height=150,
52
+ placeholder="Type here or paste a sample from the left... / Buraya yazın veya soldan bir örnek seçin..."
53
+ )
54
+
55
+ # Analiz Butonu / Analysis Button
56
+ predict_btn = st.button("🔍 Analyze Sentiment / Duyguyu Analiz Et", use_container_width=True)
57
+
58
+ if predict_btn:
59
+ if user_input.strip() == "":
60
+ st.warning("Please enter a text for analysis! / Lütfen analiz için bir metin girin!")
61
+ else:
62
+ # Metni temizle / Clean the text
63
+ clean_text = nfx.normalize(user_input)
64
+
65
+ # Tahmin (SVM) / Prediction
66
+ pred = svm_model.predict([clean_text])[0]
67
+
68
+ # Sonuç Ekranı / Result Display
69
+ st.divider()
70
+ if pred == 1:
71
+ st.success("### ✨ RESULT: POSITIVE / SONUÇ: POZİTİF 😊")
72
+ st.balloons()
73
+ else:
74
+ st.error("### ⚠️ RESULT: NEGATIVE / SONUÇ: NEGATİF 😡")
75
+
76
+ # Alt Bilgi / Footer Caption
77
+ st.caption("Analysis performed with SVM algorithm (%92.6 Accuracy). / Analiz SVM algoritması ile %92.6 doğrulukla yapılmıştır.")