import gradio as gr from transformers import pipeline import streamlit as st import socket # Load the pre-trained sentiment-analysis pipeline classifier = pipeline('sentiment-analysis') # Function to classify sentiment def classify_text(text): result = classifier(text)[0] return f"{result['label']} with score {result['score']}" # Function to find an available port def find_free_port(): with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: s.bind(('', 0)) return s.getsockname()[1] # Find an available port port = find_free_port() # Launch the Gradio interface on the dynamically found port iface = gr.Interface(fn=classify_text, inputs="text", outputs="text") iface.launch(server_port=port, share=True) # Streamlit code st.title('IMDb Sentiment Analysis') st.write('This project performs sentiment analysis on IMDb movie reviews using Streamlit.')