diff --git a/README.md b/README.md index f6b21b9b..819f1fe3 100644 --- a/README.md +++ b/README.md @@ -4,39 +4,21 @@ See our paper: [Visual ChatGPT: Talking, Drawing and Editing with Visual Foundation Models](https://arxiv.org/abs/2303.04671) -## Demo - - -## System Architecture - - -

Logo

- +## Intro +I implement a google-colab version under standard GPU environment. +I just use two models `T2I` and `ImageCaption` to process images because of my insufficient GPU memory. +You can try my colab notebook here -## Quick Start - -``` -# create a new environment -conda create -n visgpt python=3.8 - -# activate the new environment -conda activate visgpt - -# prepare the basic environments -pip install -r requirement.txt +[![Open 2k image generation in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1bl-JAgrUru9GlGsb9hrcZCqj3uI6ev_O?usp=sharing) +## Demo +`T2I` -# download the visual foundation models -bash download.sh + -# prepare your private openAI private key -export OPENAI_API_KEY={Your_Private_Openai_Key} +`ImageCaption` -# create a folder to save images -mkdir ./image + -# Start Visual ChatGPT ! -python visual_chatgpt.py -``` ## GPU memory usage Here we list the GPU memory usage of each visual foundation model, one can modify ``self.tools`` with fewer visual foundation models to save your GPU memory: diff --git a/assets/dog-meme.jpg b/assets/dog-meme.jpg new file mode 100644 index 00000000..88c168c7 Binary files /dev/null and b/assets/dog-meme.jpg differ diff --git a/assets/football.jpg b/assets/football.jpg new file mode 100644 index 00000000..b654d15c Binary files /dev/null and b/assets/football.jpg differ diff --git a/download.sh b/download.sh index dffa07a9..9d6afefa 100644 --- a/download.sh +++ b/download.sh @@ -3,12 +3,12 @@ ln -s ControlNet/ldm ./ldm ln -s ControlNet/cldm ./cldm ln -s ControlNet/annotator ./annotator cd ControlNet/models -wget https://huggingface.co/lllyasviel/ControlNet/resolve/main/models/control_sd15_canny.pth -wget https://huggingface.co/lllyasviel/ControlNet/resolve/main/models/control_sd15_depth.pth -wget https://huggingface.co/lllyasviel/ControlNet/resolve/main/models/control_sd15_hed.pth -wget https://huggingface.co/lllyasviel/ControlNet/resolve/main/models/control_sd15_mlsd.pth -wget https://huggingface.co/lllyasviel/ControlNet/resolve/main/models/control_sd15_normal.pth -wget https://huggingface.co/lllyasviel/ControlNet/resolve/main/models/control_sd15_openpose.pth -wget https://huggingface.co/lllyasviel/ControlNet/resolve/main/models/control_sd15_scribble.pth -wget https://huggingface.co/lllyasviel/ControlNet/resolve/main/models/control_sd15_seg.pth +#wget https://huggingface.co/lllyasviel/ControlNet/resolve/main/models/control_sd15_canny.pth +#wget https://huggingface.co/lllyasviel/ControlNet/resolve/main/models/control_sd15_depth.pth +#wget https://huggingface.co/lllyasviel/ControlNet/resolve/main/models/control_sd15_hed.pth +#wget https://huggingface.co/lllyasviel/ControlNet/resolve/main/models/control_sd15_mlsd.pth +#wget https://huggingface.co/lllyasviel/ControlNet/resolve/main/models/control_sd15_normal.pth +#wget https://huggingface.co/lllyasviel/ControlNet/resolve/main/models/control_sd15_openpose.pth +#wget https://huggingface.co/lllyasviel/ControlNet/resolve/main/models/control_sd15_scribble.pth +#wget https://huggingface.co/lllyasviel/ControlNet/resolve/main/models/control_sd15_seg.pth cd ../../ diff --git a/requirement.txt b/requirement.txt index c1bfb107..f1736d43 100644 --- a/requirement.txt +++ b/requirement.txt @@ -3,7 +3,7 @@ torchvision==0.13.1 numpy==1.23.1 transformers==4.26.1 albumentations==1.3.0 -opencv-contrib-python==4.3.0.36 +opencv-python==4.5.1.48 imageio==2.9.0 imageio-ffmpeg==0.4.2 pytorch-lightning==1.5.0 diff --git a/visual_chatgpt.py b/visual_chatgpt.py index 836c2e1e..360721b4 100644 --- a/visual_chatgpt.py +++ b/visual_chatgpt.py @@ -801,27 +801,27 @@ class ConversationBot: def __init__(self): print("Initializing VisualChatGPT") self.llm = OpenAI(temperature=0) - self.edit = ImageEditing(device="cuda:6") - self.i2t = ImageCaptioning(device="cuda:4") - self.t2i = T2I(device="cuda:1") - self.image2canny = image2canny() - self.canny2image = canny2image(device="cuda:1") - self.image2line = image2line() - self.line2image = line2image(device="cuda:1") - self.image2hed = image2hed() - self.hed2image = hed2image(device="cuda:2") - self.image2scribble = image2scribble() - self.scribble2image = scribble2image(device="cuda:3") - self.image2pose = image2pose() - self.pose2image = pose2image(device="cuda:3") - self.BLIPVQA = BLIPVQA(device="cuda:4") - self.image2seg = image2seg() - self.seg2image = seg2image(device="cuda:7") - self.image2depth = image2depth() - self.depth2image = depth2image(device="cuda:7") - self.image2normal = image2normal() - self.normal2image = normal2image(device="cuda:5") - self.pix2pix = Pix2Pix(device="cuda:3") + # self.edit = ImageEditing(device="cuda:6") + self.i2t = ImageCaptioning(device="cuda:0") + self.t2i = T2I(device="cuda:0") + # self.image2canny = image2canny() + # self.canny2image = canny2image(device="cuda:1") + # self.image2line = image2line() + # self.line2image = line2image(device="cuda:1") + # self.image2hed = image2hed() + # self.hed2image = hed2image(device="cuda:2") + # self.image2scribble = image2scribble() + # self.scribble2image = scribble2image(device="cuda:3") + # self.image2pose = image2pose() + # self.pose2image = pose2image(device="cuda:3") + # self.BLIPVQA = BLIPVQA(device="cuda:4") + # self.image2seg = image2seg() + # self.seg2image = seg2image(device="cuda:7") + # self.image2depth = image2depth() + # self.depth2image = depth2image(device="cuda:7") + # self.image2normal = image2normal() + # self.normal2image = normal2image(device="cuda:5") + # self.pix2pix = Pix2Pix(device="cuda:3") self.memory = ConversationBufferMemory(memory_key="chat_history", output_key='output') self.tools = [ Tool(name="Get Photo Description", func=self.i2t.inference, @@ -829,68 +829,68 @@ def __init__(self): "The input to this tool should be a string, representing the image_path. "), Tool(name="Generate Image From User Input Text", func=self.t2i.inference, description="useful when you want to generate an image from a user input text and save it to a file. like: generate an image of an object or something, or generate an image that includes some objects. " - "The input to this tool should be a string, representing the text used to generate image. "), - Tool(name="Remove Something From The Photo", func=self.edit.remove_part_of_image, - description="useful when you want to remove and object or something from the photo from its description or location. " - "The input to this tool should be a comma seperated string of two, representing the image_path and the object need to be removed. "), - Tool(name="Replace Something From The Photo", func=self.edit.replace_part_of_image, - description="useful when you want to replace an object from the object description or location with another object from its description. " - "The input to this tool should be a comma seperated string of three, representing the image_path, the object to be replaced, the object to be replaced with "), - - Tool(name="Instruct Image Using Text", func=self.pix2pix.inference, - description="useful when you want to the style of the image to be like the text. like: make it look like a painting. or make it like a robot. " - "The input to this tool should be a comma seperated string of two, representing the image_path and the text. "), - Tool(name="Answer Question About The Image", func=self.BLIPVQA.get_answer_from_question_and_image, - description="useful when you need an answer for a question based on an image. like: what is the background color of the last image, how many cats in this figure, what is in this figure. " - "The input to this tool should be a comma seperated string of two, representing the image_path and the question"), - Tool(name="Edge Detection On Image", func=self.image2canny.inference, - description="useful when you want to detect the edge of the image. like: detect the edges of this image, or canny detection on image, or peform edge detection on this image, or detect the canny image of this image. " - "The input to this tool should be a string, representing the image_path"), - Tool(name="Generate Image Condition On Canny Image", func=self.canny2image.inference, - description="useful when you want to generate a new real image from both the user desciption and a canny image. like: generate a real image of a object or something from this canny image, or generate a new real image of a object or something from this edge image. " - "The input to this tool should be a comma seperated string of two, representing the image_path and the user description. "), - Tool(name="Line Detection On Image", func=self.image2line.inference, - description="useful when you want to detect the straight line of the image. like: detect the straight lines of this image, or straight line detection on image, or peform straight line detection on this image, or detect the straight line image of this image. " - "The input to this tool should be a string, representing the image_path"), - Tool(name="Generate Image Condition On Line Image", func=self.line2image.inference, - description="useful when you want to generate a new real image from both the user desciption and a straight line image. like: generate a real image of a object or something from this straight line image, or generate a new real image of a object or something from this straight lines. " - "The input to this tool should be a comma seperated string of two, representing the image_path and the user description. "), - Tool(name="Hed Detection On Image", func=self.image2hed.inference, - description="useful when you want to detect the soft hed boundary of the image. like: detect the soft hed boundary of this image, or hed boundary detection on image, or peform hed boundary detection on this image, or detect soft hed boundary image of this image. " - "The input to this tool should be a string, representing the image_path"), - Tool(name="Generate Image Condition On Soft Hed Boundary Image", func=self.hed2image.inference, - description="useful when you want to generate a new real image from both the user desciption and a soft hed boundary image. like: generate a real image of a object or something from this soft hed boundary image, or generate a new real image of a object or something from this hed boundary. " - "The input to this tool should be a comma seperated string of two, representing the image_path and the user description"), - Tool(name="Segmentation On Image", func=self.image2seg.inference, - description="useful when you want to detect segmentations of the image. like: segment this image, or generate segmentations on this image, or peform segmentation on this image. " - "The input to this tool should be a string, representing the image_path"), - Tool(name="Generate Image Condition On Segmentations", func=self.seg2image.inference, - description="useful when you want to generate a new real image from both the user desciption and segmentations. like: generate a real image of a object or something from this segmentation image, or generate a new real image of a object or something from these segmentations. " - "The input to this tool should be a comma seperated string of two, representing the image_path and the user description"), - Tool(name="Predict Depth On Image", func=self.image2depth.inference, - description="useful when you want to detect depth of the image. like: generate the depth from this image, or detect the depth map on this image, or predict the depth for this image. " - "The input to this tool should be a string, representing the image_path"), - Tool(name="Generate Image Condition On Depth", func=self.depth2image.inference, - description="useful when you want to generate a new real image from both the user desciption and depth image. like: generate a real image of a object or something from this depth image, or generate a new real image of a object or something from the depth map. " - "The input to this tool should be a comma seperated string of two, representing the image_path and the user description"), - Tool(name="Predict Normal Map On Image", func=self.image2normal.inference, - description="useful when you want to detect norm map of the image. like: generate normal map from this image, or predict normal map of this image. " - "The input to this tool should be a string, representing the image_path"), - Tool(name="Generate Image Condition On Normal Map", func=self.normal2image.inference, - description="useful when you want to generate a new real image from both the user desciption and normal map. like: generate a real image of a object or something from this normal map, or generate a new real image of a object or something from the normal map. " - "The input to this tool should be a comma seperated string of two, representing the image_path and the user description"), - Tool(name="Sketch Detection On Image", func=self.image2scribble.inference, - description="useful when you want to generate a scribble of the image. like: generate a scribble of this image, or generate a sketch from this image, detect the sketch from this image. " - "The input to this tool should be a string, representing the image_path"), - Tool(name="Generate Image Condition On Sketch Image", func=self.scribble2image.inference, - description="useful when you want to generate a new real image from both the user desciption and a scribble image or a sketch image. " - "The input to this tool should be a comma seperated string of two, representing the image_path and the user description"), - Tool(name="Pose Detection On Image", func=self.image2pose.inference, - description="useful when you want to detect the human pose of the image. like: generate human poses of this image, or generate a pose image from this image. " - "The input to this tool should be a string, representing the image_path"), - Tool(name="Generate Image Condition On Pose Image", func=self.pose2image.inference, - description="useful when you want to generate a new real image from both the user desciption and a human pose image. like: generate a real image of a human from this human pose image, or generate a new real image of a human from this pose. " - "The input to this tool should be a comma seperated string of two, representing the image_path and the user description")] + "The input to this tool should be a string, representing the text used to generate image. ")] + # Tool(name="Remove Something From The Photo", func=self.edit.remove_part_of_image, + # description="useful when you want to remove and object or something from the photo from its description or location. " + # "The input to this tool should be a comma seperated string of two, representing the image_path and the object need to be removed. "), + # Tool(name="Replace Something From The Photo", func=self.edit.replace_part_of_image, + # description="useful when you want to replace an object from the object description or location with another object from its description. " + # "The input to this tool should be a comma seperated string of three, representing the image_path, the object to be replaced, the object to be replaced with "), + # + # Tool(name="Instruct Image Using Text", func=self.pix2pix.inference, + # description="useful when you want to the style of the image to be like the text. like: make it look like a painting. or make it like a robot. " + # "The input to this tool should be a comma seperated string of two, representing the image_path and the text. "), + # Tool(name="Answer Question About The Image", func=self.BLIPVQA.get_answer_from_question_and_image, + # description="useful when you need an answer for a question based on an image. like: what is the background color of the last image, how many cats in this figure, what is in this figure. " + # "The input to this tool should be a comma seperated string of two, representing the image_path and the question"), + # Tool(name="Edge Detection On Image", func=self.image2canny.inference, + # description="useful when you want to detect the edge of the image. like: detect the edges of this image, or canny detection on image, or peform edge detection on this image, or detect the canny image of this image. " + # "The input to this tool should be a string, representing the image_path"), + # Tool(name="Generate Image Condition On Canny Image", func=self.canny2image.inference, + # description="useful when you want to generate a new real image from both the user desciption and a canny image. like: generate a real image of a object or something from this canny image, or generate a new real image of a object or something from this edge image. " + # "The input to this tool should be a comma seperated string of two, representing the image_path and the user description. "), + # Tool(name="Line Detection On Image", func=self.image2line.inference, + # description="useful when you want to detect the straight line of the image. like: detect the straight lines of this image, or straight line detection on image, or peform straight line detection on this image, or detect the straight line image of this image. " + # "The input to this tool should be a string, representing the image_path"), + # Tool(name="Generate Image Condition On Line Image", func=self.line2image.inference, + # description="useful when you want to generate a new real image from both the user desciption and a straight line image. like: generate a real image of a object or something from this straight line image, or generate a new real image of a object or something from this straight lines. " + # "The input to this tool should be a comma seperated string of two, representing the image_path and the user description. "), + # Tool(name="Hed Detection On Image", func=self.image2hed.inference, + # description="useful when you want to detect the soft hed boundary of the image. like: detect the soft hed boundary of this image, or hed boundary detection on image, or peform hed boundary detection on this image, or detect soft hed boundary image of this image. " + # "The input to this tool should be a string, representing the image_path"), + # Tool(name="Generate Image Condition On Soft Hed Boundary Image", func=self.hed2image.inference, + # description="useful when you want to generate a new real image from both the user desciption and a soft hed boundary image. like: generate a real image of a object or something from this soft hed boundary image, or generate a new real image of a object or something from this hed boundary. " + # "The input to this tool should be a comma seperated string of two, representing the image_path and the user description"), + # Tool(name="Segmentation On Image", func=self.image2seg.inference, + # description="useful when you want to detect segmentations of the image. like: segment this image, or generate segmentations on this image, or peform segmentation on this image. " + # "The input to this tool should be a string, representing the image_path"), + # Tool(name="Generate Image Condition On Segmentations", func=self.seg2image.inference, + # description="useful when you want to generate a new real image from both the user desciption and segmentations. like: generate a real image of a object or something from this segmentation image, or generate a new real image of a object or something from these segmentations. " + # "The input to this tool should be a comma seperated string of two, representing the image_path and the user description"), + # Tool(name="Predict Depth On Image", func=self.image2depth.inference, + # description="useful when you want to detect depth of the image. like: generate the depth from this image, or detect the depth map on this image, or predict the depth for this image. " + # "The input to this tool should be a string, representing the image_path"), + # Tool(name="Generate Image Condition On Depth", func=self.depth2image.inference, + # description="useful when you want to generate a new real image from both the user desciption and depth image. like: generate a real image of a object or something from this depth image, or generate a new real image of a object or something from the depth map. " + # "The input to this tool should be a comma seperated string of two, representing the image_path and the user description"), + # Tool(name="Predict Normal Map On Image", func=self.image2normal.inference, + # description="useful when you want to detect norm map of the image. like: generate normal map from this image, or predict normal map of this image. " + # "The input to this tool should be a string, representing the image_path"), + # Tool(name="Generate Image Condition On Normal Map", func=self.normal2image.inference, + # description="useful when you want to generate a new real image from both the user desciption and normal map. like: generate a real image of a object or something from this normal map, or generate a new real image of a object or something from the normal map. " + # "The input to this tool should be a comma seperated string of two, representing the image_path and the user description"), + # Tool(name="Sketch Detection On Image", func=self.image2scribble.inference, + # description="useful when you want to generate a scribble of the image. like: generate a scribble of this image, or generate a sketch from this image, detect the sketch from this image. " + # "The input to this tool should be a string, representing the image_path"), + # Tool(name="Generate Image Condition On Sketch Image", func=self.scribble2image.inference, + # description="useful when you want to generate a new real image from both the user desciption and a scribble image or a sketch image. " + # "The input to this tool should be a comma seperated string of two, representing the image_path and the user description"), + # Tool(name="Pose Detection On Image", func=self.image2pose.inference, + # description="useful when you want to detect the human pose of the image. like: generate human poses of this image, or generate a pose image from this image. " + # "The input to this tool should be a string, representing the image_path"), + # Tool(name="Generate Image Condition On Pose Image", func=self.pose2image.inference, + # description="useful when you want to generate a new real image from both the user desciption and a human pose image. like: generate a real image of a human from this human pose image, or generate a new real image of a human from this pose. " + # "The input to this tool should be a comma seperated string of two, representing the image_path and the user description")] self.agent = initialize_agent( self.tools, self.llm, @@ -955,4 +955,4 @@ def run_image(self, image, state, txt): clear.click(bot.memory.clear) clear.click(lambda: [], None, chatbot) clear.click(lambda: [], None, state) - demo.launch(server_name="0.0.0.0", server_port=7860) + demo.launch(server_name="0.0.0.0", server_port=7860, share=True)