Update app.py
Browse files
app.py
CHANGED
|
@@ -12,21 +12,56 @@ with open('sinhala_comment_classifier_v1.pkl', "rb") as f:
|
|
| 12 |
|
| 13 |
def predict_sinhala(text):
|
| 14 |
prediction = model_sinhala.predict([text])
|
| 15 |
-
return "
|
| 16 |
|
| 17 |
def predict_singlish(text):
|
| 18 |
prediction = model_singlish.predict([text])
|
| 19 |
-
return "
|
| 20 |
|
| 21 |
interface = gr.Interface(
|
| 22 |
fn=lambda text, model_choice: predict_singlish(text) if model_choice == "Singlish" else predict_sinhala(text),
|
| 23 |
inputs=[
|
| 24 |
-
gr.Textbox(
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
],
|
| 27 |
outputs="text",
|
| 28 |
-
title="Sinhala and Singlish
|
| 29 |
-
description="
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
)
|
| 31 |
|
| 32 |
interface.launch(share=True)
|
|
|
|
| 12 |
|
| 13 |
def predict_sinhala(text):
|
| 14 |
prediction = model_sinhala.predict([text])
|
| 15 |
+
return "No Harmful" if prediction[0] == 1 else "Harmful"
|
| 16 |
|
| 17 |
def predict_singlish(text):
|
| 18 |
prediction = model_singlish.predict([text])
|
| 19 |
+
return "No Harmful" if prediction[0] == 1 else "Harmful"
|
| 20 |
|
| 21 |
interface = gr.Interface(
|
| 22 |
fn=lambda text, model_choice: predict_singlish(text) if model_choice == "Singlish" else predict_sinhala(text),
|
| 23 |
inputs=[
|
| 24 |
+
gr.Textbox(
|
| 25 |
+
label="Enter Text",
|
| 26 |
+
placeholder="Type a comment to analyze here...",
|
| 27 |
+
lines=3,
|
| 28 |
+
elem_id="input_text"
|
| 29 |
+
),
|
| 30 |
+
gr.Radio(
|
| 31 |
+
choices=["Singlish", "Sinhala"],
|
| 32 |
+
label="Choose Language",
|
| 33 |
+
info="Select which language model to use for the analysis.",
|
| 34 |
+
elem_id="radio_choice"
|
| 35 |
+
),
|
| 36 |
],
|
| 37 |
outputs="text",
|
| 38 |
+
title="Sinhala and Singlish Harmful Comment Detector",
|
| 39 |
+
description="Select the language model and input a comment to detect whether it is harmful or not.",
|
| 40 |
+
theme="huggingface",
|
| 41 |
+
css="""
|
| 42 |
+
.gradio-container {
|
| 43 |
+
background-color: #f4f4f9;
|
| 44 |
+
padding: 20px;
|
| 45 |
+
border-radius: 8px;
|
| 46 |
+
box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.1);
|
| 47 |
+
}
|
| 48 |
+
.gradio-input {
|
| 49 |
+
border: 1px solid #ddd;
|
| 50 |
+
padding: 10px;
|
| 51 |
+
border-radius: 6px;
|
| 52 |
+
}
|
| 53 |
+
.gradio-button {
|
| 54 |
+
background-color: #4CAF50;
|
| 55 |
+
color: white;
|
| 56 |
+
font-weight: bold;
|
| 57 |
+
border-radius: 6px;
|
| 58 |
+
padding: 12px 24px;
|
| 59 |
+
}
|
| 60 |
+
.gradio-button:hover {
|
| 61 |
+
background-color: #45a049;
|
| 62 |
+
}
|
| 63 |
+
""",
|
| 64 |
+
allow_flagging="never"
|
| 65 |
)
|
| 66 |
|
| 67 |
interface.launch(share=True)
|