File size: 610 Bytes
000a6ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import json

import gradio as gr
import yolov5

model = yolov5.load('Cinderella.pt')


def inference(gr_input):
   with open("json/classes.json", "r")as f:
      dic = json.load(f)
   predictions = model(gr_input).pred[0]
   name = [x for x in dic.values()]
   idols = []
   for i in predictions[:, 5]:  # 検出
      idols.append(name[int(i.item())])
   if len(idols) == 0:
      return "該当するクラスが存在しません"
   else:
      text = "\n".join(idols)
      return text


inputs = gr.inputs.Image()

interface = gr.Interface(fn=inference, inputs=inputs, outputs="text")
interface.launch()