WRX020510 commited on
Commit
c7e6970
·
verified ·
1 Parent(s): 39a1750

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -14
app.py CHANGED
@@ -5,30 +5,22 @@ import torch
5
  def main():
6
  # 加载情感分析模型和tokenizer
7
  model = AutoModelForSequenceClassification.from_pretrained("WRX020510/CustomModel_twitter", num_labels=3)
8
- tokenizer = AutoTokenizer.from_pretrained("cardiffnlp/twitter-roberta-base-sentiment-latest")
9
  sentiment_pipeline = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
10
 
11
- # 加载文本摘要模型
12
- summarizer = pipeline("summarization", model="human-centered-summarization/financial-summarization-pegasus")
13
-
14
  # Streamlit 应用界面设计
15
- st.title("Financial Text Analysis with Hugging Face Spaces")
16
- st.write("Enter a financial text to analyze its sentiment and generate a summary:")
17
 
18
  # 用户输入
19
- user_input = st.text_area("Text Input", height=150)
20
 
21
  if user_input:
22
  # 情感分析
23
  sentiment_result = sentiment_pipeline(user_input)
24
  sentiment = sentiment_result[0]['label']
25
- st.write(f"Sentiment (0-2): {sentiment}")
26
-
27
- # 文本摘要
28
- summary_result = summarizer(user_input, max_length=130, min_length=30, do_sample=False)
29
- summary = summary_result[0]['summary_text']
30
- st.write("Summary:")
31
- st.write(summary)
32
 
33
  if __name__ == "__main__":
34
  main()
 
5
  def main():
6
  # 加载情感分析模型和tokenizer
7
  model = AutoModelForSequenceClassification.from_pretrained("WRX020510/CustomModel_twitter", num_labels=3)
8
+ tokenizer = AutoTokenizer.from_pretrained("cardiffnlp/twitter-roberta-base-sentiment-latest", use_fast=False)
9
  sentiment_pipeline = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
10
 
 
 
 
11
  # Streamlit 应用界面设计
12
+ st.title("📈 Financial Text Sentiment Analysis with Hugging Face Spaces 🚀")
13
+ st.write("Enter a financial text to analyze its sentiment:")
14
 
15
  # 用户输入
16
+ user_input = st.text_area("Text Input 📝", height=150)
17
 
18
  if user_input:
19
  # 情感分析
20
  sentiment_result = sentiment_pipeline(user_input)
21
  sentiment = sentiment_result[0]['label']
22
+ sentiment_icon = "😊" if sentiment == "LABEL_1" else "😟" if sentiment == "LABEL_0" else "😐"
23
+ st.write(f"Sentiment (0-2): {sentiment} {sentiment_icon}")
 
 
 
 
 
24
 
25
  if __name__ == "__main__":
26
  main()