sunil23391/try_model_implementation
0
1import os2os.system('pip install transformers')3os.system('pip install torch')4 5# Import required libraries6import torch7import transformers8import streamlit as st9from transformers import pipeline10 11# Initialize the Streamlit app12st.set_page_config(layout="wide")13st.header("Sentiment Analysis App")14 15# Define the function for performing sentiment analysis16def analyze_sentiment(text):17 # Load the pre-trained sentiment analysis model and tokenizer18 model = pipeline('sentiment-analysis')19 20 # Perform sentiment analysis on the input text21 result = model(text)[0]['label']22 23 # Return the predicted sentiment label24 return result25 26# Create the user input form27with st.form(key='sentiment_analysis'):28 col1, col2 = st.columns(2)29 with col1:30 text_input = st.text_area("Enter Text:", "", key="my_input")31 with col2:32 submitted = st.form_submit_button("Submit")33 34# Display the sentiment analysis results35if submitted:36 sentiment = analyze_sentiment(text_input)37 st.subheader("Sentiment Analysis Result:")38 st.write(f"**Predicted Sentiment:** {sentiment}")