ml-positivity / app.py
Mediocre-Judge's picture
Create app.py
b82c1e8 verified
Raw
History Blame Contribute Delete
1.05 kB
import gradio as gr
import joblib
# Load trained model and vectorizer
try:
model = joblib.load("positivity_model.pkl")
vectorizer = joblib.load("vectorizer.pkl")
print("βœ… Model and vectorizer loaded successfully.")
except Exception as e:
raise RuntimeError(f"Error loading model: {e}")
# Define the prediction function
def predict_sentiment(text):
"""Predicts positivity score based on input text."""
features = vectorizer.transform([text])
score = model.predict(features)[0]
return f"Positivity Score: {round(float(score), 2)}"
# Gradio Interface
with gr.Blocks() as app:
gr.Markdown("# 😊 Sentiment Analysis Model")
gr.Markdown("Enter text and get a positivity score!")
text_input = gr.Textbox(label="Input Text")
output_label = gr.Label(label="Positivity Score")
btn = gr.Button("Predict")
btn.click(predict_sentiment, inputs=text_input, outputs=output_label)
gr.Markdown("πŸš€ Powered by a Machine Learning Model")
# Launch app
if __name__ == "__main__":
app.launch()