Update app.py
Browse files
app.py
CHANGED
|
@@ -1,33 +1,42 @@
|
|
| 1 |
-
import os
|
| 2 |
import streamlit as st
|
| 3 |
-
from transformers import pipeline
|
| 4 |
|
| 5 |
def analyze_financial_news():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
st.title("Financial News Analysis")
|
| 7 |
st.write("Analyze corresponding Topic and Trend for Financial News!")
|
| 8 |
st.image("./Fin.jpg", use_column_width=True)
|
| 9 |
|
| 10 |
-
# Text input for user to enter the
|
| 11 |
text = st.text_area("Enter the Financial News", "")
|
| 12 |
|
| 13 |
-
|
| 14 |
-
summarization_pipe = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 15 |
-
|
| 16 |
-
# Use pipeline as a high-level helper
|
| 17 |
-
summary = summarization_pipe(text)[0]['summary_text']
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
def main():
|
| 30 |
-
st.set_page_config(page_title="Financial News Analysis", page_icon="♕")
|
| 31 |
analyze_financial_news()
|
| 32 |
|
| 33 |
if __name__ == "__main__":
|
|
|
|
|
|
|
| 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 pipeline
|
| 9 |
+
classification = pipeline("text-classification", model="nickmuchi/finbert-tone-finetuned-finance-topic-classification", token=access+token)
|
| 10 |
+
sentiment_analysis = pipeline("sentiment-analysis")
|
| 11 |
+
|
| 12 |
+
st.set_page_config(page_title="Financial News Analysis", page_icon="♕")
|
| 13 |
+
|
| 14 |
+
# Streamlit application layout
|
| 15 |
st.title("Financial News Analysis")
|
| 16 |
st.write("Analyze corresponding Topic and Trend for Financial News!")
|
| 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", "")
|
| 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("Sentiment:", sentiment_results["label"])
|
| 35 |
+
st.write("Sentiment Score:", sentiment_results["score"])
|
| 36 |
+
else:
|
| 37 |
+
st.write("The provided news is not relevant to Energy | Oil.")
|
| 38 |
|
| 39 |
def main():
|
|
|
|
| 40 |
analyze_financial_news()
|
| 41 |
|
| 42 |
if __name__ == "__main__":
|