Spaces:
Sleeping
Sleeping
File size: 1,053 Bytes
58e4258 69d2881 edc2460 eddc41b edc2460 ab5098c edc2460 9b07141 edc2460 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
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}") |