import gradio as gr from joblib import load # Load the model and preprocessing artifacts model = load("logistic_model.joblib") tfidf_vectorizer = load("tfidf_vectorizer.joblib") mlb = load("label_binarizer.joblib") # Define a function to classify commit messages def classify_commit(message): # Preprocess the input message X_tfidf = tfidf_vectorizer.transform([message]) # Predict the labels prediction = model.predict(X_tfidf) predicted_labels = mlb.inverse_transform(prediction) # Return the predicted labels as a comma-separated string return ", ".join(predicted_labels[0]) if predicted_labels[0] else "No labels" # Create a Gradio interface with enhanced aesthetics demo = gr.Interface( fn=classify_commit, inputs=gr.Textbox( label="Enter Commit Message", placeholder="Type your commit message here...", lines=3, max_lines=5, ), outputs=gr.Textbox(label="Predicted Labels"), title="🚀 Commit Message Classifier", description="📜 This tool classifies commit messages into categories like 'bug fix', 'feature addition', and more. Enter a message to see the predicted labels.", examples=[ ["Fixed a bug in the login feature"], ["Added a new user dashboard"], ["Updated order processing logic"], ["Refactored the payment module for better performance"], ], theme="compact", # Optional: A compact Gradio theme ) # Launch the Gradio app demo.launch(share=True, server_port=7860)