StarAtNyte1 commited on
Commit
fb9bd11
1 Parent(s): 91c3034

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -47
app.py CHANGED
@@ -1,47 +0,0 @@
1
- import json
2
- import gradio as gr
3
- import yolov5
4
- from PIL import Image
5
- from huggingface_hub import hf_hub_download
6
-
7
- app_title = "Object Detection"
8
- models_ids = ['StarAtNyte1/yolov7_custom']
9
-
10
- current_model_id = models_ids[-1]
11
- model = yolov5.load(current_model_id)
12
-
13
-
14
-
15
- def predict(image, threshold=0.25, model_id=None):
16
- # update model if required
17
- global current_model_id
18
- global model
19
- if model_id != current_model_id:
20
- model = yolov5.load(model_id)
21
- current_model_id = model_id
22
-
23
- # get model input size
24
- config_path = hf_hub_download(repo_id=model_id, filename="config.json")
25
- with open(config_path, "r") as f:
26
- config = json.load(f)
27
- input_size = config["input_size"]
28
-
29
- # perform inference
30
- model.conf = threshold
31
- results = model(image, size=input_size)
32
- numpy_image = results.render()[0]
33
- output_image = Image.fromarray(numpy_image)
34
- return output_image
35
-
36
-
37
- gr.Interface(
38
- title=app_title,
39
- description="Created by ",
40
- fn=predict,
41
- inputs=[
42
- gr.Image(type="pil"),
43
- gr.Dropdown(models_ids, value=models_ids[-1]),
44
- ],
45
- outputs=gr.Image(type="pil"),
46
- cache_examples=True if examples else False,
47
- ).launch(enable_queue=True)