Khushter's picture
Update app.py
000fd09
raw
history blame contribute delete
No virus
1.21 kB
import streamlit as st
from transformers import pipeline
# sentiment_pipeline = pipeline("sentiment-analysis")
# st.title("Financial Sentiment Analysis Using HuggingFace")
# st.write("Enter a Sentence to Analyze the Sentiment:")
# user_input = st.text_input("")
# if user_input:
# result = sentiment_pipeline(user_input)
# sentiment = result[0]["label"]
# confidence = result[0]["score"]
# st.write(f"Sentiment: {sentiment}")
# st.write(f"Confidence: {confidence:.2f}")
def analyze_sentiment(text):
sentiment_analyzer = pipeline("sentiment-analysis")
result = sentiment_analyzer(text)
return result[0]['label'], result[0]['score']
def main():
st.title("Financial Sentiment Analysis")
# User input
text_input = st.text_area("Enter financial news or tweet:", "")
if st.button("Analyze Sentiment"):
if text_input:
# Analyze sentiment
label, score = analyze_sentiment(text_input)
# Display results
st.write(f"Sentiment: {label}")
st.write(f"Confidence Score: {score:.2%}")
else:
st.warning("Please enter some text for analysis.")
if __name__ == "__main__":
main()