torch
Browse files- app.py +12 -2
- requirements.txt +1 -0
app.py
CHANGED
@@ -5,9 +5,19 @@ from unittest.mock import patch
|
|
5 |
import gradio as gr
|
6 |
import ast
|
7 |
from transformers import AutoModelForCausalLM, AutoProcessor
|
|
|
8 |
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
def draw_boxes(image, quad_boxes):
|
13 |
draw = ImageDraw.Draw(image)
|
|
|
5 |
import gradio as gr
|
6 |
import ast
|
7 |
from transformers import AutoModelForCausalLM, AutoProcessor
|
8 |
+
from transformers.dynamic_module_utils import get_imports
|
9 |
|
10 |
+
def fixed_get_imports(filename: str | os.PathLike) -> list[str]:
|
11 |
+
"""Work around for https://huggingface.co/microsoft/phi-1_5/discussions/72."""
|
12 |
+
if not str(filename).endswith("/modeling_florence2.py"):
|
13 |
+
return get_imports(filename)
|
14 |
+
imports = get_imports(filename)
|
15 |
+
imports.remove("flash_attn")
|
16 |
+
return imports
|
17 |
+
|
18 |
+
with patch("transformers.dynamic_module_utils.get_imports", fixed_get_imports):
|
19 |
+
model = AutoModelForCausalLM.from_pretrained("microsoft/Florence-2-large-ft", trust_remote_code=True)
|
20 |
+
processor = AutoProcessor.from_pretrained("microsoft/Florence-2-large-ft", trust_remote_code=True)
|
21 |
|
22 |
def draw_boxes(image, quad_boxes):
|
23 |
draw = ImageDraw.Draw(image)
|
requirements.txt
CHANGED
@@ -2,3 +2,4 @@ gradio==4.40.0
|
|
2 |
Pillow==9.1.0
|
3 |
Requests==2.32.3
|
4 |
transformers==4.24.0
|
|
|
|
2 |
Pillow==9.1.0
|
3 |
Requests==2.32.3
|
4 |
transformers==4.24.0
|
5 |
+
torch
|