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" # Enhanced Gradio Interface demo = gr.Interface( fn=classify_commit, inputs=gr.Textbox( label="Enter Commit Message", placeholder="Type a commit message here...", lines=3 ), outputs=gr.Label(label="Predicted Categories"), title="šŸš€ Commit Message Classifier", description="šŸ“œ Enter a commit message to classify it into predefined categories.\n\nšŸ’” **Example:** \"Fixed a bug in login feature\" → Predicted Categories: `bug fix`", theme="default", examples=[ "Fixed a bug in login feature", "Added a new user dashboard", "Updated order processing logic", "Refactored payment module for better efficiency" ], live=True, allow_flagging="never" # Disable flagging for a cleaner look ) # Add a custom background and layout css = """ body { font-family: 'Arial', sans-serif; background-color: #f7f9fc; margin: 0; padding: 0; } #component-0 { background-color: #ffffff; border: 1px solid #ddd; border-radius: 10px; padding: 20px; box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.1); } textarea { font-size: 16px; border-radius: 5px; border: 1px solid #ccc; padding: 10px; resize: none; } label { font-weight: bold; font-size: 18px; } """ # Launch the Gradio app with custom styling demo.launch(share=True, server_port=7860, auth=("user", "password"), css=css)