Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,15 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
import pickle
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
# π Load model files
|
| 8 |
try:
|
|
@@ -12,7 +19,7 @@ try:
|
|
| 12 |
with open("model (3).pkl", "rb") as f:
|
| 13 |
model = pickle.load(f)
|
| 14 |
|
| 15 |
-
with open("mlb (
|
| 16 |
mlb = pickle.load(f)
|
| 17 |
|
| 18 |
except Exception as e:
|
|
@@ -28,11 +35,10 @@ def predict_tags(title, description):
|
|
| 28 |
input_text = title + " " + description
|
| 29 |
input_vector = vectorizer.transform([input_text])
|
| 30 |
prediction = model.predict(input_vector)
|
| 31 |
-
|
| 32 |
predicted_tags = mlb.inverse_transform(prediction)
|
| 33 |
|
| 34 |
if predicted_tags and predicted_tags[0]:
|
| 35 |
-
return "β
|
| 36 |
else:
|
| 37 |
return "βΉοΈ No tags predicted. Try refining your question."
|
| 38 |
|
|
@@ -40,12 +46,12 @@ def predict_tags(title, description):
|
|
| 40 |
return f"β Error during prediction: {str(e)}"
|
| 41 |
|
| 42 |
# π Streamlit UI
|
| 43 |
-
st.title("
|
| 44 |
-
st.markdown("Enter a question title and description to
|
| 45 |
|
| 46 |
title = st.text_input("π Enter Question Title")
|
| 47 |
description = st.text_area("π Enter Question Description", height=150)
|
| 48 |
|
| 49 |
-
if st.button("
|
| 50 |
result = predict_tags(title, description)
|
| 51 |
-
st.markdown(result)
|
|
|
|
|
|
|
| 1 |
import pickle
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import os
|
| 4 |
+
import numpy as np
|
| 5 |
|
| 6 |
+
# π‘ Define the custom tokenizer exactly as used during training
|
| 7 |
+
def custom_tokenizer(text):
|
| 8 |
+
# Modify this function to match your original tokenizer logic
|
| 9 |
+
return text.lower().split()
|
| 10 |
+
|
| 11 |
+
# π§ Debug: Show current directory contents to verify files
|
| 12 |
+
st.write("π Files in current directory:", os.listdir())
|
| 13 |
|
| 14 |
# π Load model files
|
| 15 |
try:
|
|
|
|
| 19 |
with open("model (3).pkl", "rb") as f:
|
| 20 |
model = pickle.load(f)
|
| 21 |
|
| 22 |
+
with open("mlb (2).pkl", "rb") as f:
|
| 23 |
mlb = pickle.load(f)
|
| 24 |
|
| 25 |
except Exception as e:
|
|
|
|
| 35 |
input_text = title + " " + description
|
| 36 |
input_vector = vectorizer.transform([input_text])
|
| 37 |
prediction = model.predict(input_vector)
|
|
|
|
| 38 |
predicted_tags = mlb.inverse_transform(prediction)
|
| 39 |
|
| 40 |
if predicted_tags and predicted_tags[0]:
|
| 41 |
+
return "β
Predicted Tags: " + ", ".join(predicted_tags[0])
|
| 42 |
else:
|
| 43 |
return "βΉοΈ No tags predicted. Try refining your question."
|
| 44 |
|
|
|
|
| 46 |
return f"β Error during prediction: {str(e)}"
|
| 47 |
|
| 48 |
# π Streamlit UI
|
| 49 |
+
st.title("π Stack Overflow Tags Predictor")
|
| 50 |
+
st.markdown("Enter a question title and description to predict relevant tags.")
|
| 51 |
|
| 52 |
title = st.text_input("π Enter Question Title")
|
| 53 |
description = st.text_area("π Enter Question Description", height=150)
|
| 54 |
|
| 55 |
+
if st.button("Predict Tags"):
|
| 56 |
result = predict_tags(title, description)
|
| 57 |
+
st.markdown(result)
|