Asanaly commited on
Update app.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142import streamlit as stfrom transformers import pipelinest.set_page_config(page_title="Emotion Analyzer", page_icon="🙂")st.title("Twitter Sentiment Analysis (BERT)")st.write("Твиттердің эмоционалды реңкін анықтайтын веб-қосымша")# Load model@st.cache_resourcedef load_model():return pipeline("sentiment-analysis", model="nlptown/bert-base-multilingual-uncased-sentiment")model = load_model()# User inputtext = st.text_area("Мәтінді енгізіңіз:", placeholder="Мысалы: Бұл жоба өте керемет!")if st.button("Анализ жасау"):if text.strip() == "":st.warning("Мәтін енгізіңіз!")else:result = model(text)[0]label = result["label"]score = result["score"]st.subheader("Нәтиже:")st.write(f"**Эмоция:** {label}")st.write(f"**Дәлдік:** {round(score, 3)}")# Simple emotion label mappingif label == "1 star":st.error("Негатив 😠")elif label == "2 stars":st.warning("Соншалықты жақсы емес 😕")elif label == "3 stars":st.info("Нейтрал 🙂")elif label == "4 stars":st.success("Жақсы 🙂")elif label == "5 stars":st.success("Өте позитивті 😍")12345678910111213141516171819202122232425262728293031323334import gradio as grfrom transformers import pipeline# Load model once (cached by HF)sentiment_model = pipeline("sentiment-analysis",model="nlptown/bert-base-multilingual-uncased-sentiment")def analyze(text):result = sentiment_model(text)[0]label = result["label"]score = round(result["score"], 3)mapping = {"1 star": "Өте негатив 😡","2 stars": "Негатив 😠","3 stars": "Нейтрал 🙂","4 stars": "Позитив 😊","5 stars": "Өте позитив 😍",}emotion = mapping.get(label, label)return f"Эмоция: {emotion}\nДәлдік: {score}"ui = gr.Interface(fn=analyze,inputs=gr.Textbox(label="Мәтін енгізіңіз"),outputs=gr.Textbox(label="Нәтиже"),title="Sentiment Analysis",description="BERT моделіне негізделген эмоция талдау")ui.launch()
app.py+32-40