Spaces:
Runtime error
Runtime error
ZephyruSalsify
commited on
Commit
•
0d35448
1
Parent(s):
eb8b0c1
Upload app (1).py
Browse files- app (1).py +44 -0
app (1).py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
def analyze_financial_news():
|
5 |
+
access = "hf_"
|
6 |
+
token = "hhbFNpjKohezoexWMlyPUpvJQLWlaFhJaa"
|
7 |
+
|
8 |
+
# Load the text classification model and finetuned model pipeline
|
9 |
+
classification = pipeline("text-classification", model="nickmuchi/finbert-tone-finetuned-finance-topic-classification", token=access+token)
|
10 |
+
sentiment_analysis = pipeline("text-classification", model="JoanParanoid/FinNews_SentimentAnalysis_v2")
|
11 |
+
|
12 |
+
st.set_page_config(page_title="Energy/Oil-Related Financial News Sentiment Analysis", page_icon="♕")
|
13 |
+
|
14 |
+
# Streamlit application layout
|
15 |
+
st.title("Energy/Oil-Related Financial News Sentiment Analysis")
|
16 |
+
st.write("Conduct Sentiment Analysis for Energy/Oil-Related Financial News to Find Out the Trend In Energy/Oil Industry and Make Wise Decisions!")
|
17 |
+
st.image("./Fin.jpg", use_column_width=True)
|
18 |
+
|
19 |
+
# Text input for user to enter the text
|
20 |
+
text = st.text_area("Enter the Financial News Content", "")
|
21 |
+
|
22 |
+
analyze_clicked = st.button("Analyze")
|
23 |
+
|
24 |
+
if analyze_clicked:
|
25 |
+
# Perform text classification on the input text
|
26 |
+
results = classification(text)[0]
|
27 |
+
|
28 |
+
# Check if the classification is "Energy | Oil"
|
29 |
+
if results["label"] == "Energy | Oil":
|
30 |
+
# If the news is related to Energy | Oil, perform sentiment analysis
|
31 |
+
sentiment_results = sentiment_analysis(text)[0]
|
32 |
+
|
33 |
+
# Display the sentiment analysis result
|
34 |
+
st.write("This financial news belongs to the 'Energy | Oil' category.")
|
35 |
+
st.write("Sentiment:", sentiment_results["label"])
|
36 |
+
st.write("Sentiment Score:", sentiment_results["score"])
|
37 |
+
else:
|
38 |
+
st.write("This financial news does not belong to the 'Energy | Oil' category. Please enter a relevant news article.")
|
39 |
+
|
40 |
+
def main():
|
41 |
+
analyze_financial_news()
|
42 |
+
|
43 |
+
if __name__ == "__main__":
|
44 |
+
main()
|