Instructions to use team-indain-image-caption/hindi-image-captioning with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use team-indain-image-caption/hindi-image-captioning with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="team-indain-image-caption/hindi-image-captioning")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForMultimodalLM tokenizer = AutoTokenizer.from_pretrained("team-indain-image-caption/hindi-image-captioning") model = AutoModelForMultimodalLM.from_pretrained("team-indain-image-caption/hindi-image-captioning", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use team-indain-image-caption/hindi-image-captioning with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "team-indain-image-caption/hindi-image-captioning" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "team-indain-image-caption/hindi-image-captioning", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/team-indain-image-caption/hindi-image-captioning
- SGLang
How to use team-indain-image-caption/hindi-image-captioning with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "team-indain-image-caption/hindi-image-captioning" \ --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": "team-indain-image-caption/hindi-image-captioning", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
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 "team-indain-image-caption/hindi-image-captioning" \ --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": "team-indain-image-caption/hindi-image-captioning", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use team-indain-image-caption/hindi-image-captioning with Docker Model Runner:
docker model run hf.co/team-indain-image-caption/hindi-image-captioning
delete app.py
Browse files
app.py
DELETED
|
@@ -1,55 +0,0 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
import re
|
| 3 |
-
import gradio as gr
|
| 4 |
-
from pathlib import Path
|
| 5 |
-
from transformers import AutoTokenizer, AutoFeatureExtractor, VisionEncoderDecoderModel
|
| 6 |
-
# Pattern to ignore all the text after 2 or more full stops
|
| 7 |
-
regex_pattern = "[.]{2,}"
|
| 8 |
-
def post_process(text):
|
| 9 |
-
try:
|
| 10 |
-
text = text.strip()
|
| 11 |
-
text = re.split(regex_pattern, text)[0]
|
| 12 |
-
except Exception as e:
|
| 13 |
-
print(e)
|
| 14 |
-
pass
|
| 15 |
-
return text
|
| 16 |
-
def predict(image, max_length=64, num_beams=4):
|
| 17 |
-
pixel_values = feature_extractor(images=image, return_tensors="pt").pixel_values
|
| 18 |
-
pixel_values = pixel_values.to(device)
|
| 19 |
-
with torch.no_grad():
|
| 20 |
-
output_ids = model.generate(
|
| 21 |
-
pixel_values,
|
| 22 |
-
max_length=max_length,
|
| 23 |
-
num_beams=num_beams,
|
| 24 |
-
return_dict_in_generate=True,
|
| 25 |
-
).sequences
|
| 26 |
-
preds = tokenizer.batch_decode(output_ids, skip_special_tokens=True)
|
| 27 |
-
pred = post_process(preds[0])
|
| 28 |
-
return pred
|
| 29 |
-
model_name_or_path = "deepklarity/poster2plot"
|
| 30 |
-
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
| 31 |
-
# Load model.
|
| 32 |
-
model = VisionEncoderDecoderModel.from_pretrained(model_name_or_path)
|
| 33 |
-
model.to(device)
|
| 34 |
-
print("Loaded model")
|
| 35 |
-
feature_extractor = AutoFeatureExtractor.from_pretrained(model.encoder.name_or_path)
|
| 36 |
-
print("Loaded feature_extractor")
|
| 37 |
-
tokenizer = AutoTokenizer.from_pretrained(model.decoder.name_or_path, use_fast=True)
|
| 38 |
-
if model.decoder.name_or_path == "gpt2":
|
| 39 |
-
tokenizer.pad_token = tokenizer.eos_token
|
| 40 |
-
print("Loaded tokenizer")
|
| 41 |
-
title = "Poster2Plot: Upload a Movie/T.V show poster to generate a plot"
|
| 42 |
-
description = ""
|
| 43 |
-
input = gr.inputs.Image(type="pil")
|
| 44 |
-
example_images = sorted([f.as_posix() for f in Path("examples").glob("*.jpg")])
|
| 45 |
-
print(f"Loaded {len(example_images)} example images")
|
| 46 |
-
interface = gr.Interface(
|
| 47 |
-
fn=predict,
|
| 48 |
-
inputs=input,
|
| 49 |
-
outputs="textbox",
|
| 50 |
-
title=title,
|
| 51 |
-
description=description,
|
| 52 |
-
examples=example_images,
|
| 53 |
-
live=True,
|
| 54 |
-
)
|
| 55 |
-
interface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|