| |
| |
| |
|
|
| |
| |
|
|
| import gradio as gr |
| import fasttext |
| import re |
| from huggingface_hub import hf_hub_download |
| import os |
|
|
| |
| |
| |
| |
| REPO_ID = "Sheshank2609/Complaint_Classifier" |
| MODEL_FILENAME = "complaint_classifier.ftz" |
|
|
| |
| model_path = hf_hub_download(repo_id=REPO_ID, filename=MODEL_FILENAME) |
|
|
| |
| model = fasttext.load_model(model_path) |
|
|
| |
| |
| |
| def clean_text(text): |
| text = str(text).lower() |
| text = re.sub(r'\s+', ' ', text).strip() |
| return text |
|
|
| def normalize_slang(text): |
| replacements = { |
| "bakwass": "bakwas", |
| "boht": "bahut", |
| "nhi": "nahi", |
| "nai": "nahi", |
| "yaarrr": "yaar", |
| "yawwrrr": "yaar", |
| "pls": "please", |
| "plz": "please" |
| } |
| for k, v in replacements.items(): |
| text = text.replace(k, v) |
| return text |
|
|
| def boost_keywords(text): |
| if any(word in text for word in ["khana", "khaana", "Jevan", "food", "mess", "roti", "sabzi", "rice", "milk"]): |
| text += " mess food quality eating" |
|
|
| if any(word in text for word in ["ganda","flush","toilet", "washroom", "dirty", "dust", "garbage", "smell"]): |
| text += " cleanliness hygiene sanitation" |
|
|
| |
| if any(word in text for word in ["wifi", "internet", "net", "network", "server", "pcs", "system"]): |
| text += " technical network issue" |
|
|
| |
| if any(word in text for word in ["ac", "fan", "light", "door", "bench", "lock", "window"]): |
| text += " infrastructure maintenance" |
|
|
| |
| if any(word in text for word in ["teacher", "lecture", "class", "test", "exam", "assignment"]): |
| text += " academics study" |
|
|
| |
| if any(word in text for word in ["ragging", "bully", "harass", "senior"]): |
| text += " ragging harassment" |
|
|
| return text |
|
|
| |
| |
| |
| def predict_complaint_gradio(complaint_text): |
| |
| processed_text = clean_text(complaint_text) |
| processed_text = normalize_slang(processed_text) |
| processed_text = boost_keywords(processed_text) |
|
|
| |
| |
| predictions = model.predict(processed_text, k=1) |
| |
| |
| label = predictions[0][0].replace("__label__", "") |
| confidence = predictions[1][0] * 100 |
|
|
| return f"Department: {label}", f"Confidence: {confidence:.2f}%" |
|
|
| |
| |
| |
|
|
| |
| examples = [ |
| ["The projector in room 301 is not working. It's urgent for the class."], |
| ["My room is full of dust and cobwebs. Please send someone to clean it."], |
| ["The food in the mess is very spicy and unhealthy."], |
| ["The wifi is constantly disconnecting in my hostel room."], |
| ["The teacher didn't explain the concept properly in today's lecture."], |
| ["Seniors are bothering first-year students in the common area."] |
| ] |
|
|
| iface = gr.Interface( |
| fn=predict_complaint_gradio, |
| inputs=gr.Textbox(lines=5, placeholder="Enter your complaint here..."), |
| outputs=[gr.Textbox(label="Predicted Department"), gr.Textbox(label="Confidence")], |
| title="Student Complaint Classifier", |
| description="Enter a student complaint, and the model will classify it into the most relevant department along with a confidence score.", |
| examples=examples, |
| allow_flagging="manual" |
| ) |
|
|
| |
| |
| |
| if __name__ == "__main__": |
| iface.launch() |