Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,7 @@ import subprocess
|
|
3 |
import torch
|
4 |
from PIL import Image
|
5 |
from transformers import AutoProcessor, AutoConfig
|
6 |
-
import importlib, sys
|
7 |
|
8 |
subprocess.run(
|
9 |
"pip install --upgrade transformers>=4.50.0",
|
@@ -17,17 +17,23 @@ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
17 |
|
18 |
config = AutoConfig.from_pretrained(model_id, trust_remote_code=True)
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
"
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
florence_model = FlorenceLM.from_pretrained(
|
29 |
model_id,
|
30 |
-
trust_remote_code=True
|
31 |
).to(device).eval()
|
32 |
florence_processor = AutoProcessor.from_pretrained(model, trust_remote_code=True)
|
33 |
|
|
|
3 |
import torch
|
4 |
from PIL import Image
|
5 |
from transformers import AutoProcessor, AutoConfig
|
6 |
+
import importlib.util, sys, os
|
7 |
|
8 |
subprocess.run(
|
9 |
"pip install --upgrade transformers>=4.50.0",
|
|
|
17 |
|
18 |
config = AutoConfig.from_pretrained(model_id, trust_remote_code=True)
|
19 |
|
20 |
+
mconfig_mod_name = config.__class__.__module__
|
21 |
+
config_mod = sys.modules[config_mod_name]
|
22 |
+
code_dir = os.path.dirname(config_mod.__file__)
|
23 |
|
24 |
+
modeling_path = os.path.join(code_dir, "modeling_florence2.py")
|
25 |
+
if not os.path.exists(modeling_path):
|
26 |
+
raise FileNotFoundError(f"Couldnβt find {modeling_path}")
|
27 |
+
|
28 |
+
spec = importlib.util.spec_from_file_location("florence2_modeling", modeling_path)
|
29 |
+
flor_mod = importlib.util.module_from_spec(spec)
|
30 |
+
sys.modules["florence2_modeling"] = flor_mod
|
31 |
+
spec.loader.exec_module(flor_mod)
|
32 |
+
|
33 |
+
FlorenceLM = flor_mod.Florence2LanguageForConditionalGeneration
|
34 |
florence_model = FlorenceLM.from_pretrained(
|
35 |
model_id,
|
36 |
+
trust_remote_code=True
|
37 |
).to(device).eval()
|
38 |
florence_processor = AutoProcessor.from_pretrained(model, trust_remote_code=True)
|
39 |
|