import gradio as gr from transformers import pipeline, AutoModelForSequenceClassification, AutoTokenizer # Load the model from the hub model = AutoModelForSequenceClassification.from_pretrained("MALEKSAHLIA/fine-tuned-sentiment-model-imdb") tokenizer = AutoTokenizer.from_pretrained("MALEKSAHLIA/fine-tuned-sentiment-model-imdb") # Create a pipeline for sentiment analysis nlp = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer) def predict_sentiment(sentence): result = nlp(sentence) sentiment = "Positive" if result[0]['label'] == 'LABEL_1' else "Negative" # Adjust the label to match your model's output return sentiment iface = gr.Interface( fn=predict_sentiment, inputs="text", outputs="text", title="Sentiment Analysis", description="Enter a sentence to get the sentiment (Positive or Negative)." ) iface.launch()