Text Generation
Transformers
PyTorch
TensorFlow
JAX
Rust
ONNX
Safetensors
English
gpt2
text-generation-inference
Instructions to use openai-community/gpt2-medium with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use openai-community/gpt2-medium with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="openai-community/gpt2-medium")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("openai-community/gpt2-medium") model = AutoModelForCausalLM.from_pretrained("openai-community/gpt2-medium") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use openai-community/gpt2-medium with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "openai-community/gpt2-medium" # 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-medium", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/openai-community/gpt2-medium
- SGLang
How to use openai-community/gpt2-medium 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-medium" \ --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-medium", "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-medium" \ --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-medium", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use openai-community/gpt2-medium with Docker Model Runner:
docker model run hf.co/openai-community/gpt2-medium
Update README.md
#19
by JessJessLDU - opened
README.md
CHANGED
|
@@ -197,4 +197,39 @@ See the [associated paper](https://d4mucfpksywv.cloudfront.net/better-language-m
|
|
| 197 |
|
| 198 |
## Model Card Authors
|
| 199 |
|
| 200 |
-
This model card was written by the Hugging Face team.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
|
| 198 |
## Model Card Authors
|
| 199 |
|
| 200 |
+
This model card was written by the Hugging Face team.
|
| 201 |
+
|
| 202 |
+
@app.post("/chat")
|
| 203 |
+
def chat(data: dict):
|
| 204 |
+
mensaje = data.get("mensaje", "").lower()
|
| 205 |
+
|
| 206 |
+
# Simulación de datos (puedes conectar tu DB aquí)
|
| 207 |
+
sample_clientes = [
|
| 208 |
+
{"ingresos": 800, "deuda": 6000},
|
| 209 |
+
{"ingresos": 3000, "deuda": 1000},
|
| 210 |
+
{"ingresos": 1200, "deuda": 4000}
|
| 211 |
+
]
|
| 212 |
+
|
| 213 |
+
df = pd.DataFrame(sample_clientes)
|
| 214 |
+
preds = model.predict(df)
|
| 215 |
+
|
| 216 |
+
respuesta = ""
|
| 217 |
+
|
| 218 |
+
if "malos" in mensaje:
|
| 219 |
+
respuesta += "Clientes de alto riesgo:\n"
|
| 220 |
+
for i in range(len(df)):
|
| 221 |
+
if preds[i] == 1:
|
| 222 |
+
shap_values = explainer(df.iloc[[i]])
|
| 223 |
+
razones = explicar(df.iloc[[i]], shap_values)
|
| 224 |
+
respuesta += f"Cliente {i}: deuda alta, ingresos bajos\n"
|
| 225 |
+
|
| 226 |
+
elif "buenos" in mensaje:
|
| 227 |
+
respuesta += "Clientes confiables:\n"
|
| 228 |
+
for i in range(len(df)):
|
| 229 |
+
if preds[i] == 0:
|
| 230 |
+
respuesta += f"Cliente {i}: buen perfil crediticio\n"
|
| 231 |
+
|
| 232 |
+
else:
|
| 233 |
+
respuesta = "Puedes preguntarme: clientes malos, clientes buenos"
|
| 234 |
+
|
| 235 |
+
return {"respuesta": respuesta}
|