Spaces:
Running
on
Zero
Running
on
Zero
Darius Morawiec
commited on
Commit
·
251f917
1
Parent(s):
9afc0f5
Refactor constants
Browse files
app.py
CHANGED
|
@@ -18,6 +18,7 @@ from transformers import (
|
|
| 18 |
|
| 19 |
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
|
| 20 |
|
|
|
|
| 21 |
if os.environ.get("SPACES_ZERO_GPU") is not None:
|
| 22 |
import spaces
|
| 23 |
else:
|
|
@@ -31,10 +32,10 @@ else:
|
|
| 31 |
return wrapper
|
| 32 |
|
| 33 |
|
|
|
|
| 34 |
EXAMPLES_DIR = Path(__file__).parent / "examples"
|
| 35 |
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
| 36 |
-
|
| 37 |
-
model_ids = [
|
| 38 |
"Qwen/Qwen2-VL-2B-Instruct", # https://huggingface.co/Qwen/Qwen2-VL-2B-Instruct
|
| 39 |
"Qwen/Qwen2-VL-7B-Instruct", # https://huggingface.co/Qwen/Qwen2-VL-7B-Instruct
|
| 40 |
"Qwen/Qwen2.5-VL-3B-Instruct", # https://huggingface.co/Qwen/Qwen2.5-VL-3B-Instruct
|
|
@@ -88,7 +89,7 @@ with gr.Blocks() as demo:
|
|
| 88 |
gr.Markdown("## Settings")
|
| 89 |
|
| 90 |
input_model_id = gr.Dropdown(
|
| 91 |
-
choices=
|
| 92 |
label="✨ Select Model ID",
|
| 93 |
)
|
| 94 |
default_system_prompt = 'You are a helpful assistant to detect objects in images. When asked to detect elements based on a description, you return a valid JSON object containing bounding boxes for all elements in the form `[{"bbox_2d": [xmin, ymin, xmax, ymax], "label": "placeholder"}, ...]`. For example, a valid response could be: `[{"bbox_2d": [10, 30, 20, 60], "label": "placeholder"}, {"bbox_2d": [40, 15, 52, 27], "label": "placeholder"}]`.'
|
|
|
|
| 18 |
|
| 19 |
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
|
| 20 |
|
| 21 |
+
# Handle spaces.GPU decorator for GPU allocation in Spaces
|
| 22 |
if os.environ.get("SPACES_ZERO_GPU") is not None:
|
| 23 |
import spaces
|
| 24 |
else:
|
|
|
|
| 32 |
return wrapper
|
| 33 |
|
| 34 |
|
| 35 |
+
# Define constants
|
| 36 |
EXAMPLES_DIR = Path(__file__).parent / "examples"
|
| 37 |
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
| 38 |
+
MODEL_IDS = [
|
|
|
|
| 39 |
"Qwen/Qwen2-VL-2B-Instruct", # https://huggingface.co/Qwen/Qwen2-VL-2B-Instruct
|
| 40 |
"Qwen/Qwen2-VL-7B-Instruct", # https://huggingface.co/Qwen/Qwen2-VL-7B-Instruct
|
| 41 |
"Qwen/Qwen2.5-VL-3B-Instruct", # https://huggingface.co/Qwen/Qwen2.5-VL-3B-Instruct
|
|
|
|
| 89 |
gr.Markdown("## Settings")
|
| 90 |
|
| 91 |
input_model_id = gr.Dropdown(
|
| 92 |
+
choices=MODEL_IDS,
|
| 93 |
label="✨ Select Model ID",
|
| 94 |
)
|
| 95 |
default_system_prompt = 'You are a helpful assistant to detect objects in images. When asked to detect elements based on a description, you return a valid JSON object containing bounding boxes for all elements in the form `[{"bbox_2d": [xmin, ymin, xmax, ymax], "label": "placeholder"}, ...]`. For example, a valid response could be: `[{"bbox_2d": [10, 30, 20, 60], "label": "placeholder"}, {"bbox_2d": [40, 15, 52, 27], "label": "placeholder"}]`.'
|