Dr. Khushter Kaifi commited on
Commit
c840b8c
·
unverified ·
1 Parent(s): 0868524

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Finacial Sentiment Analysis Using Huggingface App
2
+ # Team Name :- Free Thinkers
3
+ # Authors:- Lalit Chaudhary and Khushter Kaifi
4
+
5
+ # streamlit is a Python library used for creating web applications with minimal effort.
6
+ # pipeline is a class from the Hugging Face Transformers library that allows you to easily use pre-trained models for various natural language processing (NLP) tasks
7
+
8
+ import streamlit as st
9
+ from transformers import pipeline
10
+
11
+ # This line creates a sentiment analysis pipeline using the Hugging Face Transformers library.
12
+ # The pipeline is pre-configured to perform sentiment analysis on input text.
13
+ # # Load sentiment analysis pipeline
14
+ sentiment_pipeline = pipeline("sentiment-analysis")
15
+
16
+ # Sets the title of the Streamlit web application
17
+ st.title("Financial Sentiment Analysis Using HuggingFace 😎 \n Team Name:- Free Thinkers")
18
+
19
+ # Displays a text input box where the user can enter a sentence for sentiment analysis.
20
+ st.write("Enter a Sentence to Analyze the Sentiment:")
21
+ user_input = st.text_input("")
22
+ st.write("Press the Enter key")
23
+
24
+ # Performing Sentiment Analysis:
25
+ # Checks if the user has entered some text. If yes,
26
+ # it uses the sentiment_pipeline to analyze the sentiment of the input text and stores the result in the result variable.
27
+
28
+ if user_input:
29
+ result = sentiment_pipeline(user_input)
30
+ sentiment = result[0]["label"]
31
+ confidence = result[0]["score"]
32
+
33
+
34
+ # Displaying Results:
35
+ #If there is user input, it displays the sentiment and confidence score.
36
+ # The sentiment is extracted from the "label" field in the result, and the confidence score is extracted from the "score" field.
37
+ st.write(f"Sentiment: {sentiment}")
38
+ st.write(f"Confidence: {confidence:.2%}")