File size: 2,276 Bytes
c741d2d
 
 
f800a22
c741d2d
 
 
 
 
 
f800a22
 
c741d2d
 
6c6051e
c741d2d
 
 
6c6051e
c741d2d
 
 
 
6c6051e
 
 
 
 
 
 
 
 
 
 
 
c741d2d
 
8ca97f6
 
6c6051e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79ecbbc
 
 
 
 
 
6c6051e
 
c741d2d
 
 
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
import gradio as gr
import pickle

#for loading models
with open('singlish_comment_classifier_v3.pkl', "rb") as f:
    model_singlish = pickle.load(f)

with open('sinhala_comment_classifier_v1.pkl', "rb") as f:
    model_sinhala = pickle.load(f)



def predict_sinhala(text):
    prediction = model_sinhala.predict([text])
    return "No Harmful" if prediction[0] == 1 else "Harmful"

def predict_singlish(text):
    prediction = model_singlish.predict([text])
    return "No Harmful" if prediction[0] == 1 else "Harmful"

interface = gr.Interface(
    fn=lambda text, model_choice: predict_singlish(text) if model_choice == "Singlish" else predict_sinhala(text),
    inputs=[
        gr.Textbox(
            label="Enter Text", 
            placeholder="Type a comment to analyze here...", 
            lines=3, 
            elem_id="input_text"  
        ),
        gr.Radio(
            choices=["Singlish", "Sinhala"], 
            label="Choose Language", 
            info="Select which language model to use for the analysis.", 
            elem_id="radio_choice"
        ),
    ],
    outputs="text",
    title="Sinhala and Singlish Harmful Comment Detection for Anonymous Feedback",
    description="Use these 2 models to detect harmful content in anonymous messages shared through feedback links about someone. Designed for Sinhala and Singlish (one model for each lang), the models help identify offensive or hurtful comments about individuals",
    theme="huggingface",  
    css="""
        .gradio-container { 
            background-color: #f4f4f9; 
            padding: 20px; 
            border-radius: 8px;
            box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.1);
        }
        .gradio-input { 
            border: 1px solid #ddd; 
            padding: 10px; 
            border-radius: 6px;
        }
        .gradio-button { 
            background-color: #4CAF50; 
            color: white; 
            font-weight: bold; 
            border-radius: 6px; 
            padding: 12px 24px;
        }
        .gradio-button:hover {
            background-color: #45a049;
        }
        h1 {
            color: #333;
        }
        .prose p {
            color: #555; 
        }
    """, 
    allow_flagging="never" 
)

interface.launch(share=True)