lee-ite commited on
Commit
ed1ad2c
·
verified ·
1 Parent(s): 778660f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -9
app.py CHANGED
@@ -24,11 +24,11 @@ def fixed_get_imports(filename: str | os.PathLike) -> list[str]:
24
  imports.remove("flash_attn")
25
  return imports
26
 
27
-
28
- models = {
29
- 'microsoft/Florence-2-base-ft': AutoModelForCausalLM.from_pretrained('microsoft/Florence-2-base-ft', trust_remote_code=True, device_map='cpu'),
30
- 'microsoft/Florence-2-base': AutoModelForCausalLM.from_pretrained('microsoft/Florence-2-base', trust_remote_code=True, device_map='cpu'),
31
- }
32
 
33
  processors = {
34
  'microsoft/Florence-2-base-ft': AutoProcessor.from_pretrained('microsoft/Florence-2-base-ft', trust_remote_code=True),
@@ -49,14 +49,13 @@ def fig_to_pil(fig):
49
 
50
 
51
  def run_example(task_prompt, image, text_input=None, model_id='microsoft/Florence-2-base'):
52
- with patch("transformers.dynamic_module_utils.get_imports", fixed_get_imports):
53
- model = models[model_id]
54
- processor = processors[model_id]
55
  if text_input is None:
56
  prompt = task_prompt
57
  else:
58
  prompt = task_prompt + text_input
59
- inputs = processor(text=prompt, images=image, return_tensors="pt").to("cuda")
60
  generated_ids = model.generate(
61
  input_ids=inputs["input_ids"],
62
  pixel_values=inputs["pixel_values"],
 
24
  imports.remove("flash_attn")
25
  return imports
26
 
27
+ with patch("transformers.dynamic_module_utils.get_imports", fixed_get_imports):
28
+ models = {
29
+ 'microsoft/Florence-2-base-ft': AutoModelForCausalLM.from_pretrained('microsoft/Florence-2-base-ft', trust_remote_code=True, device_map='cpu'),
30
+ 'microsoft/Florence-2-base': AutoModelForCausalLM.from_pretrained('microsoft/Florence-2-base', trust_remote_code=True, device_map='cpu'),
31
+ }
32
 
33
  processors = {
34
  'microsoft/Florence-2-base-ft': AutoProcessor.from_pretrained('microsoft/Florence-2-base-ft', trust_remote_code=True),
 
49
 
50
 
51
  def run_example(task_prompt, image, text_input=None, model_id='microsoft/Florence-2-base'):
52
+ model = models[model_id]
53
+ processor = processors[model_id]
 
54
  if text_input is None:
55
  prompt = task_prompt
56
  else:
57
  prompt = task_prompt + text_input
58
+ inputs = processor(text=prompt, images=image, return_tensors="pt")
59
  generated_ids = model.generate(
60
  input_ids=inputs["input_ids"],
61
  pixel_values=inputs["pixel_values"],