taesiri commited on
Commit
85d4eb3
1 Parent(s): 99abd69
Files changed (2) hide show
  1. README.md +2 -2
  2. app.py +28 -16
README.md CHANGED
@@ -1,7 +1,7 @@
1
  ---
2
- title: Detic
3
  emoji: 👀
4
- colorFrom: indigo
5
  colorTo: red
6
  sdk: gradio
7
  app_file: app.py
 
1
  ---
2
+ title: Detic+ChatGPT
3
  emoji: 👀
4
+ colorFrom: blue
5
  colorTo: red
6
  sdk: gradio
7
  app_file: app.py
app.py CHANGED
@@ -77,12 +77,6 @@ BUILDIN_METADATA_PATH = {
77
  "coco": "coco_2017_val",
78
  }
79
 
80
- vocabulary = "lvis" # change to 'lvis', 'objects365', 'openimages', or 'coco'
81
- metadata = MetadataCatalog.get(BUILDIN_METADATA_PATH[vocabulary])
82
- classifier = BUILDIN_CLASSIFIER[vocabulary]
83
- num_classes = len(metadata.thing_classes)
84
- reset_cls_test(predictor.model, classifier, num_classes)
85
-
86
  session_token = os.environ.get("SessionToken")
87
 
88
 
@@ -98,7 +92,11 @@ def get_response_from_chatbot(text):
98
  return response
99
 
100
 
101
- def inference(img):
 
 
 
 
102
 
103
  im = cv2.imread(img)
104
 
@@ -140,21 +138,35 @@ def inference(img):
140
  )
141
 
142
 
 
143
  with gr.Blocks() as demo:
144
  gr.Markdown("# Detic+ChatGPT")
145
- gr.Markdown("Use Detic to detect objects in an image and then use ChatGPT to describe the image.")
146
-
147
- gr.HTML("<p>You can duplicating this space and use your own session token: <a style='display:inline-block' href='https://huggingface.co/spaces/yizhangliu/chatGPT?duplicate=true'><img src='https://img.shields.io/badge/-Duplicate%20Space-blue?labelColor=white&style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAP5JREFUOE+lk7FqAkEURY+ltunEgFXS2sZGIbXfEPdLlnxJyDdYB62sbbUKpLbVNhyYFzbrrA74YJlh9r079973psed0cvUD4A+4HoCjsA85X0Dfn/RBLBgBDxnQPfAEJgBY+A9gALA4tcbamSzS4xq4FOQAJgCDwV2CPKV8tZAJcAjMMkUe1vX+U+SMhfAJEHasQIWmXNN3abzDwHUrgcRGmYcgKe0bxrblHEB4E/pndMazNpSZGcsZdBlYJcEL9Afo75molJyM2FxmPgmgPqlWNLGfwZGG6UiyEvLzHYDmoPkDDiNm9JR9uboiONcBXrpY1qmgs21x1QwyZcpvxt9NS09PlsPAAAAAElFTkSuQmCC&logoWidth=14' alt='Duplicate Space'></a></p>")
148
- gr.HTML("<p> Instruction on how to get session token can be seen in video <a style='display:inline-block' href='https://www.youtube.com/watch?v=TdNSj_qgdFk'><font style='color:blue;weight:bold;'>here</font></a>. Add your session token by going to settings and add under secrets. </p>")
149
-
 
 
 
 
 
 
150
  with gr.Column():
151
- inp = gr.Image(label="Input Image", type="filepath")
 
 
 
 
 
 
 
152
  btn_detic = gr.Button("Run Detic+ChatGPT")
153
- with gr.Column():
154
  outviz = gr.Image(label="Visualization", type="pil")
155
- output_desc = gr.Textbox(label="chatGPT Description", lines=5)
156
  # outputjson = gr.JSON(label="Detected Objects")
157
 
158
- btn_detic.click(fn=inference, inputs=inp, outputs=[outviz, output_desc])
159
 
160
  demo.launch()
 
77
  "coco": "coco_2017_val",
78
  }
79
 
 
 
 
 
 
 
80
  session_token = os.environ.get("SessionToken")
81
 
82
 
 
92
  return response
93
 
94
 
95
+ def inference(img, vocabulary):
96
+ metadata = MetadataCatalog.get(BUILDIN_METADATA_PATH[vocabulary])
97
+ classifier = BUILDIN_CLASSIFIER[vocabulary]
98
+ num_classes = len(metadata.thing_classes)
99
+ reset_cls_test(predictor.model, classifier, num_classes)
100
 
101
  im = cv2.imread(img)
102
 
 
138
  )
139
 
140
 
141
+ # create a gradio block for image classification
142
  with gr.Blocks() as demo:
143
  gr.Markdown("# Detic+ChatGPT")
144
+ gr.Markdown(
145
+ "Use Detic to detect objects in an image and then use ChatGPT to describe the image."
146
+ )
147
+
148
+ gr.HTML(
149
+ "<p>You can duplicating this space and use your own session token: <a style='display:inline-block' href='https://huggingface.co/spaces/yizhangliu/chatGPT?duplicate=true'><img src='https://img.shields.io/badge/-Duplicate%20Space-blue?labelColor=white&style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAP5JREFUOE+lk7FqAkEURY+ltunEgFXS2sZGIbXfEPdLlnxJyDdYB62sbbUKpLbVNhyYFzbrrA74YJlh9r079973psed0cvUD4A+4HoCjsA85X0Dfn/RBLBgBDxnQPfAEJgBY+A9gALA4tcbamSzS4xq4FOQAJgCDwV2CPKV8tZAJcAjMMkUe1vX+U+SMhfAJEHasQIWmXNN3abzDwHUrgcRGmYcgKe0bxrblHEB4E/pndMazNpSZGcsZdBlYJcEL9Afo75molJyM2FxmPgmgPqlWNLGfwZGG6UiyEvLzHYDmoPkDDiNm9JR9uboiONcBXrpY1qmgs21x1QwyZcpvxt9NS09PlsPAAAAAElFTkSuQmCC&logoWidth=14' alt='Duplicate Space'></a></p>"
150
+ )
151
+ gr.HTML(
152
+ "<p> Instruction on how to get session token can be seen in video <a style='display:inline-block' href='https://www.youtube.com/watch?v=TdNSj_qgdFk'><font style='color:blue;weight:bold;'>here</font></a>. Add your session token by going to settings and add under secrets. </p>"
153
+ )
154
+
155
  with gr.Column():
156
+ with gr.Row():
157
+ inp = gr.Image(label="Input Image", type="filepath")
158
+ vocab = gr.Dropdown(
159
+ ["lvis", "objects365", "openimages", "coco"],
160
+ label="Vocabulary",
161
+ value="lvis",
162
+ )
163
+
164
  btn_detic = gr.Button("Run Detic+ChatGPT")
165
+ with gr.Row():
166
  outviz = gr.Image(label="Visualization", type="pil")
167
+ output_desc = gr.Textbox(label="ChatGPT Description", lines=5)
168
  # outputjson = gr.JSON(label="Detected Objects")
169
 
170
+ btn_detic.click(fn=inference, inputs=[inp, vocab], outputs=[outviz, output_desc])
171
 
172
  demo.launch()