Spaces:
Running
Running
replace Qwen2-VL with Florence-2 API for caption generation
Browse files
app.py
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
|
| 2 |
import os
|
| 3 |
import torch
|
|
@@ -86,7 +94,7 @@ def generate_captions_api(image):
|
|
| 86 |
],
|
| 87 |
"max_tokens": 80
|
| 88 |
}
|
| 89 |
-
response = requests.post(
|
| 90 |
|
| 91 |
headers=HF_HEADERS,
|
| 92 |
json=payload,
|
|
@@ -134,7 +142,7 @@ def compute_jina_scores(image, captions):
|
|
| 134 |
"documents": ["data:image/jpeg;base64," + img_b64],
|
| 135 |
"top_n": 1
|
| 136 |
}
|
| 137 |
-
response = requests.post(
|
| 138 |
JINA_URL,
|
| 139 |
headers=JINA_HEADERS,
|
| 140 |
json=payload,
|
|
@@ -232,7 +240,7 @@ def fuse_captions_api(cap1, cap2, dino_labels):
|
|
| 232 |
"temperature" : 0.1,
|
| 233 |
"repetition_penalty": 1.1
|
| 234 |
}
|
| 235 |
-
response = requests.post(
|
| 236 |
QWEN_LM_URL,
|
| 237 |
headers=HF_HEADERS,
|
| 238 |
json=payload,
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
from io import BytesIO
|
| 3 |
+
FLORENCE_URL = "https://api-inference.huggingface.co/models/microsoft/Florence-2-large"
|
| 4 |
+
HF_HEADERS = {"Authorization": f"Bearer {HF_TOKEN}"} if "HF_TOKEN" in locals() or "HF_TOKEN" in globals() else {}
|
| 5 |
+
import requests
|
| 6 |
+
from io import BytesIO
|
| 7 |
+
FLORENCE_URL = "https://api-inference.huggingface.co/models/microsoft/Florence-2-large"
|
| 8 |
+
HF_HEADERS = {"Authorization": f"Bearer {HF_TOKEN}"} if "HF_TOKEN" in locals() or "HF_TOKEN" in globals() else {}
|
| 9 |
|
| 10 |
import os
|
| 11 |
import torch
|
|
|
|
| 94 |
],
|
| 95 |
"max_tokens": 80
|
| 96 |
}
|
| 97 |
+
response = requests.post(FLORENCE_URL,
|
| 98 |
|
| 99 |
headers=HF_HEADERS,
|
| 100 |
json=payload,
|
|
|
|
| 142 |
"documents": ["data:image/jpeg;base64," + img_b64],
|
| 143 |
"top_n": 1
|
| 144 |
}
|
| 145 |
+
response = requests.post(FLORENCE_URL,
|
| 146 |
JINA_URL,
|
| 147 |
headers=JINA_HEADERS,
|
| 148 |
json=payload,
|
|
|
|
| 240 |
"temperature" : 0.1,
|
| 241 |
"repetition_penalty": 1.1
|
| 242 |
}
|
| 243 |
+
response = requests.post(FLORENCE_URL,
|
| 244 |
QWEN_LM_URL,
|
| 245 |
headers=HF_HEADERS,
|
| 246 |
json=payload,
|