Update app.py
Browse files
app.py
CHANGED
@@ -1,16 +1,41 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
sentiment_pipeline = pipeline("sentiment-analysis")
|
5 |
|
6 |
-
st.title("Financial Sentiment Analysis Using HuggingFace")
|
7 |
-
st.write("Enter a Sentence to Analyze the Sentiment:")
|
8 |
|
9 |
-
user_input = st.text_input("")
|
10 |
-
if user_input:
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# sentiment_pipeline = pipeline("sentiment-analysis")
|
5 |
|
6 |
+
# st.title("Financial Sentiment Analysis Using HuggingFace")
|
7 |
+
# st.write("Enter a Sentence to Analyze the Sentiment:")
|
8 |
|
9 |
+
# user_input = st.text_input("")
|
10 |
+
# if user_input:
|
11 |
+
# result = sentiment_pipeline(user_input)
|
12 |
+
# sentiment = result[0]["label"]
|
13 |
+
# confidence = result[0]["score"]
|
14 |
|
15 |
+
# st.write(f"Sentiment: {sentiment}")
|
16 |
+
# st.write(f"Confidence: {confidence:.2f}")
|
17 |
+
|
18 |
+
def analyze_sentiment(text):
|
19 |
+
sentiment_analyzer = pipeline("sentiment-analysis")
|
20 |
+
result = sentiment_analyzer(text)
|
21 |
+
return result[0]['label'], result[0]['score']
|
22 |
+
|
23 |
+
def main():
|
24 |
+
st.title("Financial Sentiment Analysis")
|
25 |
+
|
26 |
+
# User input
|
27 |
+
text_input = st.text_area("Enter financial news or tweet:", "")
|
28 |
+
|
29 |
+
if st.button("Analyze Sentiment"):
|
30 |
+
if text_input:
|
31 |
+
# Analyze sentiment
|
32 |
+
label, score = analyze_sentiment(text_input)
|
33 |
+
|
34 |
+
# Display results
|
35 |
+
st.write(f"Sentiment: {label}")
|
36 |
+
st.write(f"Confidence Score: {score:.2%}")
|
37 |
+
else:
|
38 |
+
st.warning("Please enter some text for analysis.")
|
39 |
+
|
40 |
+
if __name__ == "__main__":
|
41 |
+
main()
|