sunil23391 commited on
Commit
edc2460
1 Parent(s): 69d2881

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -11
app.py CHANGED
@@ -1,17 +1,37 @@
1
  import os
2
  os.system('pip install transformers')
3
  os.system('pip install torch')
4
- import streamlit as st
 
 
5
  import transformers
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
- classifier = transformers.pipeline("sentiment-analysis")
8
- txt = st.text_area(
9
- "Text to analyze",
10
- "It was the best of times, it was the worst of times, it was the age of "
11
- "wisdom, it was the age of foolishness, it was the epoch of belief, it "
12
- "was the epoch of incredulity, it was the season of Light, it was the "
13
- "season of Darkness, it was the spring of hope, it was the winter of "
14
- "despair, (...)",
15
- )
16
 
17
- st.write(f'You wrote {len(txt)} characters.\n {classifier(txt)}')
 
 
 
 
 
1
  import os
2
  os.system('pip install transformers')
3
  os.system('pip install torch')
4
+
5
+ # Import required libraries
6
+ import torch
7
  import transformers
8
+ import streamlit as st
9
+ from transformers import pipeline
10
+
11
+ # Initialize the Streamlit app
12
+ st.set_page_config(layout="wide")
13
+ st.header("Sentiment Analysis App")
14
+
15
+ # Define the function for performing sentiment analysis
16
+ def analyze_sentiment(text):
17
+ # Load the pre-trained sentiment analysis model and tokenizer
18
+ model = pipeline('sentiment-analysis')
19
+
20
+ # Perform sentiment analysis on the input text
21
+ result = model(text)[0]['label']
22
+
23
+ # Return the predicted sentiment label
24
+ return result
25
 
26
+ # Create the user input form
27
+ col1, col2 = st.beta_columns(2)
28
+ with col1:
29
+ text_input = st.text_area("Enter Text:", "", key="my_input")
30
+ with col2:
31
+ submitted = st.form_submit_button("Submit")
 
 
 
32
 
33
+ # Display the sentiment analysis results
34
+ if submitted:
35
+ sentiment = analyze_sentiment(text_input)
36
+ st.subheader("Sentiment Analysis Result:")
37
+ st.write(f"**Predicted Sentiment:** {sentiment}")