Update app.py
Browse files
app.py
CHANGED
|
@@ -42,7 +42,7 @@ tokenizer = AutoTokenizer.from_pretrained(LORA_MODEL, trust_remote_code=True)
|
|
| 42 |
|
| 43 |
print("Loading models on CPU to safely bypass ZeroGPU startup constraints...")
|
| 44 |
|
| 45 |
-
# π
|
| 46 |
_original_cuda_available = torch.cuda.is_available
|
| 47 |
torch.cuda.is_available = lambda: False
|
| 48 |
|
|
@@ -61,7 +61,7 @@ try:
|
|
| 61 |
_peft_model = PeftModel.from_pretrained(
|
| 62 |
base_model,
|
| 63 |
LORA_MODEL,
|
| 64 |
-
device_map={"": "cpu"}
|
| 65 |
)
|
| 66 |
|
| 67 |
print("Merging LoRA weights...")
|
|
@@ -87,7 +87,7 @@ try:
|
|
| 87 |
_draft_peft = PeftModel.from_pretrained(
|
| 88 |
_draft_base,
|
| 89 |
DRAFT_MODEL,
|
| 90 |
-
device_map={"": "cpu"}
|
| 91 |
)
|
| 92 |
|
| 93 |
draft_model = _draft_peft.merge_and_unload()
|
|
@@ -129,6 +129,10 @@ def generate_code(topic: str, temperature: float, max_tokens: int):
|
|
| 129 |
yield "# Please enter a topic or description."
|
| 130 |
return
|
| 131 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
messages = [
|
| 133 |
{"role": "system", "content": SYSTEM_PROMPT},
|
| 134 |
{"role": "user", "content": topic.strip()},
|
|
@@ -274,16 +278,7 @@ CSS = """
|
|
| 274 |
}
|
| 275 |
"""
|
| 276 |
|
| 277 |
-
with gr.Blocks(
|
| 278 |
-
title="Anim Vid Max β AI Animation Generator",
|
| 279 |
-
css=CSS,
|
| 280 |
-
theme=gr.themes.Base(
|
| 281 |
-
primary_hue=gr.themes.colors.indigo,
|
| 282 |
-
secondary_hue=gr.themes.colors.sky,
|
| 283 |
-
neutral_hue=gr.themes.colors.slate,
|
| 284 |
-
font=gr.themes.GoogleFont("Inter"),
|
| 285 |
-
),
|
| 286 |
-
) as demo:
|
| 287 |
|
| 288 |
gr.HTML("""
|
| 289 |
<div class="header-wrap">
|
|
@@ -324,7 +319,7 @@ with gr.Blocks(
|
|
| 324 |
label="π‘ Examples",
|
| 325 |
)
|
| 326 |
|
| 327 |
-
with gr.Column(scale=3
|
| 328 |
gr.HTML('<div class="section-label">2. Manim Code</div>')
|
| 329 |
code_output = gr.Code(
|
| 330 |
label="Generated Script (editable)",
|
|
@@ -364,4 +359,13 @@ with gr.Blocks(
|
|
| 364 |
outputs=[output_video, status_output],
|
| 365 |
)
|
| 366 |
|
| 367 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
print("Loading models on CPU to safely bypass ZeroGPU startup constraints...")
|
| 44 |
|
| 45 |
+
# π Temporarily blind the environment to CUDA so PEFT doesn't crash during startup
|
| 46 |
_original_cuda_available = torch.cuda.is_available
|
| 47 |
torch.cuda.is_available = lambda: False
|
| 48 |
|
|
|
|
| 61 |
_peft_model = PeftModel.from_pretrained(
|
| 62 |
base_model,
|
| 63 |
LORA_MODEL,
|
| 64 |
+
device_map={"": "cpu"}
|
| 65 |
)
|
| 66 |
|
| 67 |
print("Merging LoRA weights...")
|
|
|
|
| 87 |
_draft_peft = PeftModel.from_pretrained(
|
| 88 |
_draft_base,
|
| 89 |
DRAFT_MODEL,
|
| 90 |
+
device_map={"": "cpu"}
|
| 91 |
)
|
| 92 |
|
| 93 |
draft_model = _draft_peft.merge_and_unload()
|
|
|
|
| 129 |
yield "# Please enter a topic or description."
|
| 130 |
return
|
| 131 |
|
| 132 |
+
# π THE FINAL FIX: Move models from CPU RAM to the ZeroGPU hardware just-in-time
|
| 133 |
+
model.to(device)
|
| 134 |
+
draft_model.to(device)
|
| 135 |
+
|
| 136 |
messages = [
|
| 137 |
{"role": "system", "content": SYSTEM_PROMPT},
|
| 138 |
{"role": "user", "content": topic.strip()},
|
|
|
|
| 278 |
}
|
| 279 |
"""
|
| 280 |
|
| 281 |
+
with gr.Blocks(title="Anim Vid Max β AI Animation Generator") as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 282 |
|
| 283 |
gr.HTML("""
|
| 284 |
<div class="header-wrap">
|
|
|
|
| 319 |
label="π‘ Examples",
|
| 320 |
)
|
| 321 |
|
| 322 |
+
with gr.Column(scale=3, elem_classes=["col-sep"]):
|
| 323 |
gr.HTML('<div class="section-label">2. Manim Code</div>')
|
| 324 |
code_output = gr.Code(
|
| 325 |
label="Generated Script (editable)",
|
|
|
|
| 359 |
outputs=[output_video, status_output],
|
| 360 |
)
|
| 361 |
|
| 362 |
+
# Cleaned up launch arguments to prevent warnings
|
| 363 |
+
demo.launch(
|
| 364 |
+
css=CSS,
|
| 365 |
+
theme=gr.themes.Base(
|
| 366 |
+
primary_hue=gr.themes.colors.indigo,
|
| 367 |
+
secondary_hue=gr.themes.colors.sky,
|
| 368 |
+
neutral_hue=gr.themes.colors.slate,
|
| 369 |
+
font=gr.themes.GoogleFont("Inter"),
|
| 370 |
+
)
|
| 371 |
+
)
|