DiningSystem commited on
Commit
551a079
1 Parent(s): 4a6e749

Upload 10 files

Browse files
.gitattributes CHANGED
@@ -32,3 +32,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
32
  *.zip filter=lfs diff=lfs merge=lfs -text
33
  *.zst filter=lfs diff=lfs merge=lfs -text
34
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
32
  *.zip filter=lfs diff=lfs merge=lfs -text
33
  *.zst filter=lfs diff=lfs merge=lfs -text
34
  *tfevents* filter=lfs diff=lfs merge=lfs -text
35
+ MiniGPT_4.pdf filter=lfs diff=lfs merge=lfs -text
CODEOWNERS ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ # Comment line immediately above ownership line is reserved for related gus information. Please be careful while editing.
2
+ #ECCN:Open Source
LICENSE.txt ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2022 Salesforce, Inc.
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
9
+
10
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
11
+
12
+ 3. Neither the name of Salesforce.com nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
13
+
14
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
MANIFEST.in ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ recursive-include minigpt4/configs *.yaml *.json
2
+ recursive-include minigpt4/projects *.yaml *.json
3
+
4
+ recursive-exclude minigpt4/datasets/download_scripts *
5
+ recursive-exclude minigpt4/output *
6
+
7
+ include requirements.txt
README.md CHANGED
@@ -1,13 +1,14 @@
1
  ---
2
- title: Hair Space
3
- emoji: 💻
4
- colorFrom: blue
5
- colorTo: indigo
6
  sdk: gradio
7
- sdk_version: 3.24.1
8
  app_file: app.py
9
  pinned: false
10
- license: mit
 
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: MiniGPT-4
3
+ emoji: 🚀
4
+ colorFrom: purple
5
+ colorTo: gray
6
  sdk: gradio
7
+ sdk_version: 3.27.0
8
  app_file: app.py
9
  pinned: false
10
+ license: other
11
+ duplicated_from: Vision-CAIR/minigpt4
12
  ---
13
 
14
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py CHANGED
@@ -1,32 +1,154 @@
1
- import gradio as gr
2
- from diffusers import StableDiffusionPipeline
3
- import torch
4
- import huggingface_hub as hf
5
  import os
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
- my_file = open("./style_name.txt", "r")
8
-
9
- # reading the file
10
- data = my_file.read()
11
-
12
- # replacing end splitting the text
13
- # when newline ('\n') is seen.
14
- data_into_list = data.split("\n")[:-1]
15
 
16
- my_file.close()
 
17
 
18
- hf.login(token=os.environ['model_token'])
19
- #remember to login with token before loading model
20
- def text_to_hair(prompt, guidance_scale=8, num_inference_steps=30, styles=data_into_list, model_path ="DiningSystem/hair-model2"):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
- pipe = StableDiffusionPipeline.from_pretrained(os.environ['bmd'], torch_dtype=torch.float16, use_auth_token=True)
23
- pipe.unet.load_attn_procs(model_path)
24
- pipe.to("cuda")
25
- image = pipe(prompt, num_inference_steps=num_inference_steps, guidance_scale=guidance_scale).images[0]
26
- #image.save(save_name) #comment if don't want to save image
27
- return image #PIL format
28
-
29
- demo = gr.Interface(fn=text_to_hair, inputs=["text", gr.Slider(5, 20, value=8, label="Guidance_scale", info="Choose between 5 and 20 to improve image's content"),
30
- gr.Slider(20, 500, value=20, label="Num_infer_steps", info="Choose between 20 and 500 to improve image's resolution"),
31
- gr.Dropdown(data_into_list, interactive=True, label="Some suggestion hairstyles", info="For your suggestion and reference!")],outputs="image")
32
- demo.launch()
 
1
+ import argparse
 
 
 
2
  import os
3
+ import random
4
+
5
+ import numpy as np
6
+ import torch
7
+ import torch.backends.cudnn as cudnn
8
+ import gradio as gr
9
+
10
+ from minigpt4.common.config import Config
11
+ from minigpt4.common.dist_utils import get_rank
12
+ from minigpt4.common.registry import registry
13
+ from minigpt4.conversation.conversation import Chat, CONV_VISION
14
+
15
+ # imports modules for registration
16
+ from minigpt4.datasets.builders import *
17
+ from minigpt4.models import *
18
+ from minigpt4.processors import *
19
+ from minigpt4.runners import *
20
+ from minigpt4.tasks import *
21
+
22
+ def parse_args():
23
+ parser = argparse.ArgumentParser(description="Demo")
24
+ parser.add_argument("--cfg-path", type=str, default='eval_configs/minigpt4.yaml', help="path to configuration file.")
25
+ parser.add_argument(
26
+ "--options",
27
+ nargs="+",
28
+ help="override some settings in the used config, the key-value pair "
29
+ "in xxx=yyy format will be merged into config file (deprecate), "
30
+ "change to --cfg-options instead.",
31
+ )
32
+ args = parser.parse_args()
33
+ return args
34
+
35
+
36
+ def setup_seeds(config):
37
+ seed = config.run_cfg.seed + get_rank()
38
+
39
+ random.seed(seed)
40
+ np.random.seed(seed)
41
+ torch.manual_seed(seed)
42
+
43
+ cudnn.benchmark = False
44
+ cudnn.deterministic = True
45
+
46
+ # ========================================
47
+ # Model Initialization
48
+ # ========================================
49
+
50
+ SHARED_UI_WARNING = f'''### [NOTE] It is possible that you are waiting in a lengthy queue.
51
+
52
+ You can duplicate and use it with a paid private GPU.
53
 
54
+ <a class="duplicate-button" style="display:inline-block" target="_blank" href="https://huggingface.co/spaces/Vision-CAIR/minigpt4?duplicate=true"><img style="margin-top:0;margin-bottom:0" src="https://huggingface.co/datasets/huggingface/badges/raw/main/duplicate-this-space-xl-dark.svg" alt="Duplicate Space"></a>
 
 
 
 
 
 
 
55
 
56
+ Alternatively, you can also use the demo on our [project page](https://minigpt-4.github.io).
57
+ '''
58
 
59
+ print('Initializing Chat')
60
+ cfg = Config(parse_args())
61
+
62
+ model_config = cfg.model_cfg
63
+ model_cls = registry.get_model_class(model_config.arch)
64
+ model = model_cls.from_config(model_config).to('cuda:0')
65
+
66
+ vis_processor_cfg = cfg.datasets_cfg.cc_align.vis_processor.train
67
+ vis_processor = registry.get_processor_class(vis_processor_cfg.name).from_config(vis_processor_cfg)
68
+ chat = Chat(model, vis_processor)
69
+ print('Initialization Finished')
70
+
71
+ # ========================================
72
+ # Gradio Setting
73
+ # ========================================
74
+
75
+ def gradio_reset(chat_state, img_list):
76
+ if chat_state is not None:
77
+ chat_state.messages = []
78
+ if img_list is not None:
79
+ img_list = []
80
+ return None, gr.update(value=None, interactive=True), gr.update(placeholder='Please upload your image first', interactive=False), gr.update(value="Upload & Start Chat", interactive=True), chat_state, img_list
81
+
82
+ def upload_img(gr_img, text_input, chat_state):
83
+ if gr_img is None:
84
+ return None, None, gr.update(interactive=True), chat_state, None
85
+ chat_state = CONV_VISION.copy()
86
+ img_list = []
87
+ llm_message = chat.upload_img(gr_img, chat_state, img_list)
88
+ return gr.update(interactive=False), gr.update(interactive=True, placeholder='Type and press Enter'), gr.update(value="Start Chatting", interactive=False), chat_state, img_list
89
+
90
+ def gradio_ask(user_message, chatbot, chat_state):
91
+ if len(user_message) == 0:
92
+ return gr.update(interactive=True, placeholder='Input should not be empty!'), chatbot, chat_state
93
+ chat.ask(user_message, chat_state)
94
+ chatbot = chatbot + [[user_message, None]]
95
+ return '', chatbot, chat_state
96
+
97
+
98
+ def gradio_answer(chatbot, chat_state, img_list, num_beams, temperature):
99
+ llm_message = chat.answer(conv=chat_state, img_list=img_list, max_new_tokens=300, num_beams=1, temperature=temperature, max_length=2000)[0]
100
+ chatbot[-1][1] = llm_message
101
+ return chatbot, chat_state, img_list
102
+
103
+ title = """<h1 align="center">Demo of MiniGPT-4</h1>"""
104
+ description = """<h3>This is the demo of MiniGPT-4. Upload your images and start chatting!</h3>"""
105
+ article = """<div style='display:flex; gap: 0.25rem; '><a href='https://minigpt-4.github.io'><img src='https://img.shields.io/badge/Project-Page-Green'></a><a href='https://github.com/Vision-CAIR/MiniGPT-4'><img src='https://img.shields.io/badge/Github-Code-blue'></a><a href='https://github.com/TsuTikgiau/blip2-llm/blob/release_prepare/MiniGPT_4.pdf'><img src='https://img.shields.io/badge/Paper-PDF-red'></a></div>
106
+ """
107
+
108
+ #TODO show examples below
109
+
110
+ with gr.Blocks() as demo:
111
+ gr.Markdown(title)
112
+ gr.Markdown(SHARED_UI_WARNING)
113
+ gr.Markdown(description)
114
+ gr.Markdown(article)
115
+
116
+ with gr.Row():
117
+ with gr.Column(scale=0.5):
118
+ image = gr.Image(type="pil")
119
+ upload_button = gr.Button(value="Upload & Start Chat", interactive=True, variant="primary")
120
+ clear = gr.Button("Restart")
121
+
122
+ num_beams = gr.Slider(
123
+ minimum=1,
124
+ maximum=5,
125
+ value=1,
126
+ step=1,
127
+ interactive=True,
128
+ label="beam search numbers)",
129
+ )
130
+
131
+ temperature = gr.Slider(
132
+ minimum=0.1,
133
+ maximum=2.0,
134
+ value=1.0,
135
+ step=0.1,
136
+ interactive=True,
137
+ label="Temperature",
138
+ )
139
+
140
+
141
+ with gr.Column():
142
+ chat_state = gr.State()
143
+ img_list = gr.State()
144
+ chatbot = gr.Chatbot(label='MiniGPT-4')
145
+ text_input = gr.Textbox(label='User', placeholder='Please upload your image first', interactive=False)
146
+
147
+ upload_button.click(upload_img, [image, text_input, chat_state], [image, text_input, upload_button, chat_state, img_list])
148
 
149
+ text_input.submit(gradio_ask, [text_input, chatbot, chat_state], [text_input, chatbot, chat_state]).then(
150
+ gradio_answer, [chatbot, chat_state, img_list, num_beams, temperature], [chatbot, chat_state, img_list]
151
+ )
152
+ clear.click(gradio_reset, [chat_state, img_list], [chatbot, image, text_input, upload_button, chat_state, img_list], queue=False)
153
+
154
+ demo.launch(enable_queue=True)
 
 
 
 
 
blip2_pretrained_flant5xxl.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4b3839ea6c617f315ead9bf4036bbb0f0cf6bf62695ecfc14968ea626af03a29
3
+ size 433481467
checkpoint.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1e7b8a3c21f146654c21a1a29a577dab2c3bd1aa3b1bc902f39e86954357a811
3
+ size 47369169
prerained_minigpt4_7b.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:017a9ed588a11ed383711003cf50cf675191420a04689f682fb56fa9bbb8dcbb
3
+ size 37907201
requirements.txt CHANGED
@@ -1,6 +1,7 @@
1
- diffusers
2
- huggingface-hub
3
- torch
4
- transformers
 
5
  accelerate
6
- gradio==3.26.0
 
1
+ --extra-index-url https://download.pytorch.org/whl/cu113
2
+ torch==1.12.1
3
+ torchvision==0.13.1
4
+ salesforce-lavis
5
+ bitsandbytes
6
  accelerate
7
+ git+https://github.com/huggingface/transformers.git