app = FastAPI(title="FG‑Arabic Generation API")
model_path = "fg-selective-arabic.bin" tokenizer = AutoTokenizer.from_pretrained("fg-consortium/fg-selective-arabic", trust_remote_code=True) Fg-selective-arabic.bin
# Example usage prompt = "اكتب مقالًا قصيرًا عن تأثير الذكاء الاصطناعي على التعليم في العالم العربي" print(generate_arabic(prompt)) from fastapi import FastAPI, Request from pydantic import BaseModel AutoTokenizer import torch
@app.post("/generate") async def generate(req: GenerationRequest): text = generate_arabic( req.prompt, max_new_tokens=req.max_new_tokens, temperature=req.temperature, top_p=req.top_p ) return "generated_text": text Run with: Fg-selective-arabic.bin
# 2️⃣ Install core dependencies pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu124 pip install transformers==4.44.0 sentencepiece tqdm accelerate # Replace <TOKEN> with the access token you received after agreeing to the license wget -O fg-selective-arabic.bin "https://huggingface.co/fg-consortium/fg-selective-arabic/resolve/main/fg-selective-arabic.bin?download=true&token=<TOKEN>" Tip: The file is ~6 GB compressed ( .bin.gz ). Use pigz -d for faster decompression on multi‑core CPUs. 5.3 Loading the Model from transformers import AutoModelForCausalLM, AutoTokenizer import torch