# app.py import gradio as gr from sklearn.feature_extraction.text import TfidfVectorizer from sklearn.naive_bayes import MultinomialNB # Sample documents and labels documents = [ "I love data science and machine learning", # Positive "Data science is fun and exciting", # Positive "Machine learning is a part of data science", # Positive "I hate dealing with messy data", # Negative "Data preprocessing is so boring", # Negative "I dislike coding errors and bugs" # Negative ] labels = [1, 1, 1, 0, 0, 0] # 1 = Positive, 0 = Negative # Train model vectorizer = TfidfVectorizer() X = vectorizer.fit_transform(documents) model = MultinomialNB() model.fit(X, labels) # Prediction function def predict_sentiment(text): X_new = vectorizer.transform([text]) prediction = model.predict(X_new)[0] return "Positive 😊" if prediction == 1 else "Negative 😠" # Gradio interface interface = gr.Interface( fn=predict_sentiment, inputs=gr.Textbox(lines=2, placeholder="Enter your sentence here..."), outputs="text", title="Simple Test Sentiment Classifier (Beta)", description="Enter a sentence to classify it as Positive 😊 or Negative 😠." ) # Run the app if __name__ == "__main__": interface.launch()