sanshizhang commited on
Commit
bafd7db
β€’
1 Parent(s): 6ab0ede

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
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()