tuandunghcmut commited on
Commit
783ae83
1 Parent(s): 4d107c7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -13
app.py CHANGED
@@ -9,7 +9,7 @@ from datetime import datetime
9
  import numpy as np
10
  import os
11
 
12
- HF_TOKEN = os.environ['HF_TOKEN']
13
  # subprocess.run('pip install flash-attn --no-build-isolation', env={'FLASH_ATTENTION_SKIP_CUDA_BUILD': "TRUE"}, shell=True)
14
 
15
  # models = {
@@ -21,8 +21,10 @@ def array_to_image_path(image_array):
21
  img = Image.fromarray(np.uint8(image_array))
22
 
23
  # Generate a unique filename using timestamp
24
- timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
25
- filename = f"image_{timestamp}.png"
 
 
26
 
27
  # Save the image
28
  img.save(filename)
@@ -33,21 +35,21 @@ def array_to_image_path(image_array):
33
  return full_path
34
 
35
  models = {
36
- "Qwen/Qwen2-VL-7B-Instruct": Qwen2VLForConditionalGeneration.from_pretrained(
37
- "Qwen/Qwen2-VL-7B-Instruct",
38
  trust_remote_code=True,
39
- token=HF_TOKEN,
40
- torch_dtype=torch.bfloat16,
41
- # attn_implementation="flash_attention_2"
42
  ).cuda().eval()
43
 
44
  }
45
 
46
  processors = {
47
- "Qwen/Qwen2-VL-7B-Instruct": AutoProcessor.from_pretrained("Qwen/Qwen2-VL-7B-Instruct", trust_remote_code=True)
48
  }
49
 
50
- DESCRIPTION = "[Qwen2-VL-7B Demo](https://huggingface.co/Qwen/Qwen2-VL-7B-Instruct)"
51
 
52
  kwargs = {}
53
  kwargs['torch_dtype'] = torch.bfloat16
@@ -57,7 +59,7 @@ assistant_prompt = '<|assistant|>\n'
57
  prompt_suffix = "<|end|>\n"
58
 
59
  @spaces.GPU
60
- def run_example(image, text_input=None, model_id="Qwen/Qwen2-VL-7B-Instruct"):
61
  image_path = array_to_image_path(image)
62
 
63
  print(image_path)
@@ -114,11 +116,11 @@ css = """
114
 
115
  with gr.Blocks(css=css) as demo:
116
  gr.Markdown(DESCRIPTION)
117
- with gr.Tab(label="Qwen2-VL-7B Input"):
118
  with gr.Row():
119
  with gr.Column():
120
  input_img = gr.Image(label="Input Picture")
121
- model_selector = gr.Dropdown(choices=list(models.keys()), label="Model", value="Qwen/Qwen2-VL-7B-Instruct")
122
  text_input = gr.Textbox(label="Question")
123
  submit_btn = gr.Button(value="Submit")
124
  with gr.Column():
 
9
  import numpy as np
10
  import os
11
 
12
+
13
  # subprocess.run('pip install flash-attn --no-build-isolation', env={'FLASH_ATTENTION_SKIP_CUDA_BUILD': "TRUE"}, shell=True)
14
 
15
  # models = {
 
21
  img = Image.fromarray(np.uint8(image_array))
22
 
23
  # Generate a unique filename using timestamp
24
+ # timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
25
+ # filename = f"image_{timestamp}.png" # comment this, only save 1 image int the local path
26
+
27
+ filename = "image_to_inference.png"
28
 
29
  # Save the image
30
  img.save(filename)
 
35
  return full_path
36
 
37
  models = {
38
+ "Qwen/Qwen2-VL-2B-Instruct": Qwen2VLForConditionalGeneration.from_pretrained(
39
+ "Qwen/Qwen2-VL-2B-Instruct",
40
  trust_remote_code=True,
41
+ # load_in_4bit=True,
42
+ # attn_implementation="flash_attention_2",
43
+ torch_dtype=torch.bfloat16
44
  ).cuda().eval()
45
 
46
  }
47
 
48
  processors = {
49
+ "Qwen/Qwen2-VL-2B-Instruct": AutoProcessor.from_pretrained("Qwen/Qwen2-VL-2B-Instruct", trust_remote_code=True)
50
  }
51
 
52
+ DESCRIPTION = "[Qwen2-VL-2B Demo](https://huggingface.co/Qwen/Qwen2-VL-2B-Instruct)"
53
 
54
  kwargs = {}
55
  kwargs['torch_dtype'] = torch.bfloat16
 
59
  prompt_suffix = "<|end|>\n"
60
 
61
  @spaces.GPU
62
+ def run_example(image, text_input=None, model_id="Qwen/Qwen2-VL-2B-Instruct"):
63
  image_path = array_to_image_path(image)
64
 
65
  print(image_path)
 
116
 
117
  with gr.Blocks(css=css) as demo:
118
  gr.Markdown(DESCRIPTION)
119
+ with gr.Tab(label="Qwen2-VL-2B Input"):
120
  with gr.Row():
121
  with gr.Column():
122
  input_img = gr.Image(label="Input Picture")
123
+ model_selector = gr.Dropdown(choices=list(models.keys()), label="Model", value="Qwen/Qwen2-VL-2B-Instruct")
124
  text_input = gr.Textbox(label="Question")
125
  submit_btn = gr.Button(value="Submit")
126
  with gr.Column():