Skip to content

Commit

Permalink
[gpt4v_vqa] update eusilsp lib and add simple script
Browse files Browse the repository at this point in the history
  • Loading branch information
sktometometo committed Jan 9, 2024
1 parent ff9d5c0 commit a963fb9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
9 changes: 9 additions & 0 deletions gpt4v_vqa/euslisp/run_simple_vqa.l
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env roseus

(load "package://gpt4v_vqa/euslisp/utils.l")

(ros::roseus "run_simple_vqa")

(print "Question is \"Please describe the image briefly.\"")
(print (format nil "Answer is ~a" (run-vqa "Please describe the image briefly.")))
(exit)
33 changes: 33 additions & 0 deletions gpt4v_vqa/euslisp/utils.l
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
(ros::load-ros-manifest "jsk_recognition_msgs")

(defparameter *vqa-action* nil)

(defun init-vqa-action (&key (timeout 10))
(unless *vqa-action*
(setq *vqa-action*
(instance ros::simple-action-client :init
"/vqa/inference_server" jsk_recognition_msgs::VQATaskAction)))
(send *vqa-action* :wait-for-server timeout)
)

(defun run-vqa (question &optional msg_image &key (timeout 30))
"run vqa action client. return answer string or nil if failed."
(if (not (init-vqa-action))
(return-from run-vqa nil))
(let* (result answer
(action-goal (instance jsk_recognition_msgs::VQATaskGoal :init)))
(send action-goal :questions (list question))
(if msg_image
(send action-goal :image msg_image)
)
(send *vqa-action* :send-goal action-goal)
(unless (send *vqa-action* :wait-for-result :timeout timeout)
(send *vqa-action* :cancel-all-goals)
(ros::ros-error "No result returned from /vqa action server")
(return-from run-vqa nil))
(setq result (send *vqa-action* :get-result))
(if (and result (> (length (send result :result :result)) 0))
(send (elt (send result :result :result) 0) :answer)
nil)
)
)

0 comments on commit a963fb9

Please sign in to comment.