Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- README.md +10 -0
- app.py +23 -3
- requirements.txt +2 -0
README.md
CHANGED
|
@@ -26,6 +26,16 @@ O `agents.md` é **gerado automaticamente** pela HF para todo Gradio Space. Agen
|
|
| 26 |
|
| 27 |
Endpoint útil neste app: **`ask`** (`prompt` → `answer`).
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
## Secrets (Settings → Variables and secrets)
|
| 30 |
|
| 31 |
| Name | Valor |
|
|
|
|
| 26 |
|
| 27 |
Endpoint útil neste app: **`ask`** (`prompt` → `answer`).
|
| 28 |
|
| 29 |
+
## Hardware
|
| 30 |
+
|
| 31 |
+
Este Space **não carrega o modelo 30B**. Só faz HTTP para a Inference API.
|
| 32 |
+
|
| 33 |
+
- Preferido: **CPU Basic**
|
| 34 |
+
- Se estiver em **ZeroGPU**, o `app.py` inclui `@spaces.GPU` para o runtime não falhar com
|
| 35 |
+
`No @spaces.GPU function detected during startup`
|
| 36 |
+
|
| 37 |
+
Em **Settings → Settings → Hardware**, troque ZeroGPU → CPU se puder.
|
| 38 |
+
|
| 39 |
## Secrets (Settings → Variables and secrets)
|
| 40 |
|
| 41 |
| Name | Valor |
|
app.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
-
"""CoderInstruc Gradio Space — UI + agent
|
| 2 |
|
| 3 |
from __future__ import annotations
|
| 4 |
|
| 5 |
import os
|
| 6 |
-
from typing import Any
|
| 7 |
|
| 8 |
import gradio as gr
|
| 9 |
import httpx
|
|
@@ -16,6 +16,22 @@ SYSTEM_PROMPT = (
|
|
| 16 |
"to edit files or run tests. Refuse requests for malware or secret exfiltration."
|
| 17 |
)
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
def _settings() -> dict[str, str]:
|
| 21 |
token = os.getenv("HF_TOKEN") or os.getenv("CODERINSTRUC_HF_TOKEN") or ""
|
|
@@ -37,6 +53,7 @@ def _is_unsafe(text: str) -> bool:
|
|
| 37 |
return any(b in lowered for b in blocked)
|
| 38 |
|
| 39 |
|
|
|
|
| 40 |
def complete(message: str, history: list[dict[str, str]] | None = None) -> str:
|
| 41 |
"""Core completion used by UI and agent API."""
|
| 42 |
cfg = _settings()
|
|
@@ -83,7 +100,7 @@ def complete(message: str, history: list[dict[str, str]] | None = None) -> str:
|
|
| 83 |
|
| 84 |
|
| 85 |
def ask(prompt: str) -> str:
|
| 86 |
-
"""Stateless agent endpoint —
|
| 87 |
return complete(prompt, history=None)
|
| 88 |
|
| 89 |
|
|
@@ -98,6 +115,9 @@ Assistente de código (base Qwen3-Coder → post-train CoderInstruc).
|
|
| 98 |
**Modelo:** `{cfg["model"]}` · Inferência remota (pesos fora deste Space)
|
| 99 |
|
| 100 |
**Agents:** `curl https://huggingface.co/spaces/amarorn/CoderInstruc/agents.md`
|
|
|
|
|
|
|
|
|
|
| 101 |
"""
|
| 102 |
)
|
| 103 |
with gr.Tab("Chat"):
|
|
|
|
| 1 |
+
"""CoderInstruc Gradio Space — UI + agent API (remote HF inference, no local model)."""
|
| 2 |
|
| 3 |
from __future__ import annotations
|
| 4 |
|
| 5 |
import os
|
| 6 |
+
from typing import Any, Callable, TypeVar
|
| 7 |
|
| 8 |
import gradio as gr
|
| 9 |
import httpx
|
|
|
|
| 16 |
"to edit files or run tests. Refuse requests for malware or secret exfiltration."
|
| 17 |
)
|
| 18 |
|
| 19 |
+
F = TypeVar("F", bound=Callable[..., Any])
|
| 20 |
+
|
| 21 |
+
# ZeroGPU Spaces require at least one @spaces.GPU function at startup.
|
| 22 |
+
# We only do remote HTTP inference — decorate anyway so ZeroGPU hardware boots.
|
| 23 |
+
try:
|
| 24 |
+
import spaces # type: ignore
|
| 25 |
+
except ImportError: # local / CPU Space
|
| 26 |
+
spaces = None
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def gpu_if_zerogpu(fn: F) -> F:
|
| 30 |
+
if spaces is None:
|
| 31 |
+
return fn
|
| 32 |
+
# Short duration: function only waits on Inference API, no local CUDA kernels
|
| 33 |
+
return spaces.GPU(duration=120)(fn) # type: ignore[return-value]
|
| 34 |
+
|
| 35 |
|
| 36 |
def _settings() -> dict[str, str]:
|
| 37 |
token = os.getenv("HF_TOKEN") or os.getenv("CODERINSTRUC_HF_TOKEN") or ""
|
|
|
|
| 53 |
return any(b in lowered for b in blocked)
|
| 54 |
|
| 55 |
|
| 56 |
+
@gpu_if_zerogpu
|
| 57 |
def complete(message: str, history: list[dict[str, str]] | None = None) -> str:
|
| 58 |
"""Core completion used by UI and agent API."""
|
| 59 |
cfg = _settings()
|
|
|
|
| 100 |
|
| 101 |
|
| 102 |
def ask(prompt: str) -> str:
|
| 103 |
+
"""Stateless agent endpoint — api_name='ask' for /agents.md clients."""
|
| 104 |
return complete(prompt, history=None)
|
| 105 |
|
| 106 |
|
|
|
|
| 115 |
**Modelo:** `{cfg["model"]}` · Inferência remota (pesos fora deste Space)
|
| 116 |
|
| 117 |
**Agents:** `curl https://huggingface.co/spaces/amarorn/CoderInstruc/agents.md`
|
| 118 |
+
|
| 119 |
+
> Preferência de hardware: **CPU Basic** (não precisa ZeroGPU). Se estiver em ZeroGPU, o app
|
| 120 |
+
> usa `@spaces.GPU` só para satisfazer o runtime — a carga real é a Inference API.
|
| 121 |
"""
|
| 122 |
)
|
| 123 |
with gr.Tab("Chat"):
|
requirements.txt
CHANGED
|
@@ -1,3 +1,5 @@
|
|
| 1 |
gradio>=5.23.0,<7
|
| 2 |
httpx>=0.28.0
|
| 3 |
python-dotenv>=1.0.0
|
|
|
|
|
|
|
|
|
| 1 |
gradio>=5.23.0,<7
|
| 2 |
httpx>=0.28.0
|
| 3 |
python-dotenv>=1.0.0
|
| 4 |
+
# Present on ZeroGPU Spaces; optional locally
|
| 5 |
+
spaces>=0.30.0
|