Spaces:
Build error
Build error
Download app.py from VitouPro/animal_classification: direct link, hf CLI and curl.
- Browser
- Download file 976 Bytes
-
https://huggingface.co/spaces/VitouPro/animal_classification/resolve/main/app.py
- Command line
-
hf download hf://spaces/VitouPro/animal_classification/app.py
-
curl -L -o app.py https://huggingface.co/spaces/VitouPro/animal_classification/resolve/main/app.py
976 Bytes
| import gradio as gr | |
| from clients import send_request | |
| import json | |
| import ast | |
| import cv2 | |
| import numpy as np | |
| def save_non_abuse_class(top_classes): | |
| top_class_json = json.loads(json.dumps(top_classes['message'])) | |
| top_class_json = ast.literal_eval(top_class_json) | |
| return dict(list(top_class_json.items())[:3]) | |
| def prediction(img): | |
| top_classes = send_request(img_input=img, url='http://54.169.176.200/') | |
| print(top_classes) | |
| save_class = save_non_abuse_class(top_classes) | |
| prediction_str = "\n".join([f"{index+1}. {property} : {round(value*100,2)}%" for index, (property, value) in enumerate(save_class.items())]) | |
| return prediction_str | |
| with gr.Blocks(css="footer{display:none !important}") as demo: | |
| with gr.Row(): | |
| prediction_output = gr.Textbox(placeholder="result", label="Prediction") | |
| gr.Interface(prediction, inputs="image", outputs=prediction_output) | |
| if __name__ == "__main__": | |
| demo.launch() |