Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
30 |
-
|
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 |
-
|
53 |
-
|
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")
|
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"],
|