omarhkh commited on
Commit
cef6856
1 Parent(s): a7825fb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py CHANGED
@@ -68,12 +68,36 @@ def detect_objects(model_name,url_input,image_input,threshold):
68
 
69
  #Make prediction
70
  processed_outputs = make_prediction(image, feature_extractor, model)
 
71
 
72
  #Visualize prediction
73
  viz_img = visualize_prediction(image, processed_outputs, threshold, model.config.id2label)
74
 
75
  return viz_img
 
 
 
 
 
 
 
76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
  def set_example_image(example: list) -> dict:
78
  return gr.Image.update(value=example[0])
79
 
@@ -105,6 +129,8 @@ demo = gr.Blocks(css=css)
105
  with demo:
106
  gr.Markdown(title)
107
  gr.Markdown(description)
 
 
108
 
109
  options = gr.Dropdown(choices=models,label='Select Object Detection Model',show_label=True)
110
  slider_input = gr.Slider(minimum=0.1,maximum=1,value=0.7,label='Prediction Threshold')
@@ -121,6 +147,13 @@ with demo:
121
  example_images = gr.Dataset(components=[img_input], samples=[[path.as_posix()] for path in sorted(pathlib.Path('images').rglob('*.jpg'))])
122
 
123
  img_but = gr.Button('Detect')
 
 
 
 
 
 
 
124
 
125
 
126
 
 
68
 
69
  #Make prediction
70
  processed_outputs = make_prediction(image, feature_extractor, model)
71
+ print(processed_outputs)
72
 
73
  #Visualize prediction
74
  viz_img = visualize_prediction(image, processed_outputs, threshold, model.config.id2label)
75
 
76
  return viz_img
77
+
78
+ def detect_objects2(model_name,url_input,image_input,threshold):
79
+
80
+ #Extract model and feature extractor
81
+ feature_extractor = AutoFeatureExtractor.from_pretrained(model_name)
82
+
83
+
84
 
85
+ model = DetrForObjectDetection.from_pretrained(model_name)
86
+
87
+
88
+
89
+
90
+ image = image_input
91
+
92
+ #Make prediction
93
+ processed_outputs = make_prediction(image, feature_extractor, model)
94
+ print(processed_outputs)
95
+
96
+ #Visualize prediction
97
+ viz_img = visualize_prediction(image, processed_outputs, threshold, model.config.id2label)
98
+
99
+ return processed_outputs
100
+
101
  def set_example_image(example: list) -> dict:
102
  return gr.Image.update(value=example[0])
103
 
 
129
  with demo:
130
  gr.Markdown(title)
131
  gr.Markdown(description)
132
+ gr.Markdown(detect_objects2)
133
+
134
 
135
  options = gr.Dropdown(choices=models,label='Select Object Detection Model',show_label=True)
136
  slider_input = gr.Slider(minimum=0.1,maximum=1,value=0.7,label='Prediction Threshold')
 
147
  example_images = gr.Dataset(components=[img_input], samples=[[path.as_posix()] for path in sorted(pathlib.Path('images').rglob('*.jpg'))])
148
 
149
  img_but = gr.Button('Detect')
150
+
151
+ with gr.Blocks() as demo:
152
+ name = gr.Textbox(label="Name")
153
+ output = gr.Textbox(label="Results")
154
+ greet_btn = gr.Button("Results")
155
+ greet_btn.click(fn=detect_objects2, inputs=[options,img_input,img_input,slider_input], outputs=output, queue=True)
156
+
157
 
158
 
159