ikuinen99 commited on
Commit
ec16106
1 Parent(s): 1101c88
app.py CHANGED
@@ -1,11 +1,13 @@
1
  import argparse
2
  import os
3
  import random
 
4
  # import sys
5
  # import os
6
  #
7
  # BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
8
  # sys.path.append(BASE_DIR)
 
9
 
10
  import numpy as np
11
  import torch
@@ -29,7 +31,6 @@ from imagebind.models.image_bind import ModalityType
29
  from tagging_model import TaggingModule
30
 
31
 
32
-
33
  def parse_args():
34
  parser = argparse.ArgumentParser(description="Qualitative")
35
  parser.add_argument("--cfg-path", help="path to configuration file.", default='./eval_configs/mmgpt4_eval.yaml')
@@ -105,11 +106,11 @@ def gradio_reset(chat_state, emb_list):
105
  if emb_list is not None:
106
  emb_list = []
107
  return None, gr.update(value=None, interactive=True), gr.update(value=None, interactive=False), \
108
- gr.update(value=None, interactive=True), \
109
- gr.update(placeholder='Please upload your image/audio first', interactive=False), \
110
- gr.update(value=None), \
111
- gr.update(value="Upload & Start Chat", interactive=True), \
112
- chat_state, emb_list, gr.update(value={})
113
 
114
 
115
  def upload_x(gr_img, gr_aud, chat_state):
@@ -128,15 +129,15 @@ def upload_x(gr_img, gr_aud, chat_state):
128
  if gr_aud is not None:
129
  chat.upload_aud(gr_aud, chat_state, emb_list)
130
  return gr.update(interactive=False), gr.update(interactive=False), \
131
- gr.update(interactive=True, placeholder='Type and press Enter'), \
132
- gr.update(value="Start Chatting", interactive=False), \
133
- chat_state, emb_list, state
134
 
135
 
136
  def gradio_ask(user_message, chatbot, chat_state, text_output, last_answer):
137
  if len(user_message) == 0:
138
  return gr.update(interactive=True, placeholder='Input should not be empty!'), chatbot, chat_state, \
139
- gr.update(value=None, color_map=None, show_legend=False), gr.update(value=None)
140
  if last_answer is not None:
141
  chatbot[-1][1] = last_answer
142
  chat.ask(user_message, chat_state)
@@ -188,6 +189,7 @@ def gradio_answer(image, chatbot, chat_state, emb_list, num_beams, temperature,
188
  entity_state, \
189
  gr.update(value=None), gr.update(value=None)
190
 
 
191
  def grounding_fn(image, chatbot, entity_state):
192
  # print("Grounding fn: ", entity_state)
193
  if image and entity_state:
 
1
  import argparse
2
  import os
3
  import random
4
+
5
  # import sys
6
  # import os
7
  #
8
  # BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
9
  # sys.path.append(BASE_DIR)
10
+ os.system("CUDA_HOME=/usr/local/cuda python -m pip install -e git+https://github.com/IDEA-Research/GroundingDINO.git")
11
 
12
  import numpy as np
13
  import torch
 
31
  from tagging_model import TaggingModule
32
 
33
 
 
34
  def parse_args():
35
  parser = argparse.ArgumentParser(description="Qualitative")
36
  parser.add_argument("--cfg-path", help="path to configuration file.", default='./eval_configs/mmgpt4_eval.yaml')
 
106
  if emb_list is not None:
107
  emb_list = []
108
  return None, gr.update(value=None, interactive=True), gr.update(value=None, interactive=False), \
109
+ gr.update(value=None, interactive=True), \
110
+ gr.update(placeholder='Please upload your image/audio first', interactive=False), \
111
+ gr.update(value=None), \
112
+ gr.update(value="Upload & Start Chat", interactive=True), \
113
+ chat_state, emb_list, gr.update(value={})
114
 
115
 
116
  def upload_x(gr_img, gr_aud, chat_state):
 
129
  if gr_aud is not None:
130
  chat.upload_aud(gr_aud, chat_state, emb_list)
131
  return gr.update(interactive=False), gr.update(interactive=False), \
132
+ gr.update(interactive=True, placeholder='Type and press Enter'), \
133
+ gr.update(value="Start Chatting", interactive=False), \
134
+ chat_state, emb_list, state
135
 
136
 
137
  def gradio_ask(user_message, chatbot, chat_state, text_output, last_answer):
138
  if len(user_message) == 0:
139
  return gr.update(interactive=True, placeholder='Input should not be empty!'), chatbot, chat_state, \
140
+ gr.update(value=None, color_map=None, show_legend=False), gr.update(value=None)
141
  if last_answer is not None:
142
  chatbot[-1][1] = last_answer
143
  chat.ask(user_message, chat_state)
 
189
  entity_state, \
190
  gr.update(value=None), gr.update(value=None)
191
 
192
+
193
  def grounding_fn(image, chatbot, entity_state):
194
  # print("Grounding fn: ", entity_state)
195
  if image and entity_state:
grounding_model.py CHANGED
@@ -64,7 +64,7 @@ class GroundingModule(nn.Module):
64
  print('==> Box grounding with "{}"...'.format(prompt))
65
  with torch.cuda.amp.autocast(enabled=True):
66
  boxes, logits, phrases = predict(self.grounding_model,
67
- image_tensor, prompt, box_threshold, text_threshold, device='cpu')
68
  print(phrases)
69
  # from PIL import Image, ImageDraw, ImageFont
70
  H, W = original_image.size[1], original_image.size[0]
 
64
  print('==> Box grounding with "{}"...'.format(prompt))
65
  with torch.cuda.amp.autocast(enabled=True):
66
  boxes, logits, phrases = predict(self.grounding_model,
67
+ image_tensor, prompt, box_threshold, text_threshold, device=self.device)
68
  print(phrases)
69
  # from PIL import Image, ImageDraw, ImageFont
70
  H, W = original_image.size[1], original_image.size[0]
groundingdino/models/GroundingDINO/ms_deform_attn.py CHANGED
@@ -26,11 +26,11 @@ from torch.autograd.function import once_differentiable
26
  from torch.nn.init import constant_, xavier_uniform_
27
 
28
  try:
29
- # from groundingdino import _C
30
- from mmcv.utils import ext_loader
31
-
32
- _C = ext_loader.load_ext(
33
- '_ext', ['ms_deform_attn_backward', 'ms_deform_attn_forward'])
34
  except:
35
  print("Failed to load custom C++ ops. Running on CPU mode Only!")
36
 
 
26
  from torch.nn.init import constant_, xavier_uniform_
27
 
28
  try:
29
+ from groundingdino import _C
30
+ # from mmcv.utils import ext_loader
31
+ #
32
+ # _C = ext_loader.load_ext(
33
+ # '_ext', ['ms_deform_attn_backward', 'ms_deform_attn_forward'])
34
  except:
35
  print("Failed to load custom C++ ops. Running on CPU mode Only!")
36