Spaces:
Sleeping
Sleeping
| 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() | |