Ramyamaheswari commited on
Commit
7d2301f
·
verified ·
1 Parent(s): 6f3a035

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -0
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pickle
3
+
4
+ # Custom tokenizer (same one used during training)
5
+ def custom_tokenizer(text):
6
+ return text.lower().split()
7
+
8
+ # Load artifacts
9
+ with open("model.pkl", "rb") as f:
10
+ model = pickle.load(f)
11
+
12
+ with open("tfidf_vectorizer.pkl", "rb") as f:
13
+ vectorizer = pickle.load(f)
14
+
15
+ with open("mlb.pkl", "rb") as f:
16
+ mlb = pickle.load(f)
17
+
18
+ # Prediction function
19
+ def predict_tags(title, description):
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
+ # Gradio Interface
34
+ iface = gr.Interface(
35
+ fn=predict_tags,
36
+ inputs=[
37
+ gr.Textbox(label="Enter Question Title"),
38
+ gr.Textbox(label="Enter Question Description", lines=4)
39
+ ],
40
+ outputs="text",
41
+ title="🔖 Stack Overflow Tags Predictor",
42
+ description="Enter a question's title and description to get tag suggestions.",
43
+ theme="default"
44
+ )
45
+
46
+ iface.launch()