File size: 1,918 Bytes
776ad2c
ef5b05b
d85ad82
776ad2c
d85ad82
 
 
776ad2c
ef5b05b
776ad2c
 
ef5b05b
776ad2c
ef5b05b
 
 
f22493f
776ad2c
d85ad82
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d9df046
d85ad82
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5b9a405
d85ad82
 
 
 
5b9a405
d85ad82
5b9a405
d85ad82
 
776ad2c
 
 
f22493f
ef5b05b
d9df046
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import gradio as gr
import pickle
import base64

# ===============================
# LOAD MODEL & VECTORIZER
# ===============================
with open("dt_disaster_text_data_project_best.pkl", "rb") as f:
    model = pickle.load(f)

with open("tfidf_vectorizer_disaster.pkl", "rb") as f:
    vectorizer = pickle.load(f)

def predict_text(text):
    vec = vectorizer.transform([text])
    pred = model.predict(vec)[0]
    return f"Predicted Category: {pred}"

# ===============================
# LOAD BACKGROUND IMAGE (HF SAFE)
# ===============================
def load_bg_image(path):
    with open(path, "rb") as img:
        return base64.b64encode(img.read()).decode()

bg_image = load_bg_image(
    "stock-vector-a-homeless-man-holding-a-need-help-sign-sitting-down-2522562231.jpg"
)

# ===============================
# CUSTOM CSS (WORKING)
# ===============================
custom_css = f"""
html, body {{
    height: 100%;
    margin: 0;
    overflow: hidden;
}}

body {{
    background-image: url("data:image/jpg;base64,{bg_image}");
    background-repeat: no-repeat;
    background-position: center;
    background-size: cover;
    background-color: #000;
}}

.gradio-container {{
    background: rgba(255, 255, 255, 0.94);
    max-width: 460px;
    margin: auto;
    margin-top: 90px;
    padding: 30px;
    border-radius: 18px;
    box-shadow: 0 12px 35px rgba(0,0,0,0.4);
}}

footer {{
    display: none !important;
}}
"""

# ===============================
# GRADIO UI
# ===============================
with gr.Blocks(css=custom_css) as demo:

    gr.Markdown("""
    ## 🚨 Disaster Text Classification  
    **Decision Tree + TF-IDF Model**
    """)

    inp = gr.Textbox(
        label="Input Text",
        placeholder="Enter disaster-related message..."
    )

    out = gr.Textbox(label="Prediction")

    btn = gr.Button("🔍 Predict")
    btn.click(predict_text, inp, out)

demo.launch()