File size: 1,100 Bytes
53aa2c9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import streamlit as st
from transformers import pipeline

# 初始化情感分析pipeline
sentiment_pipeline = pipeline("sentiment-analysis")

# 设置页面标题
st.title("文本情感分析")

# 创建文本输入框
user_input = st.text_area("请输入要分析的文本:")

if user_input:
    # 执行情感分析
    result = sentiment_pipeline(user_input)[0]
    
    # 显示结果
    st.header("分析结果")
    
    # 根据情感标签显示不同的图标
    if result['label'] == 'POSITIVE':
        st.subheader("😊 积极情感")
    else:
        st.subheader("😔 消极情感")
    
    # 显示情感得分
    st.subheader(f"情感得分: {result['score']:.2f}")

    # 显示详细信息
    st.write(f"标签: {result['label']}")
    st.write(f"置信度: {result['score']:.2f}")

# 添加一些使用说明
st.sidebar.header("使用说明")
st.sidebar.write("1. 在文本框中输入您想要分析的文本。")
st.sidebar.write("2. 应用会自动进行情感分析。")
st.sidebar.write("3. 结果会显示情感是积极还是消极,以及相应的置信度。")