HuggingFaceH4/ultrachat_200k
Viewer • Updated • 515k • 89.4k • 1.21k
How to use procesaur/Orao2 with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="procesaur/Orao2")
messages = [
{
"role": "user",
"content": [
{"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"},
{"type": "text", "text": "What animal is on the candy?"}
]
},
]
pipe(text=messages) # pip install -U transformers accelerate
# Load model directly
from transformers import AutoProcessor, AutoModelForMultimodalLM
processor = AutoProcessor.from_pretrained("procesaur/Orao2")
model = AutoModelForMultimodalLM.from_pretrained("procesaur/Orao2", device_map="auto")
messages = [
{
"role": "user",
"content": [
{"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"},
{"type": "text", "text": "What animal is on the candy?"}
]
},
]
inputs = processor.apply_chat_template(
messages,
add_generation_prompt=True,
tokenize=True,
return_dict=True,
return_tensors="pt",
).to(model.device)
outputs = model.generate(**inputs, max_new_tokens=256)
print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:]))How to use procesaur/Orao2 with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "procesaur/Orao2"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "procesaur/Orao2",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker model run hf.co/procesaur/Orao2
How to use procesaur/Orao2 with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "procesaur/Orao2" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "procesaur/Orao2",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'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 "procesaur/Orao2" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "procesaur/Orao2",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'How to use procesaur/Orao2 with Docker Model Runner:
docker model run hf.co/procesaur/Orao2
# pip install -U transformers accelerate
# Load model directly
from transformers import AutoProcessor, AutoModelForMultimodalLM
processor = AutoProcessor.from_pretrained("procesaur/Orao2")
model = AutoModelForMultimodalLM.from_pretrained("procesaur/Orao2", device_map="auto")
messages = [
{
"role": "user",
"content": [
{"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"},
{"type": "text", "text": "What animal is on the candy?"}
]
},
]
inputs = processor.apply_chat_template(
messages,
add_generation_prompt=True,
tokenize=True,
return_dict=True,
return_tensors="pt",
).to(model.device)
outputs = model.generate(**inputs, max_new_tokens=256)
print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:]))from transformers import AutoTokenizer, AutoModelForCausalLM
model_id = "procesaur/Orao2"
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto")
def chat(messages, thinking=true):
inputs = tokenizer.apply_chat_template(
messages,
add_generation_prompt=True,
enable_thinking=thinking,
tokenize=True,
return_dict=True,
return_tensors="pt",
).to(model.device)
outputs = model.generate(**inputs, max_new_tokens=512)
decoded = tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])
print(decoded.split("</think>")[-1].split("<|im_end|>")[0])
messages = [
{"role": "system", "content": "Ти си АИ асистент који одговара на природном српском језику, у скаладу са српском културном традицијом."},
{"role": "user", "content": "Ког датума славимо Никољдан?"},
]
chat(messages)
Никољдан се слави 19. децембра.
messages = [
{"role": "system", "content": "Ти си АИ асистент који одговара на природном српском језику, у скаладу са српском културном традицијом."},
{"role": "user", "content": "Ког датума славимо Никољдан? Одговори на латиници."},
]
chat(messages)
19. decembar.
prompt = (
"Нацртај сцену према следећем опису на српском језику тако што ћеш вратити само валидан "
"<svg viewBox=\"0 0 1024 512\" width=\"1024\" height=\"512\" xmlns=\"http://www.w3.org/2000/svg\"> "
"елемент без додатног текста или markdown блокова:\n"
"Опис: Застава Републике Србије, у три боје, према званично дефинисаним RGB ознакама. У свакој траци пише име планине у три различита, смешна фонта, различитих величина. Слова имају разнобојни аутлајн."
)
messages = [
{"role": "system", "content": "Ti si AI asistent koji pomaže u pisanju koda. Analiziraj zahtev jedan po jedan i napiši kod koji odgovara svim elementima zahteva."},
{"role": "user", "content": prompt},
]
chat(messages, thinking=True)
messages = [
{"role": "system", "content": "Ti si AI asistent koji pomaže u pisanju koda. Analiziraj zahtev jedan po jedan i napiši kod koji odgovara svim elementima zahteva."},
{"role": "user", "content": "Napiši mi Pajton funkciju koja očitava word (docx) fajl izvlači iz njega tekst, preslovljava ga u latinicu iz ćirilice i čuva kao txt"},
]
chat(messages, thinking=False)
import os
from docx import Document
from unidecode import unidecode
def read_docx_to_txt(input_file_path, output_file_path):
if not os.path.exists(input_file_path):
raise FileNotFoundError(f"File not found: {input_file_path}")
doc = Document(input_file_path)
text = ""
for paragraph in doc.paragraphs:
text += paragraph.text + "\n"
latin_text = unidecode(text)
with open(output_file_path, "w", encoding="utf-8") as output_file:
output_file.write(latin_text)
print(f"Text saved to {output_file_path}")
Primer korišćenja:
read_docx_to_txt("example.docx", "output.txt")
Objašnjenje:
os.path.exists() proverava da li fajl postoji pre čitanja.Document() čita DOCX fajl i vraća objekat dokumenta.paragraph.text izvlači tekst iz svakog paragrafa i dodaje ga u string.unidecode() preslovljava tekst iz ćirilice u latinicu.open() otvara fajl za pisanje sa UTF-8 enkodiranjem.write() zapisuje latinizirani tekst u fajl.print() obaveštava korisnika o uspehu operacije.
--- OCR ---
РУЂЕР JOSIF BOŠKOVIĆ
1711—1787
I
Nezavisna dubrovačka republika bila je u zgodnim i srećim okolnostima za slobodno razvijanje i napredovanje, te pored Dubrovnika, kao najvažnijeg trgovačkog grada u primorju, beše više centara ne samo trgovačkih nego i književnih iz kojih ponike čitav niz znatnih i velikih radnika. Naslojeni s jedne strane na kulturnog suseda, a s druge dosta izolovani od varvarskih gospodara, kojima ostale srpske zemlje behu izložene, oni su se i mogli uzdići do onoga savršenstva i prefinjenosti u literaturi,
Base model
procesaur/Orao2-GPT
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="procesaur/Orao2") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)