AnyaSchen/image2poetry_ru
Viewer • Updated • 7.76k • 26
How to use AnyaSchen/vit-rugpt3-medium-pushkin with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("image-text-to-text", model="AnyaSchen/vit-rugpt3-medium-pushkin") # Load model directly
from transformers import AutoTokenizer, AutoModelForImageTextToText
tokenizer = AutoTokenizer.from_pretrained("AnyaSchen/vit-rugpt3-medium-pushkin")
model = AutoModelForImageTextToText.from_pretrained("AnyaSchen/vit-rugpt3-medium-pushkin")How to use AnyaSchen/vit-rugpt3-medium-pushkin with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "AnyaSchen/vit-rugpt3-medium-pushkin"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "AnyaSchen/vit-rugpt3-medium-pushkin",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'docker model run hf.co/AnyaSchen/vit-rugpt3-medium-pushkin
How to use AnyaSchen/vit-rugpt3-medium-pushkin with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "AnyaSchen/vit-rugpt3-medium-pushkin" \
--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": "AnyaSchen/vit-rugpt3-medium-pushkin",
"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 "AnyaSchen/vit-rugpt3-medium-pushkin" \
--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": "AnyaSchen/vit-rugpt3-medium-pushkin",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'How to use AnyaSchen/vit-rugpt3-medium-pushkin with Docker Model Runner:
docker model run hf.co/AnyaSchen/vit-rugpt3-medium-pushkin
This repo contains model for generation poetry from image in style of Pushkin.The model is fune-tuned concatecation of two pre-trained models: google/vit-base-patch16-224 as encoder and AnyaSchen/rugpt3_pushkin as decoder.
To use this model you can do:
from PIL import Image
import requests
from transformers import AutoTokenizer, VisionEncoderDecoderModel, ViTImageProcessor
def generate_poetry(fine_tuned_model, image, tokenizer):
pixel_values = feature_extractor(images=image, return_tensors="pt").pixel_values
pixel_values = pixel_values.to(device)
# Generate the poetry with the fine-tuned VisionEncoderDecoder model
generated_tokens = fine_tuned_model.generate(
pixel_values,
max_length=300,
num_beams=3,
top_p=0.8,
temperature=2.0,
do_sample=True,
pad_token_id=tokenizer.pad_token_id,
eos_token_id=tokenizer.eos_token_id,
)
# Decode the generated tokens
generated_poetry = tokenizer.decode(generated_tokens[0], skip_special_tokens=True)
return generated_poetry
path = 'AnyaSchen/vit-rugpt3-medium-pushkin'
fine_tuned_model = VisionEncoderDecoderModel.from_pretrained(path).to(device)
feature_extractor = ViTImageProcessor.from_pretrained(path)
tokenizer = AutoTokenizer.from_pretrained(path)
url = 'https://anandaindia.org/wp-content/uploads/2018/12/happy-man.jpg'
image = Image.open(requests.get(url, stream=True).raw)
generated_poetry = generate_poetry(fine_tuned_model, image, tokenizer)
print(generated_poetry)