| import gradio as gr |
| from joblib import load |
|
|
| |
| model = load("logistic_model.joblib") |
| tfidf_vectorizer = load("tfidf_vectorizer.joblib") |
| mlb = load("label_binarizer.joblib") |
|
|
| |
| def classify_commit(message): |
| |
| X_tfidf = tfidf_vectorizer.transform([message]) |
|
|
| |
| prediction = model.predict(X_tfidf) |
| predicted_labels = mlb.inverse_transform(prediction) |
|
|
| |
| return ", ".join(predicted_labels[0]) if predicted_labels[0] else "No labels" |
|
|
| |
| 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; |
| } |
| """ |
|
|
| |
| 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> |
| """ |
| ) |
|
|
| |
| demo.launch(share=True, server_port=7860) |
|
|