sree4411 commited on
Commit
c871c22
Β·
verified Β·
1 Parent(s): 867a0d8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -10
app.py CHANGED
@@ -1,8 +1,15 @@
1
- import streamlit as st
2
  import pickle
 
 
 
3
 
4
- # βœ… Set Streamlit page config (must be first command)
5
- st.set_page_config(page_title="πŸ”– Stack Overflow Multi-Tag Predictor", page_icon="🧠")
 
 
 
 
 
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 (1).pkl", "rb") as f:
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 "βœ… **Predicted Tags:** " + ", ".join(predicted_tags[0])
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("πŸ’¬ Stack Overflow Multi-Tag Predictor")
44
- st.markdown("Enter a question title and description to get multiple relevant tags.")
45
 
46
  title = st.text_input("πŸ“Œ Enter Question Title")
47
  description = st.text_area("πŸ“ Enter Question Description", height=150)
48
 
49
- if st.button("🎯 Predict Tags"):
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)