import streamlit as st from transformers import pipeline, AutoModelForSequenceClassification, AutoTokenizer def main(): # Streamlit app interface design with updated title and emoji usage st.title("📈 Financial Text Analysis") # User input area with updated prompt and emoji user_input = st.text_area("📝 Text Input", height=300) # Initialize sentiment analysis and summarization pipelines only once using st.session_state if 'sentiment_analyzer' not in st.session_state: # Load your custom sentiment analysis model with updated paths model = AutoModelForSequenceClassification.from_pretrained("WRX020510/CustomModel_twitter", num_labels=3) tokenizer = AutoTokenizer.from_pretrained("cardiffnlp/twitter-roberta-base-sentiment-latest") st.session_state.sentiment_analyzer = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer) if 'summarizer' not in st.session_state: st.session_state.summarizer = pipeline("summarization", model="t5-small") # Sentiment Analysis Section with st.container(): st.write("🔍 Sentiment Analysis") if st.button("Analyze Sentiment"): if user_input: with st.spinner('Analyzing sentiment...'): sentiment_result = st.session_state.sentiment_analyzer(user_input) sentiment = sentiment_result[0]['label'] confidence = sentiment_result[0]['score'] st.write(f"Sentiment: {sentiment} with Confidence: {confidence:.2f}") else: st.error("Please enter some text to analyze sentiment.") # Summary Section with updated header with st.container(): st.write("📜 Summary") if st.button("Generate Summary"): if user_input: with st.spinner('Generating summary...'): summary_result = st.session_state.summarizer(user_input, max_length=130, min_length=30, do_sample=False) summary = summary_result[0]['summary_text'] st.write(summary) else: st.error("Please enter some text to generate a summary.") if __name__ == "__main__": main()