|
import streamlit as st |
|
from transformers import pipeline |
|
|
|
def analyze_financial_news(): |
|
access = "hf_" |
|
token = "hhbFNpjKohezoexWMlyPUpvJQLWlaFhJaa" |
|
|
|
|
|
classification = pipeline("text-classification", model="nickmuchi/finbert-tone-finetuned-finance-topic-classification", token=access+token) |
|
sentiment_analysis = pipeline("sentiment-analysis") |
|
|
|
st.set_page_config(page_title="Financial News Analysis", page_icon="β") |
|
|
|
|
|
st.title("Financial News Analysis") |
|
st.write("Analyze corresponding Topic and Trend for Financial News!") |
|
st.image("./Fin.jpg", use_column_width=True) |
|
|
|
|
|
text = st.text_area("Enter the Financial News", "") |
|
|
|
analyze_clicked = st.button("Analyze") |
|
|
|
if analyze_clicked: |
|
|
|
results = classification(text) |
|
|
|
|
|
energy_oil_news = [news for news in results if news["label"] == "Energy | Oil"] |
|
|
|
if energy_oil_news: |
|
|
|
for news in energy_oil_news: |
|
sentiment_results = sentiment_analysis(news["sequence"])[0] |
|
|
|
|
|
st.write("Original Text:", news["sequence"]) |
|
st.write("Sentiment:", sentiment_results["label"]) |
|
st.write("Sentiment Score:", sentiment_results["score"]) |
|
st.write("---") |
|
else: |
|
st.write("No news relevant to Energy | Oil.") |
|
|
|
def main(): |
|
analyze_financial_news() |
|
|
|
if __name__ == "__main__": |
|
main() |
|
|
|
|