ProGamerGov/synthetic-dataset-1m-dalle3-high-quality-captions
Updated β’ 2.99k β’ 154
How to use gokaygokay/Florence-2-SD3-Captioner with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("image-text-to-text", model="gokaygokay/Florence-2-SD3-Captioner", trust_remote_code=True) # Load model directly
from transformers import AutoProcessor, AutoModelForMultimodalLM
processor = AutoProcessor.from_pretrained("gokaygokay/Florence-2-SD3-Captioner", trust_remote_code=True)
model = AutoModelForMultimodalLM.from_pretrained("gokaygokay/Florence-2-SD3-Captioner", trust_remote_code=True, device_map="auto")How to use gokaygokay/Florence-2-SD3-Captioner with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "gokaygokay/Florence-2-SD3-Captioner"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "gokaygokay/Florence-2-SD3-Captioner",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'docker model run hf.co/gokaygokay/Florence-2-SD3-Captioner
How to use gokaygokay/Florence-2-SD3-Captioner with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "gokaygokay/Florence-2-SD3-Captioner" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "gokaygokay/Florence-2-SD3-Captioner",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'docker run --gpus all \
--shm-size 32g \
-p 30000:30000 \
-v ~/.cache/huggingface:/root/.cache/huggingface \
--env "HF_TOKEN=<secret>" \
--ipc=host \
lmsysorg/sglang:latest \
python3 -m sglang.launch_server \
--model-path "gokaygokay/Florence-2-SD3-Captioner" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "gokaygokay/Florence-2-SD3-Captioner",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'How to use gokaygokay/Florence-2-SD3-Captioner with Docker Model Runner:
docker model run hf.co/gokaygokay/Florence-2-SD3-Captioner
pip install -q datasets flash_attn timm einops
from transformers import AutoModelForCausalLM, AutoProcessor, AutoConfig
import torch
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = AutoModelForCausalLM.from_pretrained("gokaygokay/Florence-2-SD3-Captioner", trust_remote_code=True).to(device).eval()
processor = AutoProcessor.from_pretrained("gokaygokay/Florence-2-SD3-Captioner", trust_remote_code=True)
# Function to run the model on an example
def run_example(task_prompt, text_input, image):
prompt = task_prompt + text_input
# Ensure the image is in RGB mode
if image.mode != "RGB":
image = image.convert("RGB")
inputs = processor(text=prompt, images=image, return_tensors="pt").to(device)
generated_ids = model.generate(
input_ids=inputs["input_ids"],
pixel_values=inputs["pixel_values"],
max_new_tokens=1024,
num_beams=3
)
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=False)[0]
parsed_answer = processor.post_process_generation(generated_text, task=task_prompt, image_size=(image.width, image.height))
return parsed_answer
from PIL import Image
import requests
import copy
url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/car.jpg?download=true"
image = Image.open(requests.get(url, stream=True).raw)
answer = run_example("<DESCRIPTION>", "Describe this image in great detail.", image)
final_answer = answer['<DESCRIPTION>']
print(final_answer)
# 'Captured at eye-level on a sunny day, a light blue Volkswagen Beetle is parked on a cobblestone street. The beetle is parked in front of a yellow building with two brown doors. The door on the right side of the frame is white, while the left side is a darker shade of blue. The car is facing the camera, and the car is positioned in the middle of the street.'
This model release is maintained by GΓΆkay AydoΔan. If you reference this repository in academic work, please cite it as follows and also cite the upstream models, datasets, or projects it builds upon.
@software{aydogan2024florence_2_sd3_captioner,
author = {AydoΔan, GΓΆkay},
title = {{Florence-2-SD3-Captioner}},
year = {2024},
publisher = {Hugging Face},
url = {https://huggingface.co/gokaygokay/Florence-2-SD3-Captioner},
note = {Model repository; cite the base model and upstream datasets as required.}
}