Stack / app.py
sree4411's picture
Update app.py
7bd1bd8 verified
import pickle
import streamlit as st
# Load saved model, vectorizer, and binarizer
with open("vectorizer (3).pkl", "rb") as f:
vectorizer = pickle.load(f)
with open("model (6).pkl", "rb") as f:
model = pickle.load(f)
with open("binarizer (3).pkl", "rb") as f:
mlb = pickle.load(f)
st.title("πŸ”– Stack Overflow Tags Predictor")
st.markdown("Enter a question title and description. Tags will be predicted automatically.")
title = st.text_input("πŸ“Œ Enter Question Title")
description = st.text_area("πŸ“ Enter Question Description", height=150)
def predict_tags(title, description):
if not title.strip() or not description.strip():
return []
input_text = title + " " + description
input_vector = vectorizer.transform([input_text])
# Predict tags using the model's internal default threshold
predicted_binary = model.predict(input_vector)
tags = mlb.inverse_transform(predicted_binary)
return tags[0] if tags else []
if st.button("Predict Tags"):
tags = predict_tags(title, description)
if tags:
st.success("βœ… Predicted Tags: " + ", ".join(tags))
else:
st.info("ℹ️ No tags predicted. Try refining your question.")