JoanParanoid's picture
Update app.py
5c6e809 verified
raw
history blame
1.96 kB
import streamlit as st
from transformers import pipeline
def analyze_financial_news():
access = "hf_"
token = "hhbFNpjKohezoexWMlyPUpvJQLWlaFhJaa"
# Load the text classification model pipeline
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="β™•")
# Streamlit application layout
st.title("Financial News Analysis")
st.write("Analyze corresponding Topic and Trend for Financial News!")
st.image("./Fin.jpg", use_column_width=True)
# Text input for user to enter the text
text = st.text_area("Enter the Financial News", "")
analyze_clicked = st.button("Analyze")
if analyze_clicked:
# Perform text classification on the input text
results = classification(text)
# Filter only the news related to "Energy | Oil"
energy_oil_news = [news for news in results if news["label"] == "Energy | Oil"]
st.write("Energy | Oil News:", energy_oil_news) # Debug statement to check the Energy | Oil news list
if energy_oil_news:
# If there are news related to "Energy | Oil", perform sentiment analysis for each news
for idx, news in enumerate(energy_oil_news, start=1):
# Print the structure of each news to find the correct key for the news text
st.write(f"News {idx} structure:")
st.write(news)
# Uncomment the following line once you identify the correct key for the news text
# sentiment_results = sentiment_analysis(news["<correct_key_for_text>"])[0]
else:
st.write("No news relevant to Energy | Oil.")
def main():
analyze_financial_news()
if __name__ == "__main__":
main()