dwb2023 commited on
Commit
fe0fab6
·
verified ·
1 Parent(s): a152719

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -12
app.py CHANGED
@@ -1,7 +1,7 @@
1
- import spaces
2
  import gradio as gr
3
  from transformers import AutoProcessor, AutoModelForCausalLM
4
  # import peft
 
5
 
6
  import requests
7
  import copy
@@ -20,14 +20,11 @@ subprocess.run('pip install flash-attn --no-build-isolation', env={'FLASH_ATTENT
20
  models = {
21
  'microsoft/Florence-2-large-ft': AutoModelForCausalLM.from_pretrained('microsoft/Florence-2-large-ft', trust_remote_code=True).to("cuda").eval(),
22
  'dwb2023/florence2-large-bccd-base-ft': AutoModelForCausalLM.from_pretrained('dwb2023/florence2-large-bccd-base-ft', trust_remote_code=True).to("cuda").eval(),
23
- 'dwb2023/florence2-large-liver-disease-ft': AutoModelForCausalLM.from_pretrained('dwb2023/florence2-large-liver-disease-ft', trust_remote_code=True).to("cuda").eval(),
24
-
25
  }
26
 
27
  processors = {
28
  'microsoft/Florence-2-large-ft': AutoProcessor.from_pretrained('microsoft/Florence-2-large-ft', trust_remote_code=True),
29
- 'dwb2023/florence2-large-bccd-base-ft': AutoProcessor.from_pretrained('microsoft/Florence-2-large-ft', trust_remote_code=True),
30
- 'dwb2023/florence2-large-liver-disease-ft': AutoProcessor.from_pretrained('microsoft/Florence-2-large-ft', trust_remote_code=True),
31
  }
32
 
33
  colormap = ['blue','orange','green','purple','brown','pink','gray','olive','cyan','red',
@@ -40,7 +37,7 @@ def fig_to_pil(fig):
40
  return Image.open(buf)
41
 
42
  @spaces.GPU
43
- def run_example(task_prompt, image, text_input=None, model_id='dwb2023/florence2-large-liver-disease-ft'):
44
  model = models[model_id]
45
  processor = processors[model_id]
46
  if text_input is None:
@@ -118,7 +115,7 @@ def draw_ocr_bboxes(image, prediction):
118
  fill=color)
119
  return image
120
 
121
- def process_image(image, task_prompt, text_input=None, model_id='dwb2023/florence2-large-liver-disease-ft'):
122
  image = Image.fromarray(image) # Convert NumPy array to PIL Image
123
  if task_prompt == 'Object Detection':
124
  task_prompt = '<OD>'
@@ -145,7 +142,7 @@ with gr.Blocks(theme="sudeepshouche/minimalist") as demo:
145
  with gr.Row():
146
  with gr.Column():
147
  input_img = gr.Image(label="Input Picture")
148
- model_selector = gr.Dropdown(choices=list(models.keys()), label="Model", value='dwb2023/florence2-large-liver-disease-ft')
149
  task_prompt = gr.Dropdown(choices=single_task_list, label="Task Prompt", value="Object Detection")
150
  text_input = gr.Textbox(label="Text Input", placeholder="Not used for Florence-2 Object Detection")
151
  submit_btn = gr.Button(value="Submit")
@@ -161,10 +158,8 @@ with gr.Blocks(theme="sudeepshouche/minimalist") as demo:
161
  ["examples/bccd-test/BloodImage_00090_jpg.rf.7e3d419774b20ef93d4ec6c4be8f64df.jpg", 'Object Detection'],
162
  ["examples/bccd-test/BloodImage_00099_jpg.rf.0a65e56401cdd71253e7bc04917c3558.jpg", 'Object Detection'],
163
  ["examples/bccd-test/BloodImage_00112_jpg.rf.6b8d185de08e65c6d765c824bb76ec68.jpg", 'Object Detection'],
164
- ["examples/liver-test/15_239_101_64_47_jpg.rf.c23cc3f6ba46896ce9c2cf3ee242bbaf.jpg", 'Object Detection'],
165
- ["examples/liver-test/15_242_208_18_9_jpg.rf.b1ae586b5c888d8347a21acabe80ec0e.jpg", 'Object Detection'],
166
- ["examples/liver-test/15_239_203_35_22_jpg.rf.408ffd5311f8d90f5db8f5913e876dc9.jpg", 'Object Detection'],
167
- ["examples/liver-test/15_242_202_12_107_jpg.rf.4d864b8288a54e618e6fa0c327e1445e.jpg", 'Object Detection']
168
  ],
169
 
170
  inputs=[input_img, task_prompt],
 
 
1
  import gradio as gr
2
  from transformers import AutoProcessor, AutoModelForCausalLM
3
  # import peft
4
+ import spaces
5
 
6
  import requests
7
  import copy
 
20
  models = {
21
  'microsoft/Florence-2-large-ft': AutoModelForCausalLM.from_pretrained('microsoft/Florence-2-large-ft', trust_remote_code=True).to("cuda").eval(),
22
  'dwb2023/florence2-large-bccd-base-ft': AutoModelForCausalLM.from_pretrained('dwb2023/florence2-large-bccd-base-ft', trust_remote_code=True).to("cuda").eval(),
 
 
23
  }
24
 
25
  processors = {
26
  'microsoft/Florence-2-large-ft': AutoProcessor.from_pretrained('microsoft/Florence-2-large-ft', trust_remote_code=True),
27
+ 'dwb2023/florence2-large-bccd-base-ft': AutoProcessor.from_pretrained('microsoft/Florence-2-large-ft', trust_remote_code=True),
 
28
  }
29
 
30
  colormap = ['blue','orange','green','purple','brown','pink','gray','olive','cyan','red',
 
37
  return Image.open(buf)
38
 
39
  @spaces.GPU
40
+ def run_example(task_prompt, image, text_input=None, model_id='dwb2023/florence2-large-bccd-base-ft'):
41
  model = models[model_id]
42
  processor = processors[model_id]
43
  if text_input is None:
 
115
  fill=color)
116
  return image
117
 
118
+ def process_image(image, task_prompt, text_input=None, model_id='dwb2023/florence2-large-bccd-base-ft'):
119
  image = Image.fromarray(image) # Convert NumPy array to PIL Image
120
  if task_prompt == 'Object Detection':
121
  task_prompt = '<OD>'
 
142
  with gr.Row():
143
  with gr.Column():
144
  input_img = gr.Image(label="Input Picture")
145
+ model_selector = gr.Dropdown(choices=list(models.keys()), label="Model", value='dwb2023/florence2-large-bccd-base-ft')
146
  task_prompt = gr.Dropdown(choices=single_task_list, label="Task Prompt", value="Object Detection")
147
  text_input = gr.Textbox(label="Text Input", placeholder="Not used for Florence-2 Object Detection")
148
  submit_btn = gr.Button(value="Submit")
 
158
  ["examples/bccd-test/BloodImage_00090_jpg.rf.7e3d419774b20ef93d4ec6c4be8f64df.jpg", 'Object Detection'],
159
  ["examples/bccd-test/BloodImage_00099_jpg.rf.0a65e56401cdd71253e7bc04917c3558.jpg", 'Object Detection'],
160
  ["examples/bccd-test/BloodImage_00112_jpg.rf.6b8d185de08e65c6d765c824bb76ec68.jpg", 'Object Detection'],
161
+ ["examples/bccd-test/BloodImage_00113_jpg.rf.ab69dfaa52c1b3249cf44fa66afbb619.jpg", 'Object Detection'],
162
+ ["examples/bccd-test/BloodImage_00120_jpg.rf.4a2f84ca3564ef453b12ceb9c852e32e.jpg", 'Object Detection'],
 
 
163
  ],
164
 
165
  inputs=[input_img, task_prompt],