Team Ai
Apppublic

sriramelango/CV_Social_Classification

sourceHugging Faceupdated 4y agoView on Hugging Face
1likes
app.py41 linesDownload Raw Back to root
1import gradio as gr2import os3import torch4from PIL import Image5 6                           7#subprocess.run(["mv","content/custom_data.yaml","./yolov5/data"])         8 9 10def load_model():11 '''12 Loading hub model & setting the preferences for the model  13 '''14 model = torch.hub.load('ultralytics/yolov5', 'custom', path='Content/cnn.pt')15 model.conf = 0.38 16 model.dnn=True17 model.agnostic=True18 return model19 20model=load_model()21#, force_reload=True22def detect(inp):23 #g = (size / max(inp.size))  #gain24 #im = im.resize((int(x * g) for x in im.size), Image.ANTIALIAS)  # resize 25 results = model(inp,size=640)  # inference26 print(results)27 results.render()  # updates results.imgs with boxes and labels28 return Image.fromarray(results.imgs[0])29 30 31inp = gr.inputs.Image(type="pil", label="Original Image")32output = gr.outputs.Image(type="pil", label="Output Image")33 34 35io=gr.Interface(fn=detect, inputs=inp, outputs=output, title='CV Social Classification',theme='peach')36io.launch(debug=True,share=False)37  38#examples=['Content/4.jpg','Content/10.jpg','Content/18.jpg']39 40                                             41