Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,14 +3,12 @@ import joblib
|
|
| 3 |
import requests
|
| 4 |
import os
|
| 5 |
from lime.lime_text import LimeTextExplainer
|
| 6 |
-
from fastapi import FastAPI
|
| 7 |
-
from gradio.routes import mount_gradio_app
|
| 8 |
|
| 9 |
# Constants
|
| 10 |
CLASSES = ["Non-Hate Speech", "Hate Speech"]
|
| 11 |
STOPWORDS = {
|
| 12 |
"แแ", "แแ แ", "แแ", "แ แแ", "แ แแแแแ", "แแก", "แแก", "แ แ", "แแแก", "แแแกแ",
|
| 13 |
-
"แจแแแ", "แฉแแแ", "แ แแ", "แ แแขแแ"
|
| 14 |
"แ แแแช", "แแ", "แแแ", "แฎแแ ", "แแแ ", "แ แแแแ แช", "แ แแช", "แ แแแแกแแช",
|
| 15 |
"แกแแแแช", "แแฃ", "แ แ", "แ แแแแแ", "แ แแแแแช", "แ แแแแก", "แ แแฆแ", "แแแแ แแ",
|
| 16 |
"แแ ", "แแฅ", "แแฅ", "แจแแแแแ", "แกแแ", "แแ", "แจแแ", "แแฅแแแ", "แแแแ ",
|
|
@@ -58,19 +56,16 @@ def api_predict(text):
|
|
| 58 |
words = get_hate_words(text)
|
| 59 |
return {"hate_words": words}
|
| 60 |
|
| 61 |
-
|
| 62 |
-
with gr.Blocks() as gradio_ui:
|
| 63 |
input_text = gr.Textbox(label="Enter Georgian text")
|
| 64 |
output_json = gr.JSON(label="Detected Hate Words")
|
| 65 |
submit_btn = gr.Button("Predict")
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
#
|
| 72 |
-
|
| 73 |
|
| 74 |
-
|
| 75 |
-
api_interface = gr.Interface(fn=api_predict, inputs=gr.Textbox(), outputs="json")
|
| 76 |
-
app = mount_gradio_app(app, api_interface, path="/predict")
|
|
|
|
| 3 |
import requests
|
| 4 |
import os
|
| 5 |
from lime.lime_text import LimeTextExplainer
|
|
|
|
|
|
|
| 6 |
|
| 7 |
# Constants
|
| 8 |
CLASSES = ["Non-Hate Speech", "Hate Speech"]
|
| 9 |
STOPWORDS = {
|
| 10 |
"แแ", "แแ แ", "แแ", "แ แแ", "แ แแแแแ", "แแก", "แแก", "แ แ", "แแแก", "แแแกแ",
|
| 11 |
+
"แจแแแ", "แฉแแแ", "แ แแ", "แ แแขแแ" "แแแ แ", "แแ", "แแฃ", "แแแแก", "แแแแก",
|
| 12 |
"แ แแแช", "แแ", "แแแ", "แฎแแ ", "แแแ ", "แ แแแแ แช", "แ แแช", "แ แแแแกแแช",
|
| 13 |
"แกแแแแช", "แแฃ", "แ แ", "แ แแแแแ", "แ แแแแแช", "แ แแแแก", "แ แแฆแ", "แแแแ แแ",
|
| 14 |
"แแ ", "แแฅ", "แแฅ", "แจแแแแแ", "แกแแ", "แแ", "แจแแ", "แแฅแแแ", "แแแแ ",
|
|
|
|
| 56 |
words = get_hate_words(text)
|
| 57 |
return {"hate_words": words}
|
| 58 |
|
| 59 |
+
with gr.Blocks() as demo:
|
|
|
|
| 60 |
input_text = gr.Textbox(label="Enter Georgian text")
|
| 61 |
output_json = gr.JSON(label="Detected Hate Words")
|
| 62 |
submit_btn = gr.Button("Predict")
|
| 63 |
+
|
| 64 |
+
submit_btn.click(
|
| 65 |
+
fn=api_predict,
|
| 66 |
+
inputs=input_text,
|
| 67 |
+
outputs=output_json,
|
| 68 |
+
api_name="predict" # This is the key addition
|
| 69 |
+
)
|
| 70 |
|
| 71 |
+
demo.launch()
|
|
|
|
|
|