Spaces:
Running on Zero
Running on Zero
| set -euo pipefail | |
| : "${SPACE_URL:?Set SPACE_URL, e.g. https://your-space.hf.space}" | |
| HF_TOKEN="${HF_TOKEN:-}" | |
| PROMPT="${1:-Write a short haiku about GPUs.}" | |
| MODEL="${MODEL:-unsloth/diffusiongemma-26B-A4B-it-GGUF:Q4_K_M}" | |
| MAX_TOKENS="${MAX_TOKENS:-256}" | |
| AUTH_ARGS=() | |
| if [[ -n "${HF_TOKEN}" ]]; then | |
| AUTH_ARGS=(-H "Authorization: Bearer ${HF_TOKEN}") | |
| fi | |
| PAYLOAD=$(python - "$MODEL" "$PROMPT" "$MAX_TOKENS" <<'PY' | |
| import json, sys | |
| model, prompt, max_tokens = sys.argv[1], sys.argv[2], int(sys.argv[3]) | |
| print(json.dumps({ | |
| "data": [{ | |
| "model": model, | |
| "messages": [{"role": "user", "content": prompt}], | |
| "max_tokens": max_tokens, | |
| }] | |
| }, ensure_ascii=False)) | |
| PY | |
| ) | |
| EVENT_ID=$(curl -sS -X POST "${SPACE_URL%/}/gradio_api/call/chat" \ | |
| -H "Content-Type: application/json" \ | |
| "${AUTH_ARGS[@]}" \ | |
| -d "$PAYLOAD" | python -c 'import json,sys; print(json.load(sys.stdin)["event_id"])') | |
| echo "event_id=${EVENT_ID}" >&2 | |
| curl -N "${SPACE_URL%/}/gradio_api/call/chat/${EVENT_ID}" "${AUTH_ARGS[@]}" | |