Instructions to use openai-community/gpt2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use openai-community/gpt2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="openai-community/gpt2")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("openai-community/gpt2") model = AutoModelForCausalLM.from_pretrained("openai-community/gpt2") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use openai-community/gpt2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "openai-community/gpt2" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "openai-community/gpt2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/openai-community/gpt2
- SGLang
How to use openai-community/gpt2 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 "openai-community/gpt2" \ --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": "openai-community/gpt2", "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 "openai-community/gpt2" \ --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": "openai-community/gpt2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use openai-community/gpt2 with Docker Model Runner:
docker model run hf.co/openai-community/gpt2
test
Hello
#!/bin/bash
set -e
AI_DIR="$HOME/ai_system"
VENV_DIR="$AI_DIR/venv"
sudo apt-get update
sudo apt-get install -y python3 python3-venv python3-pip git build-essential
mkdir -p "$AI_DIR"
cd "$AI_DIR"
python3 -m venv "$VENV_DIR"
. "$VENV_DIR/bin/activate"
pip install --upgrade pip setuptools wheel
pip install transformers gradio langchain torch torchvision
cat > run_ui.py <<EOF
import gradio as gr
from transformers import pipeline
generator = pipeline("text-generation", model="gpt2")
def chat(prompt):
return generator(prompt, max_length=200)[0]['generated_text']
gr.Interface(fn=chat, inputs="text", outputs="text").launch(server_name="0.0.0.0", server_port=7860)
EOF
echo "✅ تم تثبيت النظام! شغّل الواجهة:"
echo "source $VENV_DIR/bin/activate && python $AI_DIR/run_ui.py"
// routes/auth.js
const express = require('express');
const bcrypt = require('bcryptjs');
const jwt = require('jsonwebtoken');
const User = require('../models/User');
require('dotenv').config();
const router = express.Router();
/* تسجيل مستخدم جديد */
router.post('/register', async (req, res) => {
const { email, password, name } = req.body;
if (!email || !password) return res.status(400).json({msg:'بيانات غير مكتملة'});
try {
const existing = await User.findOne({email});
if (existing) return res.status(409).json({msg:'المستخدم موجود مسبقًا'});
const hash = await bcrypt.hash(password, 12);
const user = await