Upload 2 files
Browse files- app.py +26 -0
- requirements.txt +4 -3
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import streamlit as st
|
| 3 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
|
| 4 |
+
|
| 5 |
+
st.set_page_config(page_title="Sentiment Analyzer", layout="centered")
|
| 6 |
+
|
| 7 |
+
@st.cache_resource
|
| 8 |
+
def load_pipeline():
|
| 9 |
+
tokenizer = AutoTokenizer.from_pretrained("ProsusAI/finbert")
|
| 10 |
+
model = AutoModelForSequenceClassification.from_pretrained("ProsusAI/finbert")
|
| 11 |
+
return pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
|
| 12 |
+
|
| 13 |
+
pipe = load_pipeline()
|
| 14 |
+
|
| 15 |
+
st.title("馃攳 谞讬转讜讞 住谞讟讬诪谞讟 砖诇 讻讜转专讜转 驻讬谞谞住讬讜转")
|
| 16 |
+
|
| 17 |
+
text = st.text_area("讛讻谞住 讻讜转专转 讞讚砖讜转 驻讬谞谞住讬转:")
|
| 18 |
+
|
| 19 |
+
if text:
|
| 20 |
+
with st.spinner("诪谞转讞..."):
|
| 21 |
+
result = pipe(text)[0]
|
| 22 |
+
st.markdown(f"""
|
| 23 |
+
### 转讜爪讗讛:
|
| 24 |
+
**住谞讟讬诪谞讟:** {result['label']}
|
| 25 |
+
**讘讬讟讞讜谉:** {round(result['score']*100, 2)}%
|
| 26 |
+
""")
|
requirements.txt
CHANGED
|
@@ -1,3 +1,4 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
streamlit
|
| 3 |
+
transformers
|
| 4 |
+
torch
|