zhangbofei commited on
Commit
da079a2
β€’
1 Parent(s): e871fb4
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ dependency
assets/example.jpg ADDED
requirements.txt CHANGED
@@ -1,10 +1,8 @@
1
- torch
2
- transformers
3
- accelerate
4
  aiohttp
5
- fastapi
6
  httpx
7
  numpy
8
  peft
9
  sentencepiece
10
- protobuf
 
 
1
+ llava @ git+https://github.com/MM-FIRE/FIRE
 
 
2
  aiohttp
 
3
  httpx
4
  numpy
5
  peft
6
  sentencepiece
7
+ protobuf
8
+ loguru
src/model/model_llava.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from llava.model.builder import load_pretrained_model
2
+ from llava.mm_utils import get_model_name_from_path, process_images, tokenizer_image_token
3
+ from llava.constants import IMAGE_TOKEN_INDEX, DEFAULT_IMAGE_TOKEN
4
+ from llava.conversation import conv_templates
5
+
6
+ from PIL import Image
7
+ import requests
8
+ import copy
9
+ import torch
10
+ from llava.mm_utils import process_images, tokenizer_image_token, get_model_name_from_path
11
+ import spaces
12
+ #model_path = "/scratch/TecManDep/A_Models/llava-v1.6-vicuna-7b"
13
+ #conv_template = "vicuna_v1" # Make sure you use correct chat template for different models
14
+
15
+ def load_llava_model():
16
+ model_path = "Lin-Chen/open-llava-next-llama3-8b"
17
+ conv_template = "llama_v3"
18
+ model_name = get_model_name_from_path(model_path)
19
+ device = "cuda"
20
+ device_map = "auto"
21
+ tokenizer, model, image_processor, max_length = load_pretrained_model(
22
+ model_path, None, model_name, device_map=device_map) # Add any other thing you want to pass in llava_model_args
23
+
24
+ model.eval()
25
+ model.tie_weights()
26
+ return tokenizer, model, image_processor, conv_template
27
+
28
+ tokenizer_llava, model_llava, image_processor_llava, conv_template_llava = load_llava_model()
29
+
30
+ @spaces.GPU
31
+ def inference():
32
+ image = Image.open("assets/example.jpg").convert("RGB")
33
+ device = "cuda"
34
+ image_tensor = process_images([image], image_processor_llava, model_llava.config)
35
+ image_tensor = image_tensor.to(dtype=torch.float16, device=device)
36
+
37
+ prompt = """<image>What is in the figure?"""
38
+ conv = conv_templates[conv_template_llava].copy()
39
+ conv.append_message(conv.roles[0], prompt)
40
+ conv.append_message(conv.roles[1], None)
41
+ prompt_question = conv.get_prompt()
42
+
43
+ input_ids = tokenizer_image_token(prompt_question, tokenizer_llava, IMAGE_TOKEN_INDEX, return_tensors="pt").unsqueeze(0).to(device)
44
+ image_sizes = [image.size]
45
+ print(input_ids.shape, image_tensor.shape)
46
+ with torch.inference_mode():
47
+ cont = model_llava.generate(
48
+ input_ids,
49
+ images=image_tensor,
50
+ image_sizes=image_sizes,
51
+ do_sample=False,
52
+ temperature=0,
53
+ max_new_tokens=256,
54
+ use_cache=True
55
+ )
56
+ text_outputs = tokenizer_llava.batch_decode(cont, skip_special_tokens=True)
57
+ print(text_outputs)
58
+ return text_outputs
59
+
60
+ if __name__ == "__main__":
61
+ inference()
src/serve/gradio_block_arena_vision_named.py CHANGED
@@ -242,14 +242,14 @@ def add_text(
242
 
243
  def build_side_by_side_vision_ui_named(models, random_questions=None):
244
  notice_markdown = """
245
- # βš”οΈ Vision Arena βš”οΈ : Benchmarking VLMs in the Wild (FIRE-LLAVA VS. LLAVA)
246
  | [Blog](https://lmsys.org/blog/2023-05-03-arena/) | [GitHub](https://github.com/lm-sys/FastChat) | [Paper](https://arxiv.org/abs/2306.05685) | [Dataset](https://github.com/lm-sys/FastChat/blob/main/docs/dataset_release.md) | [Twitter](https://twitter.com/lmsysorg) | [Discord](https://discord.gg/HSWAKCrnFx) |
247
 
248
  ## πŸ“œ Rules
249
  - Chat with any two models side-by-side and vote!
250
  - You can continue chatting for multiple rounds.
251
  - Click "Clear history" to start a new round.
252
- - You can only chat with <span style='color: #DE3163; font-weight: bold'>one image per conversation</span>. You can upload images less than 15MB. Click the "Random Example" button to chat with a random image.
253
 
254
  **❗️ For research purposes, we log user prompts and images, and may release this data to the public in the future. Please do not upload any confidential or personal information.**
255
 
 
242
 
243
  def build_side_by_side_vision_ui_named(models, random_questions=None):
244
  notice_markdown = """
245
+ # βš”οΈ Vision Arena βš”οΈ : Benchmarking VLMs (FIRE-LLAVA VS. LLAVA)
246
  | [Blog](https://lmsys.org/blog/2023-05-03-arena/) | [GitHub](https://github.com/lm-sys/FastChat) | [Paper](https://arxiv.org/abs/2306.05685) | [Dataset](https://github.com/lm-sys/FastChat/blob/main/docs/dataset_release.md) | [Twitter](https://twitter.com/lmsysorg) | [Discord](https://discord.gg/HSWAKCrnFx) |
247
 
248
  ## πŸ“œ Rules
249
  - Chat with any two models side-by-side and vote!
250
  - You can continue chatting for multiple rounds.
251
  - Click "Clear history" to start a new round.
252
+ - You can only chat with <span style='color: #DE3163; font-weight: bold'>one image per conversation</span>. You can upload images less than 15MB.
253
 
254
  **❗️ For research purposes, we log user prompts and images, and may release this data to the public in the future. Please do not upload any confidential or personal information.**
255