Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,8 @@ import gradio as gr
|
|
| 2 |
import subprocess
|
| 3 |
import torch
|
| 4 |
from PIL import Image
|
| 5 |
-
from transformers import AutoProcessor,
|
|
|
|
| 6 |
|
| 7 |
subprocess.run(
|
| 8 |
"pip install --upgrade transformers>=4.50.0",
|
|
@@ -12,7 +13,7 @@ subprocess.run(
|
|
| 12 |
|
| 13 |
device = torch.device("cuda" if torch.cuda.is_available() else "CPU")
|
| 14 |
|
| 15 |
-
config
|
| 16 |
|
| 17 |
module_base = config.__module__.rsplit(".", 1)[0]
|
| 18 |
modeling_mod_path = module_base + ".modeling_florence2"
|
|
@@ -22,6 +23,10 @@ FlorenceLM = getattr(
|
|
| 22 |
modeling_mod,
|
| 23 |
"Florence2LanguageForConditionalGeneration"
|
| 24 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
florence_processor = AutoProcessor.from_pretrained(model, trust_remote_code=True)
|
| 26 |
|
| 27 |
def generate_caption(image):
|
|
|
|
| 2 |
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",
|
|
|
|
| 13 |
|
| 14 |
device = torch.device("cuda" if torch.cuda.is_available() else "CPU")
|
| 15 |
|
| 16 |
+
config = AutoConfig.from_pretrained(model_id, trust_remote_code=True)
|
| 17 |
|
| 18 |
module_base = config.__module__.rsplit(".", 1)[0]
|
| 19 |
modeling_mod_path = module_base + ".modeling_florence2"
|
|
|
|
| 23 |
modeling_mod,
|
| 24 |
"Florence2LanguageForConditionalGeneration"
|
| 25 |
)
|
| 26 |
+
florence_model = FlorenceLM.from_pretrained(
|
| 27 |
+
model_id,
|
| 28 |
+
trust_remote_code=True,
|
| 29 |
+
).to(device).eval()
|
| 30 |
florence_processor = AutoProcessor.from_pretrained(model, trust_remote_code=True)
|
| 31 |
|
| 32 |
def generate_caption(image):
|