liry1312 commited on
Commit
512ed50
verified
1 Parent(s): a1deda2

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +26 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
4
+
5
+ # 讟讜注谉 讗转 讛诪讜讚诇 FinBERT 驻注诐 讗讞转 讘诇讘讚
6
+ tokenizer = AutoTokenizer.from_pretrained("ProsusAI/finbert")
7
+ model = AutoModelForSequenceClassification.from_pretrained("ProsusAI/finbert")
8
+ pipe = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
9
+
10
+ # 驻讜谞拽爪讬讬转 谞讬转讜讞 讛住谞讟讬诪谞讟
11
+ def analyze_sentiment(text):
12
+ result = pipe(text)[0]
13
+ label = result["label"]
14
+ score = round(result["score"] * 100, 2)
15
+ return f"住谞讟讬诪谞讟: {label}\n讘讬讟讞讜谉: {score}%"
16
+
17
+ # 讛讙讚专转 讛诪诪砖拽 注诐 Gradio
18
+ iface = gr.Interface(
19
+ fn=analyze_sentiment,
20
+ inputs=gr.Textbox(lines=4, label="讛讻谞住 讻讜转专转 驻讬谞谞住讬转"),
21
+ outputs=gr.Textbox(label="转讜爪讗讛"),
22
+ title="馃攳 谞讬转讜讞 住谞讟讬诪谞讟 驻讬谞谞住讬 注诐 FinBERT",
23
+ description="讛讝谉 讻讜转专转 讞讚砖讜转 驻讬谞谞住讬转 讻讚讬 诇拽讘诇 住讬讜讜讙 住谞讟讬诪谞讟 (讞讬讜讘讬 / 砖诇讬诇讬 / 谞讬讟专诇讬)"
24
+ )
25
+
26
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio
2
+ transformers
3
+ torch