jevol-2b / app.py
multimodalart's picture
multimodalart HF Staff
Upload app.py with huggingface_hub
98f9786 verified
Raw History Blame Contribute Delete
6.98 kB
"""Jevol-2B — vision-language-action drone policy demo.
Give the model one camera image and a mission in English; it answers three
multiple-choice questions in a single forward pass (where to fly, whether to
change altitude, whether to slide sideways) and decodes them into one flight
command. Jevol, Racine.ai, 2026.
"""
import spaces # ZeroGPU: must be imported before torch
import time
from pathlib import Path
import gradio as gr
from huggingface_hub import snapshot_download
from PIL import Image
from jevol import Policy, actions
APP_DIR = Path(__file__).resolve().parent
CHECKPOINT_FILES = (
"config.json",
"model.safetensors",
"sentence_head.safetensors",
"jevol_config.json",
"processor_config.json",
"tokenizer.json",
)
TOP_K = 3
print("Downloading the Jevol-2B checkpoint…", flush=True)
CHECKPOINT = snapshot_download("racineai/Jevol-2B", allow_patterns=list(CHECKPOINT_FILES))
print(f"Checkpoint ready at {CHECKPOINT}", flush=True)
print("Loading Jevol-2B…", flush=True)
policy = Policy(CHECKPOINT, backend="cuda", kernel="torch", graphs=False)
print(f"Jevol-2B loaded: {policy.info()}", flush=True)
@spaces.GPU(duration=10)
def decide(image: Image.Image, mission: str) -> tuple[str, dict]:
"""Decide the drone's next flight command from one camera image and a mission.
The 2.2B vision-language-action policy looks at the image, reads the
mission, and answers three multiple-choice questions in one forward pass
(move: 20 options, altitude: 5, sideways: 3).
Args:
image: The current drone camera image. Any size — it is resized to the
672x504 training resolution and JPEG-compressed exactly like on the drone.
mission: The mission, one short sentence in English,
e.g. "Go to the red car and stop."
Returns:
A human-readable decision summary and the structured flight command:
forward speed (m/s), yaw rate (rad/s), climb rate (m/s), sideways
speed (m/s), plus the top answer options with their probabilities.
"""
if image is None:
raise gr.Error("Give the drone a camera image: upload one or pick an example below.")
mission = (mission or "").strip()
if not mission:
raise gr.Error("Write the mission in English first, e.g. 'Go to the red car and stop.'")
t0 = time.perf_counter()
result = policy.act([image], [mission])[0]
elapsed = time.perf_counter() - t0
top = result["top"]
bits = " · ".join(f"**{top[q][0]}** ({top[q][1]:.0%})" for q in ("move", "altitude", "side") if q in top)
summary = (
f"Next move: {bits}\n\n"
f"forward **{result['forward']:+.2f} m/s** · yaw **{result['yaw']:+.2f} rad/s** · "
f"climb **{result['up']:+.2f} m/s** · sideways **{result['right']:+.0f} m/s** — "
f"one forward pass in {elapsed:.2f} s"
)
def top_k(question: str, k: int = TOP_K) -> list[list]:
names = actions.OPTION_NAMES[question]
probs = result["probs"][question]
order = sorted(range(len(probs)), key=lambda i: -probs[i])[:k]
return [[names[i], probs[i]] for i in order]
command = {
"mission": mission,
"command": {
"forward_m_s": round(result["forward"], 3),
"yaw_rad_s": round(result["yaw"], 4),
"up_m_s": result["up"],
"sideways_m_s": result["right"],
},
"top_options": {q: top_k(q) for q in ("move", "altitude", "side") if q in result["probs"]},
"probabilities": result["probs"],
"latency_s": round(elapsed, 3),
}
print(
f"[decide] {mission!r} -> forward={result['forward']:+.2f} yaw={result['yaw']:+.3f} "
f"up={result['up']:+.2f} right={result['right']:+.0f} in {elapsed:.2f}s",
flush=True,
)
return summary, command
CSS = """
#col-container { max-width: 1100px; margin: 0 auto; }
.dark .gradio-container { color: var(--body-text-color); }
"""
EXAMPLES = [
[str(APP_DIR / "assets" / "street.jpg"), "Go to the red car and stop."],
[str(APP_DIR / "assets" / "street.jpg"), "Follow the street between the houses."],
[str(APP_DIR / "assets" / "container.jpg"), "Go to the blue container"],
[str(APP_DIR / "assets" / "arch.jpg"), "Fly through the next arch."],
[str(APP_DIR / "assets" / "refuse.jpg"), "Crash into the white van."],
]
with gr.Blocks(title="Jevol-2B drone policy") as demo:
with gr.Column(elem_id="col-container"):
gr.Markdown(
"""
# 🛸 Jevol-2B — vision-language-action drone policy
Show the current camera image, write the mission in English, and this 2.2B-parameter policy
answers three multiple-choice questions in **one forward pass**: where to fly next, whether to
change altitude, and whether to slide sideways. The answers decode into a single flight command.
"""
)
with gr.Row():
with gr.Column():
image = gr.Image(type="pil", sources=["upload", "clipboard"], label="Drone camera image", height=340)
mission = gr.Textbox(
label="Mission (one short sentence in English)",
placeholder="Go to the red car and stop.",
lines=2,
)
decide_btn = gr.Button("Decide", variant="primary")
with gr.Column():
summary = gr.Markdown("*The decision will appear here.*")
command = gr.JSON(label="Flight command")
gr.Examples(
examples=EXAMPLES,
inputs=[image, mission],
fn=decide,
outputs=[summary, command],
cache_examples=True,
cache_mode="lazy",
label="Examples — the model's own showcase missions (the last one is a dangerous order the drone should refuse)",
)
gr.Markdown(
"""
---
**Model**: [racineai/Jevol-2B](https://huggingface.co/racineai/Jevol-2B) — 2.2B parameters (fp16 here),
~0.17 s per decision on an L40S · code: [github.com/RacineAIOS/jevol](https://github.com/RacineAIOS/jevol) (vendored in `jevol/`)
· **Citation**: Jevol, Racine.ai, 2026.
**Licence**: [Racine Research License v1.0](LICENSE.jevol.md) — research, evaluation and prototypes are free;
operational or commercial use needs a licence from [Racine.ai](https://racine.ai/contact). Derived from
[Qwen/Qwen3.5-2B](https://huggingface.co/Qwen/Qwen3.5-2B) (Apache-2.0, see [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md)).
**Safety**: this Space evaluates a research model on static camera images. Never connect it to a real aircraft.
"""
)
decide_btn.click(
decide,
inputs=[image, mission],
outputs=[summary, command],
api_name="decide",
concurrency_limit=1,
)
demo.launch(theme=gr.themes.Citrus(), css=CSS, mcp_server=True)