|
|
import gradio as gr |
|
|
import tensorflow as tf |
|
|
import pickle |
|
|
import numpy as np |
|
|
|
|
|
|
|
|
model = tf.keras.models.load_model("subway_alert_classifier_model.keras") |
|
|
vectorizer = pickle.load(open("tfidf_vectorizer.pkl", "rb")) |
|
|
label_encoder = pickle.load(open("label_encoder.pkl", "rb")) |
|
|
|
|
|
def classify_alert(text): |
|
|
X = vectorizer.transform([text]) |
|
|
y_pred = model.predict(X) |
|
|
label = label_encoder.inverse_transform([np.argmax(y_pred)]) |
|
|
return label[0] |
|
|
|
|
|
iface = gr.Interface( |
|
|
fn=classify_alert, |
|
|
inputs=gr.Textbox(lines=2, placeholder="Enter MTA alert description"), |
|
|
outputs="text", |
|
|
title="Subway Delay Cause Classifier", |
|
|
description="Classifies MTA alerts into causes like 'track', 'signals', 'medical', etc." |
|
|
) |
|
|
|
|
|
iface.launch() |
|
|
|