sergiopaniego commited on
Commit
1a981c9
·
1 Parent(s): 1cc7126

Updated model

Browse files
Files changed (1) hide show
  1. app.py +17 -13
app.py CHANGED
@@ -1,6 +1,6 @@
1
  import gradio as gr
2
  import spaces
3
- from transformers import Qwen2VLForConditionalGeneration, AutoProcessor
4
  from qwen_vl_utils import process_vision_info
5
  import torch
6
  from PIL import Image
@@ -28,15 +28,18 @@ def array_to_image_path(image_array):
28
  full_path = os.path.abspath(filename)
29
 
30
  return full_path
31
-
32
- models = {
33
- "sergiopaniego/qwen2-7b-instruct-trl-sft-ChartQA": Qwen2VLForConditionalGeneration.from_pretrained("sergiopaniego/qwen2-7b-instruct-trl-sft-ChartQA", trust_remote_code=True, torch_dtype="auto").cuda().eval()
34
 
35
- }
36
 
37
- processors = {
38
- "sergiopaniego/qwen2-7b-instruct-trl-sft-ChartQA": AutoProcessor.from_pretrained("sergiopaniego/qwen2-7b-instruct-trl-sft-ChartQA", trust_remote_code=True)
39
- }
 
 
 
 
 
 
 
40
 
41
  DESCRIPTION = "[Qwen2-VL-7B Demo](https://huggingface.co/Qwen/Qwen2-VL-7B-Instruct)"
42
 
@@ -48,12 +51,12 @@ assistant_prompt = '<|assistant|>\n'
48
  prompt_suffix = "<|end|>\n"
49
 
50
  @spaces.GPU
51
- def run_example(image, text_input=None, model_id="sergiopaniego/qwen2-7b-instruct-trl-sft-ChartQA"):
52
  image_path = array_to_image_path(image)
53
 
54
  print(image_path)
55
- model = models[model_id]
56
- processor = processors[model_id]
57
 
58
  prompt = f"{user_prompt}<|image_1|>\n{text_input}{prompt_suffix}{assistant_prompt}"
59
  image = Image.fromarray(image).convert("RGB")
@@ -112,13 +115,14 @@ with gr.Blocks(css=css) as demo:
112
  with gr.Row():
113
  with gr.Column():
114
  input_img = gr.Image(label="Input Picture")
115
- model_selector = gr.Dropdown(choices=list(models.keys()), label="Model", value="sergiopaniego/qwen2-7b-instruct-trl-sft-ChartQA")
116
  text_input = gr.Textbox(label="Question")
117
  submit_btn = gr.Button(value="Submit")
118
  with gr.Column():
119
  output_text = gr.Textbox(label="Output Text")
120
 
121
- submit_btn.click(run_example, [input_img, text_input, model_selector], [output_text])
 
122
 
123
  demo.queue(api_open=False)
124
  demo.launch(debug=True)
 
1
  import gradio as gr
2
  import spaces
3
+ from transformers import Qwen2VLForConditionalGeneration, Qwen2VLProcessor
4
  from qwen_vl_utils import process_vision_info
5
  import torch
6
  from PIL import Image
 
28
  full_path = os.path.abspath(filename)
29
 
30
  return full_path
 
 
 
31
 
 
32
 
33
+ model_id = "Qwen/Qwen2-VL-7B-Instruct"
34
+ model = Qwen2VLForConditionalGeneration.from_pretrained(
35
+ model_id,
36
+ device_map="auto",
37
+ torch_dtype=torch.bfloat16,
38
+ )
39
+ adapter_path = "sergiopaniego/qwen2-7b-instruct-trl-sft-ChartQA"
40
+ model.load_adapter(adapter_path)
41
+
42
+ processor = Qwen2VLProcessor.from_pretrained(model_id)
43
 
44
  DESCRIPTION = "[Qwen2-VL-7B Demo](https://huggingface.co/Qwen/Qwen2-VL-7B-Instruct)"
45
 
 
51
  prompt_suffix = "<|end|>\n"
52
 
53
  @spaces.GPU
54
+ def run_example(image, text_input=None):
55
  image_path = array_to_image_path(image)
56
 
57
  print(image_path)
58
+ #model = models[model_id]
59
+ #processor = processors[model_id]
60
 
61
  prompt = f"{user_prompt}<|image_1|>\n{text_input}{prompt_suffix}{assistant_prompt}"
62
  image = Image.fromarray(image).convert("RGB")
 
115
  with gr.Row():
116
  with gr.Column():
117
  input_img = gr.Image(label="Input Picture")
118
+ #model_selector = gr.Dropdown(choices=list(models.keys()), label="Model", value="sergiopaniego/qwen2-7b-instruct-trl-sft-ChartQA")
119
  text_input = gr.Textbox(label="Question")
120
  submit_btn = gr.Button(value="Submit")
121
  with gr.Column():
122
  output_text = gr.Textbox(label="Output Text")
123
 
124
+ #submit_btn.click(run_example, [input_img, text_input, model_selector], [output_text])
125
+ submit_btn.click(run_example, [input_img, text_input], [output_text])
126
 
127
  demo.queue(api_open=False)
128
  demo.launch(debug=True)