Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -16,8 +16,8 @@ def predict_single(text):
|
|
16 |
|
17 |
result = classifier(text)[0]
|
18 |
return {
|
19 |
-
"negative (stars 1, 2 and 3)": f"{1 - result['score']:.
|
20 |
-
"positive (stars 4 and 5)": f"{result['score']:.
|
21 |
}
|
22 |
|
23 |
def process_batch(file):
|
@@ -33,8 +33,8 @@ def process_batch(file):
|
|
33 |
pred = classifier(text)[0]
|
34 |
results.append({
|
35 |
"文本": text,
|
36 |
-
"negative (stars 1, 2 and 3)": f"{1 - pred['score']:.
|
37 |
-
"positive (stars 4 and 5)": f"{pred['score']:.
|
38 |
})
|
39 |
|
40 |
df = pd.DataFrame(results)
|
@@ -46,16 +46,24 @@ def process_batch(file):
|
|
46 |
|
47 |
# =============== 界面布局 ===============
|
48 |
with gr.Blocks(title="基于RoBERTa模型的中文情感分析系统", css="""
|
49 |
-
.gradio-container {max-width: 900px
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
# 标题和说明
|
53 |
gr.Markdown("""
|
54 |
# 基于RoBERTa模型的中文情感分析系统
|
55 |
-
|
56 |
**标签说明**:
|
57 |
positive:积极情绪(相当于评分4星和5星)
|
58 |
-
negative:消极情绪(相当于评分1星和
|
59 |
""")
|
60 |
|
61 |
# ===== 单句分析标签页 =====
|
@@ -114,9 +122,9 @@ with gr.Blocks(title="基于RoBERTa模型的中文情感分析系统", css="""
|
|
114 |
outputs=download_btn
|
115 |
)
|
116 |
|
117 |
-
#
|
118 |
gr.Markdown("---")
|
119 |
-
gr.Markdown("燕山大学文法学院
|
120 |
|
121 |
# 启动应用
|
122 |
demo.launch()
|
|
|
16 |
|
17 |
result = classifier(text)[0]
|
18 |
return {
|
19 |
+
"negative (stars 1, 2 and 3)": f"{1 - result['score']:.6f}" if result['label'] == 'positive' else f"{result['score']:.6f}",
|
20 |
+
"positive (stars 4 and 5)": f"{result['score']:.6f}" if result['label'] == 'positive' else f"{1 - result['score']:.6f}"
|
21 |
}
|
22 |
|
23 |
def process_batch(file):
|
|
|
33 |
pred = classifier(text)[0]
|
34 |
results.append({
|
35 |
"文本": text,
|
36 |
+
"negative (stars 1, 2 and 3)": f"{1 - pred['score']:.6f}" if pred['label'] == 'positive' else f"{pred['score']:.6f}",
|
37 |
+
"positive (stars 4 and 5)": f"{pred['score']:.6f}" if pred['label'] == 'positive' else f"{1 - pred['score']:.6f}"
|
38 |
})
|
39 |
|
40 |
df = pd.DataFrame(results)
|
|
|
46 |
|
47 |
# =============== 界面布局 ===============
|
48 |
with gr.Blocks(title="基于RoBERTa模型的中文情感分析系统", css="""
|
49 |
+
.gradio-container {max-width: 900px;
|
50 |
+
margin:0 auto !important;
|
51 |
+
padding:20px;
|
52 |
+
}
|
53 |
+
.df-table {width: 100%;
|
54 |
+
}
|
55 |
+
hi, .markdown-text{
|
56 |
+
text-align:center !important;
|
57 |
+
}
|
58 |
+
"""
|
59 |
+
) as demo:
|
60 |
# 标题和说明
|
61 |
gr.Markdown("""
|
62 |
# 基于RoBERTa模型的中文情感分析系统
|
63 |
+
本项目使用RoBERTa中文情感分类模型,实现积极与消极情绪的二分类分析
|
64 |
**标签说明**:
|
65 |
positive:积极情绪(相当于评分4星和5星)
|
66 |
+
negative:消极情绪(相当于评分1星、2星和3星)
|
67 |
""")
|
68 |
|
69 |
# ===== 单句分析标签页 =====
|
|
|
122 |
outputs=download_btn
|
123 |
)
|
124 |
|
125 |
+
# 页脚(居中)
|
126 |
gr.Markdown("---")
|
127 |
+
gr.Markdown("燕山大学文法学院 姜,联系方式: [email protected]")
|
128 |
|
129 |
# 启动应用
|
130 |
demo.launch()
|