meriemm6's picture
Update app.py
936d09f verified
raw
history blame
2.12 kB
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"
# Custom CSS for Light Blue Background
custom_css = """
body {
background-color: #d0f0fd; /* Light Blue */
}
"""
# Create a Gradio interface with Dockerfile-specific examples and visuals
demo = gr.Interface(
fn=classify_commit,
inputs=gr.Textbox(
label="Enter Commit Message",
placeholder="Type your Dockerfile-related commit message here...",
lines=3,
max_lines=5,
),
outputs=gr.Textbox(label="Predicted Labels"),
title="🐳 Dockerfile Commit Message Classifier",
description="πŸ” Classify commit messages related to Dockerfiles into categories like 'bug fix', 'feature addition', and more. Enter a commit message to get the predictions.",
examples=[
["Fixed an issue with the base image version in Dockerfile"],
["Added a new multistage build to optimize Docker image size"],
["Updated the Python version in Dockerfile to 3.10"],
["Sort Dockerfile"],
["Added COPY instruction for configuration files"],
],
article="""
**How to Use**:
- Enter a commit message related to Dockerfiles.
- The tool predicts categories such as 'bug fix', 'code refactoring', 'feature addition', or 'maintenance/other'.
**Examples**:
- Fixing base image versions.
- Adding new Docker build stages.
- Updating dependencies in Dockerfiles.
""",
css=custom_css,
)
# Launch the Gradio app
demo.launch(share=True, server_port=7860)