sree4411 commited on
Commit
d0301ba
·
verified ·
1 Parent(s): b52dd36

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -44
app.py CHANGED
@@ -1,47 +1,42 @@
1
  import numpy as np
2
  import pandas as pd
3
  import streamlit as st
4
-
5
- import gradio as gr
6
- import joblib
7
-
8
- # Load artifacts using joblib
9
- vectorizer = joblib.load("tfidf_vectorizer(1).pkl")
10
- model = joblib.load("model(1).pkl")
11
- mlb = joblib.load("mlb.pkl")
12
-
13
- # Define prediction function
14
-
15
- def predict_tags(title, description):
16
- try:
17
- print(f"[DEBUG] Title: {repr(title)}")
18
- print(f"[DEBUG] Description: {repr(description)}")
19
-
20
- if not title.strip() or not description.strip():
21
- return "⚠️ Please enter both title and description."
22
-
23
- input_text = title + " " + description
24
- input_vector = vectorizer.transform([input_text])
25
- prediction = model.predict(input_vector)
26
- predicted_tags = mlb.inverse_transform(prediction)
27
-
28
- if predicted_tags and predicted_tags[0]:
29
- return " Predicted Tags: " + ", ".join(predicted_tags[0])
30
- else:
31
- return "ℹ️ No tags predicted. Try refining your question."
32
-
33
- except Exception as e:
34
- return f"❌ Error: {str(e)}"
35
-
36
- # Gradio app
37
- iface = gr.Interface(
38
- fn=predict_tags,
39
- inputs=[
40
- gr.Textbox(label="Enter Question Title", type="text"),
41
- gr.Textbox(label="Enter Question Description", lines=4, type="text")
42
- ],
43
- outputs="text",
44
- title="🔖 Stack Overflow Tags Predictor",
45
- description="Enter a question's title and description to get tag suggestions."
46
- )
47
- iface.launch()
 
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
+ with open("tfidf_vectorizer(1).pkl", "rb") as f:
8
+ vectorizer = pickle.load(f)
9
+
10
+ with open("model(1).pkl", "rb") as f:
11
+ model = pickle.load(f)
12
+
13
+ with open("mlb.pkl", "rb") as f:
14
+ mlb = pickle.load(f)
15
+
16
+ # Streamlit App UI
17
+ st.set_page_config(page_title="🔖 Stack Overflow Tags Predictor", layout="centered")
18
+
19
+ st.title("🔖 Stack Overflow Tags Predictor")
20
+ st.write("Enter the question's title and description to get suggested tags.")
21
+
22
+ # Input fields
23
+ title = st.text_input("Enter Question Title:")
24
+ description = st.text_area("Enter Question Description:")
25
+
26
+ # Prediction logic
27
+ if st.button("Predict Tags"):
28
+ if not title.strip() or not description.strip():
29
+ st.warning("⚠️ Please enter both title and description.")
30
+ else:
31
+ try:
32
+ input_text = title + " " + description
33
+ input_vector = vectorizer.transform([input_text])
34
+ prediction = model.predict(input_vector)
35
+ predicted_tags = mlb.inverse_transform(prediction)
36
+
37
+ if predicted_tags and predicted_tags[0]:
38
+ st.success("✅ Predicted Tags: " + ", ".join(predicted_tags[0]))
39
+ else:
40
+ st.info("ℹ️ No tags predicted. Try refining your question.")
41
+ except Exception as e:
42
+ st.error(f"❌ Error: {str(e)}")