Create the app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pickle
|
| 3 |
+
|
| 4 |
+
with open('singlish_comment_classifier_v3.pkl', "rb") as f:
|
| 5 |
+
model_singlish = pickle.load(f)
|
| 6 |
+
|
| 7 |
+
with open('sinhala_comment_classifier_v1.pkl', "rb") as f:
|
| 8 |
+
model_sinhala = pickle.load(f)
|
| 9 |
+
|
| 10 |
+
def predict_sinhala(text):
|
| 11 |
+
prediction = model_sinhala.predict([text])
|
| 12 |
+
return "POSITIVE" if prediction[0] == 1 else "NEGATIVE"
|
| 13 |
+
|
| 14 |
+
def predict_singlish(text):
|
| 15 |
+
prediction = model_singlish.predict([text])
|
| 16 |
+
return "POSITIVE" if prediction[0] == 1 else "NEGATIVE"
|
| 17 |
+
|
| 18 |
+
interface = gr.Interface(
|
| 19 |
+
fn=lambda text, model_choice: predict_singlish(text) if model_choice == "Singlish" else predict_sinhala(text),
|
| 20 |
+
inputs=[
|
| 21 |
+
gr.Textbox(label="Enter Text"),
|
| 22 |
+
gr.Radio(["Singlish", "Sinhala"], label="Choose Model")
|
| 23 |
+
],
|
| 24 |
+
outputs="text",
|
| 25 |
+
title="Sinhala and Singlish harm comment detector",
|
| 26 |
+
description="Choose a model and enter text to get predictions."
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
interface.launch(share=True)
|