Asanaly commited on
Commit
8c02922
·
verified ·
1 Parent(s): 8069fa8

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+
4
+ st.set_page_config(page_title="Emotion Analyzer", page_icon="🙂")
5
+
6
+ st.title("Twitter Sentiment Analysis (BERT)")
7
+ st.write("Твиттердің эмоционалды реңкін анықтайтын веб-қосымша")
8
+
9
+ # Load model
10
+ @st.cache_resource
11
+ def load_model():
12
+ return pipeline("sentiment-analysis", model="nlptown/bert-base-multilingual-uncased-sentiment")
13
+
14
+ model = load_model()
15
+
16
+ # User input
17
+ text = st.text_area("Мәтінді енгізіңіз:", placeholder="Мысалы: Бұл жоба өте керемет!")
18
+
19
+ if st.button("Анализ жасау"):
20
+ if text.strip() == "":
21
+ st.warning("Мәтін енгізіңіз!")
22
+ else:
23
+ result = model(text)[0]
24
+
25
+ label = result["label"]
26
+ score = result["score"]
27
+
28
+ st.subheader("Нәтиже:")
29
+ st.write(f"**Эмоция:** {label}")
30
+ st.write(f"**Дәлдік:** {round(score, 3)}")
31
+
32
+ # Simple emotion label mapping
33
+ if label == "1 star":
34
+ st.error("Негатив 😠")
35
+ elif label == "2 stars":
36
+ st.warning("Соншалықты жақсы емес 😕")
37
+ elif label == "3 stars":
38
+ st.info("Нейтрал 🙂")
39
+ elif label == "4 stars":
40
+ st.success("Жақсы 🙂")
41
+ elif label == "5 stars":
42
+ st.success("Өте позитивті 😍")