Spaces:
Sleeping
Sleeping
sanshizhang
commited on
Commit
β’
bafd7db
1
Parent(s):
6ab0ede
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline, AutoTokenizer, AutoModelForSeq2SeqLM
|
3 |
+
|
4 |
+
# ε θ½½δΈζζθ¦ζ¨‘ε
|
5 |
+
summarizer = pipeline("summarization", model="IDEA-CCNL/Randeng-Pegasus-523M-Summary-Chinese")
|
6 |
+
|
7 |
+
# ε θ½½δΈζζ
ζεζ樑ε
|
8 |
+
sentiment_analyzer = pipeline("sentiment-analysis", model="uer/roberta-base-finetuned-jd-binary-chinese")
|
9 |
+
|
10 |
+
def analyze_text(text):
|
11 |
+
# ηζζθ¦
|
12 |
+
summary = summarizer(text, max_length=150, min_length=50, do_sample=False)[0]['summary_text']
|
13 |
+
|
14 |
+
# εζζ
ζ
|
15 |
+
sentiment = sentiment_analyzer(text)[0]
|
16 |
+
sentiment_label = "η§―ζ" if sentiment['label'] == 'positive' else "ζΆζ"
|
17 |
+
sentiment_score = sentiment['score']
|
18 |
+
|
19 |
+
# ζ ΌεΌεθΎεΊ
|
20 |
+
result = f"ζθ¦οΌ\n{summary}\n\nζ
ζεΎεοΌ{sentiment_label}\nζ
ζεΎεοΌ{sentiment_score:.2f}"
|
21 |
+
|
22 |
+
return result
|
23 |
+
|
24 |
+
# εε»Ί Gradio ζ₯ε£
|
25 |
+
iface = gr.Interface(
|
26 |
+
fn=analyze_text,
|
27 |
+
inputs=gr.Textbox(lines=10, label="θΎε
₯δΈζζη« "),
|
28 |
+
outputs=gr.Textbox(label="εζη»ζ"),
|
29 |
+
title="δΈζζη« ζθ¦δΈζ
ζεζ",
|
30 |
+
description="θΎε
₯δΈζζη« οΌθ·εζθ¦εζ
ζεζη»ζγ"
|
31 |
+
)
|
32 |
+
|
33 |
+
# ε―ε¨ζ₯ε£
|
34 |
+
iface.launch()
|