Spaces:
Runtime error
Runtime error
import streamlit as st | |
from transformers import pipeline | |
sentiment_analysis = pipeline("sentiment-analysis", model="nlptown/bert-base-multilingual-uncased-sentiment") | |
def perform_sentiment_analysis(text): | |
result = sentiment_analysis(text) | |
return {'label': result[0]['label'], 'score': result[0]['score']} | |
def main(): | |
st.title("Financial Sentiment Analysis") | |
# Input for financial content | |
financial_content = st.text_area("Enter Financial Content:", "With the launch of Apple Silicon, Apple shares have increased") | |
# Perform sentiment analysis on button click | |
if st.button("Submit"): | |
sentiment="Neutral" | |
if financial_content.strip(): | |
sentiment_result = perform_sentiment_analysis(financial_content | |
if sentiment_result['label'][0]=="5" or sentiment_result['label'][0]=="4" : | |
sentiment= "Positive" | |
elif sentiment_result['label'][0]=="1" or sentiment_result['label'][0]=="2" : | |
sentiment= "Negative" | |
st.success(f"Sentiment: {sentiment} with score: {sentiment_result['score']:.2f}") | |
else: | |
st.warning("Please enter financial content before submitting.") | |
if __name__ == "__main__": | |
main() | |