sunil23391's picture
Update app.py
28933e8 verified
raw
history blame
No virus
1.11 kB
import os
os.system('pip install transformers')
os.system('pip install torch')
# Import required libraries
import torch
import transformers
import streamlit as st
from transformers import pipeline
# Initialize the Streamlit app
st.set_page_config(layout="wide")
st.header("Sentiment Analysis App")
# Define the function for performing sentiment analysis
def analyze_sentiment(text):
# Load the pre-trained sentiment analysis model and tokenizer
model = pipeline('sentiment-analysis')
# Perform sentiment analysis on the input text
result = model(text)[0]['label']
# Return the predicted sentiment label
return result
# Create the user input form
with st.form(key='sentiment_analysis'):
col1, col2 = st.columns(2)
with col1:
text_input = st.text_area("Enter Text:", "", key="my_input")
with col2:
submitted = st.form_submit_button("Submit")
# Display the sentiment analysis results
if submitted:
sentiment = analyze_sentiment(text_input)
st.subheader("Sentiment Analysis Result:")
st.write(f"**Predicted Sentiment:** {sentiment}")