sree4411 commited on
Commit
a2bcae8
Β·
verified Β·
1 Parent(s): adca082

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -20
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
- # Load models using pickle
 
 
 
 
7
  try:
8
- with open("tfidf_vectorizer(1).pkl", "rb") as f:
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("mlb.pkl", "rb") as f:
17
- mlb = pickle.load(f)
18
 
19
- # Streamlit App UI
20
- st.set_page_config(page_title="πŸ”– Stack Overflow Tags Predictor", layout="centered")
21
 
 
 
 
 
 
 
 
 
22
  st.title("πŸ”– Stack Overflow Tags Predictor")
23
- st.write("Enter the question's title and description to get suggested tags.")
24
 
25
- # Input fields
26
- title = st.text_input("Enter Question Title:")
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)}")