WRX020510 commited on
Commit
3ee3a5a
Β·
verified Β·
1 Parent(s): 4ab9396

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -7
app.py CHANGED
@@ -1,19 +1,38 @@
1
  import streamlit as st
2
- from transformers import pipeline
3
 
4
  def main():
5
  # Streamlit app interface design
6
- st.title("πŸ“ˆ Financial Text Summarization with T5")
7
- st.write("Please enter the financial text below to generate a concise summary:")
8
 
9
  # User input area for text
10
- user_input = st.text_area("Text Input πŸ“", height=300)
11
 
12
- # Initialize the summarization pipeline only once using st.session_state
 
 
 
 
 
 
 
13
  if 'summarizer' not in st.session_state:
14
- # Initialize the pipeline with the T5 model for summarization
15
  st.session_state.summarizer = pipeline("summarization", model="t5-small")
16
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  # Button to generate summary
18
  if st.button("Generate Summary"):
19
  if user_input:
@@ -21,7 +40,7 @@ def main():
21
  # Generating the summary from the input text
22
  summary_result = st.session_state.summarizer(user_input, max_length=130, min_length=30, do_sample=False)
23
  summary = summary_result[0]['summary_text']
24
- st.write("Summary πŸ“œ:")
25
  st.write(summary)
26
  else:
27
  st.error("Please enter some text to generate a summary.")
 
1
  import streamlit as st
2
+ from transformers import pipeline, AutoModelForSequenceClassification, AutoTokenizer
3
 
4
  def main():
5
  # Streamlit app interface design
6
+ st.title("πŸ“ˆ Financial Text Analysis")
7
+ st.write("Enter the financial text below to analyze its sentiment and generate a summary:")
8
 
9
  # User input area for text
10
+ user_input = st.text_area("πŸ“ Text Input", height=300)
11
 
12
+ # Load sentiment analysis pipeline only once using st.session_state
13
+ if 'sentiment_analyzer' not in st.session_state:
14
+ # Load your custom sentiment analysis model
15
+ model = AutoModelForSequenceClassification.from_pretrained("path_to/CustomModel_twitter", num_labels=3)
16
+ tokenizer = AutoTokenizer.from_pretrained("path_to/CustomModel_twitter")
17
+ st.session_state.sentiment_analyzer = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
18
+
19
+ # Load summarization pipeline only once using st.session_state
20
  if 'summarizer' not in st.session_state:
21
+ # Load the T5 model for summarization
22
  st.session_state.summarizer = pipeline("summarization", model="t5-small")
23
 
24
+ # Button to analyze sentiment
25
+ if st.button("Analyze Sentiment"):
26
+ if user_input:
27
+ with st.spinner('Analyzing sentiment...'):
28
+ # Performing sentiment analysis
29
+ sentiment_result = st.session_state.sentiment_analyzer(user_input)
30
+ sentiment = sentiment_result[0]['label']
31
+ confidence = sentiment_result[0]['score']
32
+ st.write(f"Sentiment: {sentiment} with Confidence: {confidence:.2f}")
33
+ else:
34
+ st.error("Please enter some text to analyze sentiment.")
35
+
36
  # Button to generate summary
37
  if st.button("Generate Summary"):
38
  if user_input:
 
40
  # Generating the summary from the input text
41
  summary_result = st.session_state.summarizer(user_input, max_length=130, min_length=30, do_sample=False)
42
  summary = summary_result[0]['summary_text']
43
+ st.write("πŸ“œ Summary:")
44
  st.write(summary)
45
  else:
46
  st.error("Please enter some text to generate a summary.")