Mastouri
commited on
Commit
·
5cfe83b
1
Parent(s):
e0daea5
Update Gradio app to integrate model and dataset
Browse files
app.py
CHANGED
|
@@ -1,7 +1,31 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from joblib import load
|
| 3 |
+
|
| 4 |
+
# Load the model and preprocessing artifacts
|
| 5 |
+
model = load("logistic_model.joblib")
|
| 6 |
+
tfidf_vectorizer = load("tfidf_vectorizer.joblib")
|
| 7 |
+
mlb = load("label_binarizer.joblib")
|
| 8 |
+
|
| 9 |
+
# Define a function to classify commit messages
|
| 10 |
+
def classify_commit(message):
|
| 11 |
+
# Preprocess the input message
|
| 12 |
+
X_tfidf = tfidf_vectorizer.transform([message])
|
| 13 |
+
|
| 14 |
+
# Predict the labels
|
| 15 |
+
prediction = model.predict(X_tfidf)
|
| 16 |
+
predicted_labels = mlb.inverse_transform(prediction)
|
| 17 |
+
|
| 18 |
+
# Return the predicted labels as a comma-separated string
|
| 19 |
+
return ", ".join(predicted_labels[0]) if predicted_labels[0] else "No labels"
|
| 20 |
+
|
| 21 |
+
# Create a Gradio interface
|
| 22 |
+
demo = gr.Interface(
|
| 23 |
+
fn=classify_commit, # Function to call
|
| 24 |
+
inputs=gr.Textbox(label="Enter Commit Message"), # Input: Textbox for commit message
|
| 25 |
+
outputs=gr.Textbox(label="Predicted Labels"), # Output: Textbox for predicted labels
|
| 26 |
+
title="Commit Message Classifier",
|
| 27 |
+
description="Enter a commit message to classify it into predefined categories."
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
# Launch the Gradio app
|
| 31 |
+
demo.launch()
|