meriemm6's picture
Update app.py
68ffa12 verified
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 Improved Aesthetics
custom_css = """
body {
background-color: #e6f7ff; /* Light Blue Background */
font-family: 'Arial', sans-serif;
}
.gradio-container {
padding: 20px;
border-radius: 10px;
box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.2);
max-width: 800px;
margin: auto;
}
h1, h2 {
color: #004d80; /* Darker Blue for headings */
text-align: center;
}
footer {
text-align: center;
color: #555;
font-size: 12px;
}
"""
# Create the layout with Gradio Blocks
with gr.Blocks(css=custom_css) as demo:
gr.Markdown("<h1>🐳 Dockerfile Commit Message Classifier</h1>")
gr.Markdown(
"""
<p>πŸ” Use this tool to classify Dockerfile-related commit messages into categories like <b>'bug fix'</b>,
<b>'feature addition'</b>, and more. Enter a commit message below to see the prediction.</p>
"""
)
with gr.Row():
with gr.Column(scale=1):
commit_message_input = gr.Textbox(
label="Enter Commit Message",
placeholder="Type your Dockerfile-related commit message here...",
lines=3,
max_lines=5,
)
with gr.Column(scale=1):
predicted_output = gr.Textbox(
label="Predicted Labels",
interactive=False,
lines=2,
)
classify_button = gr.Button("Classify", elem_id="classify-btn")
classify_button.click(
classify_commit, inputs=commit_message_input, outputs=predicted_output
)
gr.Markdown("<h2>πŸ“ Examples</h2>")
gr.Examples(
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"],
],
inputs=commit_message_input,
)
gr.Markdown(
"""
<footer>
<p>βš™οΈ Built with ❀️ using <b>Gradio</b>. Try it now!</p>
</footer>
"""
)
# Launch the Gradio app
demo.launch(share=True, server_port=7860)