Spaces:
Build error
Build error
SoyVitou2019 commited on
Commit ·
dddba66
1
Parent(s): 1b9abc3
7 pushing
Browse files- __pycache__/app.cpython-311.pyc +0 -0
- app.py +20 -26
__pycache__/app.cpython-311.pyc
ADDED
|
Binary file (3.18 kB). View file
|
|
|
app.py
CHANGED
|
@@ -1,32 +1,27 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
import ast
|
| 5 |
def save_non_abuse_class(top_classes):
|
| 6 |
-
top_class_json = json.loads(json.dumps(top_classes['message']))
|
| 7 |
-
top_class_json = ast.literal_eval(top_class_json)
|
| 8 |
dic_predict = {
|
| 9 |
"Non Abuse Image": 0,
|
| 10 |
"Abuse Image": 0
|
| 11 |
}
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
for k, v in top_class_json.items():
|
| 16 |
-
if k
|
| 17 |
dic_predict["Non Abuse Image"] += v
|
| 18 |
else:
|
| 19 |
dic_predict["Abuse Image"] += v
|
|
|
|
| 20 |
dic_predict = sorted(dic_predict.items(), key=lambda x: x[1], reverse=True)
|
| 21 |
dic_predict = {k: v for k, v in dic_predict}
|
| 22 |
return dic_predict
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
def prediction(img):
|
| 28 |
-
|
| 29 |
-
|
| 30 |
save_class = save_non_abuse_class(top_classes)
|
| 31 |
prediction_str = "\n".join([f"{index+1}. {property} : {round(value*100,2)}%" for index, (property, value) in enumerate(save_class.items())])
|
| 32 |
return prediction_str
|
|
@@ -34,17 +29,16 @@ def prediction(img):
|
|
| 34 |
def clear_output():
|
| 35 |
image_input.value = None
|
| 36 |
prediction_output.value = None
|
| 37 |
-
return None, None
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
image_input = gr.inputs.Image()
|
| 42 |
-
prediction_output = gr.Textbox(placeholder="result", label="Prediction")
|
| 43 |
-
image_button = gr.Button("Make prediction")
|
| 44 |
-
clear_button = gr.Button("Clear")
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
| 48 |
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
|
|
|
|
| 4 |
def save_non_abuse_class(top_classes):
|
|
|
|
|
|
|
| 5 |
dic_predict = {
|
| 6 |
"Non Abuse Image": 0,
|
| 7 |
"Abuse Image": 0
|
| 8 |
}
|
| 9 |
+
|
| 10 |
+
top_class_json = top_classes['message']
|
| 11 |
+
|
| 12 |
for k, v in top_class_json.items():
|
| 13 |
+
if k.startswith(("Nice emoji", "Non Abuse")):
|
| 14 |
dic_predict["Non Abuse Image"] += v
|
| 15 |
else:
|
| 16 |
dic_predict["Abuse Image"] += v
|
| 17 |
+
|
| 18 |
dic_predict = sorted(dic_predict.items(), key=lambda x: x[1], reverse=True)
|
| 19 |
dic_predict = {k: v for k, v in dic_predict}
|
| 20 |
return dic_predict
|
| 21 |
+
|
|
|
|
|
|
|
|
|
|
| 22 |
def prediction(img):
|
| 23 |
+
response = requests.post('http://18.139.116.122/', files={'img_input': img})
|
| 24 |
+
top_classes = response.json()
|
| 25 |
save_class = save_non_abuse_class(top_classes)
|
| 26 |
prediction_str = "\n".join([f"{index+1}. {property} : {round(value*100,2)}%" for index, (property, value) in enumerate(save_class.items())])
|
| 27 |
return prediction_str
|
|
|
|
| 29 |
def clear_output():
|
| 30 |
image_input.value = None
|
| 31 |
prediction_output.value = None
|
|
|
|
| 32 |
|
| 33 |
+
image_input = gr.inputs.Image()
|
| 34 |
+
prediction_output = gr.outputs.Textbox()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
+
image_button = gr.Button("Make prediction")
|
| 37 |
+
clear_button = gr.Button("Clear")
|
| 38 |
|
| 39 |
+
iface = gr.Interface(inputs=image_input, outputs=prediction_output,
|
| 40 |
+
title="Abuse Image Classifier",
|
| 41 |
+
description="Classify an image as abuse or non-abuse.",
|
| 42 |
+
theme="default")
|
| 43 |
+
|
| 44 |
+
iface.launch()
|