# app.py import streamlit as st from transformers import pipeline import time st.set_page_config( page_title="Cosmetic Review Analyst", layout="wide", initial_sidebar_state="expanded", ) st.session_state.disable_watchdog = True def load_css(): st.markdown(""" """, unsafe_allow_html=True) @st.cache_resource(show_spinner=False) def load_models(): summarizer = pipeline( "summarization", model="Falconsai/text_summarization", max_length=200, temperature=0.7 ) classifier = pipeline( "text-classification", model="clb5114/EPR_emoclass_TinyBERT", return_all_scores=True ) return summarizer, classifier def main(): load_css() st.title("💄 Cosmetic Review AI Analyst") st.warning("⚠️ Please keep reviews under 200 words for optimal analysis") user_input = st.text_area( "Input cosmetic product review (Chinese/English supported)", height=200, placeholder="Example: This serum transformed my skin in just 3 days...", help="Maximum 200 characters recommended" ) if st.button("Start Analysis", use_container_width=True): if not user_input.strip(): st.error("⚠️ Please input valid review content") return with st.spinner('🔍 Analyzing...'): try: summarizer, classifier = load_models() with st.expander("Original Review", expanded=True): st.write(user_input) # Text summarization summary = summarizer(user_input, max_length=200)[0]['summary_text'] with st.container(): col1, col2 = st.columns([1, 3]) with col1: st.subheader("📝 Summary") with col2: st.markdown(f"```\n{summary}\n```") # Sentiment analysis results = classifier(summary) positive_score = results[0][1]['score'] label = "Positive 👍" if positive_score > 0.5 else "Negative 👎" with st.container(): st.subheader("📊 Sentiment Analysis") col1, col2 = st.columns(2) with col1: st.metric("Verdict", label) st.write(f"Confidence: {positive_score:.2%}") with col2: progress_color = "#4CAF50" if label=="Positive 👍" else "#FF5252" st.markdown(f"""