Spaces:
Running on Zero
Running on Zero
John Ho commited on
Commit Β·
edca60d
1
Parent(s): c9780e6
added support for moondream2 as well
Browse files
app.py
CHANGED
|
@@ -27,9 +27,15 @@ def load_model():
|
|
| 27 |
return moondream
|
| 28 |
|
| 29 |
|
| 30 |
-
|
| 31 |
-
load_model()
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
|
| 35 |
@spaces.GPU(duration=30)
|
|
@@ -37,6 +43,7 @@ def detect(
|
|
| 37 |
im: Image.Image,
|
| 38 |
object_name: str,
|
| 39 |
mode: Literal["point", "object_detection", "query"],
|
|
|
|
| 40 |
reasoning: bool = False,
|
| 41 |
settings: dict = {"temperature": 0.0, "top_p": 0.95, "max_tokens": 512},
|
| 42 |
):
|
|
@@ -51,7 +58,8 @@ def detect(
|
|
| 51 |
For "point" / "object_detection": a list of points (xy) or bounding boxes (xyxy) with normalized coordinates.
|
| 52 |
For "query": a dict {"answer": str} with the answer to the question.
|
| 53 |
"""
|
| 54 |
-
model = _MODEL # load_model()
|
|
|
|
| 55 |
if isinstance(settings, str):
|
| 56 |
settings = json.loads(settings)
|
| 57 |
if mode == "point":
|
|
@@ -73,6 +81,7 @@ demo = gr.Interface(
|
|
| 73 |
info="object to detector (for points / object_detection) or question for a query",
|
| 74 |
),
|
| 75 |
gr.Dropdown(label="Mode", choices=["point", "object_detection", "query"]),
|
|
|
|
| 76 |
gr.Checkbox(
|
| 77 |
label="Reasoning",
|
| 78 |
value=False,
|
|
|
|
| 27 |
return moondream
|
| 28 |
|
| 29 |
|
| 30 |
+
_MODEL_ZOO = {
|
| 31 |
+
"moondream3-preview": load_model(), # calling spaces.GPU decorated functions outside ZeroGPU scope will cause a PickingError
|
| 32 |
+
"moondream2": AutoModelForCausalLM.from_pretrained(
|
| 33 |
+
"vikhyatk/moondream2",
|
| 34 |
+
revision="2025-04-14",
|
| 35 |
+
trust_remote_code=True,
|
| 36 |
+
device_map={"": "cuda"},
|
| 37 |
+
),
|
| 38 |
+
}
|
| 39 |
|
| 40 |
|
| 41 |
@spaces.GPU(duration=30)
|
|
|
|
| 43 |
im: Image.Image,
|
| 44 |
object_name: str,
|
| 45 |
mode: Literal["point", "object_detection", "query"],
|
| 46 |
+
model_name: Literal["moondream2", "moondream3-preview"] = "moondream3-preview",
|
| 47 |
reasoning: bool = False,
|
| 48 |
settings: dict = {"temperature": 0.0, "top_p": 0.95, "max_tokens": 512},
|
| 49 |
):
|
|
|
|
| 58 |
For "point" / "object_detection": a list of points (xy) or bounding boxes (xyxy) with normalized coordinates.
|
| 59 |
For "query": a dict {"answer": str} with the answer to the question.
|
| 60 |
"""
|
| 61 |
+
# model = _MODEL # load_model()
|
| 62 |
+
model = _MODEL_ZOO[model_name]
|
| 63 |
if isinstance(settings, str):
|
| 64 |
settings = json.loads(settings)
|
| 65 |
if mode == "point":
|
|
|
|
| 81 |
info="object to detector (for points / object_detection) or question for a query",
|
| 82 |
),
|
| 83 |
gr.Dropdown(label="Mode", choices=["point", "object_detection", "query"]),
|
| 84 |
+
gr.Dropdown(label="Model Variant", choices=list(_MODEL_ZOO.keys())),
|
| 85 |
gr.Checkbox(
|
| 86 |
label="Reasoning",
|
| 87 |
value=False,
|