Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,32 +1,36 @@
|
|
| 1 |
-
import numpy as np
|
| 2 |
-
import pandas as pd
|
| 3 |
-
import streamlit as st
|
| 4 |
import pickle
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
try:
|
| 8 |
-
with open("tfidf_vectorizer
|
| 9 |
vectorizer = pickle.load(f)
|
| 10 |
-
except FileNotFoundError:
|
| 11 |
-
st.error("β 'tfidf_vectorizer(1).pkl' not found. Please make sure the file is uploaded to the root directory.")
|
| 12 |
-
st.stop()
|
| 13 |
-
with open("model(1).pkl", "rb") as f:
|
| 14 |
-
model = pickle.load(f)
|
| 15 |
|
| 16 |
-
with open("
|
| 17 |
-
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
st.title("π Stack Overflow Tags Predictor")
|
| 23 |
-
st.
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
description = st.text_area("Enter Question Description:")
|
| 28 |
|
| 29 |
-
# Prediction logic
|
| 30 |
if st.button("Predict Tags"):
|
| 31 |
if not title.strip() or not description.strip():
|
| 32 |
st.warning("β οΈ Please enter both title and description.")
|
|
@@ -41,5 +45,6 @@ if st.button("Predict Tags"):
|
|
| 41 |
st.success("β
Predicted Tags: " + ", ".join(predicted_tags[0]))
|
| 42 |
else:
|
| 43 |
st.info("βΉοΈ No tags predicted. Try refining your question.")
|
|
|
|
| 44 |
except Exception as e:
|
| 45 |
-
st.error(f"β Error: {str(e)}")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import pickle
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import os
|
| 4 |
|
| 5 |
+
# Show current working directory and files for debugging
|
| 6 |
+
st.write("π Current directory:", os.getcwd())
|
| 7 |
+
st.write("π Files found:", os.listdir())
|
| 8 |
+
|
| 9 |
+
# Load the pickle files safely
|
| 10 |
try:
|
| 11 |
+
with open("tfidf_vectorizer.pkl", "rb") as f:
|
| 12 |
vectorizer = pickle.load(f)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
with open("model.pkl", "rb") as f:
|
| 15 |
+
model = pickle.load(f)
|
| 16 |
|
| 17 |
+
with open("mlb.pkl", "rb") as f:
|
| 18 |
+
mlb = pickle.load(f)
|
| 19 |
|
| 20 |
+
except FileNotFoundError as e:
|
| 21 |
+
st.error(f"β File not found: {e.filename}")
|
| 22 |
+
st.stop()
|
| 23 |
+
except Exception as e:
|
| 24 |
+
st.error(f"β Error loading model files: {str(e)}")
|
| 25 |
+
st.stop()
|
| 26 |
+
|
| 27 |
+
# Streamlit UI
|
| 28 |
st.title("π Stack Overflow Tags Predictor")
|
| 29 |
+
st.markdown("Enter a Stack Overflow question title and description to get predicted tags.")
|
| 30 |
|
| 31 |
+
title = st.text_input("Enter Question Title")
|
| 32 |
+
description = st.text_area("Enter Question Description", height=150)
|
|
|
|
| 33 |
|
|
|
|
| 34 |
if st.button("Predict Tags"):
|
| 35 |
if not title.strip() or not description.strip():
|
| 36 |
st.warning("β οΈ Please enter both title and description.")
|
|
|
|
| 45 |
st.success("β
Predicted Tags: " + ", ".join(predicted_tags[0]))
|
| 46 |
else:
|
| 47 |
st.info("βΉοΈ No tags predicted. Try refining your question.")
|
| 48 |
+
|
| 49 |
except Exception as e:
|
| 50 |
+
st.error(f"β Error during prediction: {str(e)}")
|