Spaces:
Sleeping
Sleeping
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 | |
col1, col2 = st.beta_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}") |