sree4411 commited on
Commit
76f694f
·
verified ·
1 Parent(s): 37e072f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py CHANGED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()