Spaces:
Sleeping
Sleeping
File size: 1,725 Bytes
311a5d9 c871c22 5c4ca1e c871c22 6fbaf6c d0301ba 8ddf816 050f824 867a0d8 050f824 a2bcae8 867a0d8 050f824 1a22490 050f824 f703295 8ddf816 46584b5 050f824 f703295 8ddf816 6fbaf6c f703295 c871c22 f703295 8ddf816 f703295 050f824 c871c22 d0301ba 8ddf816 d0301ba c871c22 8ddf816 c871c22 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
import pickle
import streamlit as st
import os
import numpy as np
# π‘ Define the custom tokenizer exactly as used during training
def custom_tokenizer(text):
# Modify this function to match your original tokenizer logic
return text.lower().split()
# π Load model files
try:
with open("tfidf.pkl", "rb") as f:
vectorizer = pickle.load(f)
with open("model (3).pkl", "rb") as f:
model = pickle.load(f)
with open("mlb (1).pkl", "rb") as f:
mlb = pickle.load(f)
except Exception as e:
st.error(f"β Error loading model files: {str(e)}")
st.stop()
# π§ Prediction function
def predict_tags(title, description):
try:
if not title.strip() or not description.strip():
return "β οΈ Please enter both title and description."
input_text = title + " " + description
input_vector = vectorizer.transform([input_text])
prediction = model.predict(input_vector)
predicted_tags = mlb.inverse_transform(prediction)
st.write(predicted_tags)
if predicted_tags and predicted_tags[0]:
return "β
Predicted Tags: " + ", ".join(predicted_tags[0])
else:
return "βΉοΈ No tags predicted. Try refining your question."
except Exception as e:
return f"β Error during prediction: {str(e)}"
# π Streamlit UI
st.title("π Stack Overflow Tags Predictor")
st.markdown("Enter a question title and description to predict relevant tags.")
title = st.text_input("π Enter Question Title")
description = st.text_area("π Enter Question Description", height=150)
if st.button("Predict Tags"):
result = predict_tags(title, description)
st.markdown(result) |