Spaces:
Runtime error
Runtime error
sliders added
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ import torch
|
|
| 3 |
from diffusers import AnimateDiffPipeline, DDIMScheduler, MotionAdapter
|
| 4 |
from diffusers.utils import export_to_gif
|
| 5 |
from diffusers.utils import export_to_video
|
|
|
|
| 6 |
import uuid
|
| 7 |
import spaces
|
| 8 |
|
|
@@ -22,21 +23,52 @@ device = "cuda"
|
|
| 22 |
adapter = MotionAdapter.from_pretrained("guoyww/animatediff-motion-adapter-v1-5-2", torch_dtype=torch.float16)
|
| 23 |
model_id = "SG161222/Realistic_Vision_V5.1_noVAE"
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
@spaces.GPU
|
| 26 |
def generate_video(prompt,negative_prompt, guidance_scale, num_inference_steps, adapter_choices):
|
| 27 |
-
pipe = AnimateDiffPipeline.from_pretrained(model_id, motion_adapter=adapter, torch_dtype=torch.float16).to(device)
|
| 28 |
-
scheduler = DDIMScheduler.from_pretrained(
|
| 29 |
-
model_id,
|
| 30 |
-
subfolder="scheduler",
|
| 31 |
-
clip_sample=False,
|
| 32 |
-
timestep_spacing="linspace",
|
| 33 |
-
beta_schedule="linear",
|
| 34 |
-
steps_offset=1,
|
| 35 |
-
)
|
| 36 |
-
pipe.scheduler = scheduler
|
| 37 |
|
| 38 |
pipe.to(device)
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
# Set adapters based on user selection
|
| 41 |
if adapter_choices:
|
| 42 |
for i in range(len(adapter_choices)):
|
|
|
|
| 3 |
from diffusers import AnimateDiffPipeline, DDIMScheduler, MotionAdapter
|
| 4 |
from diffusers.utils import export_to_gif
|
| 5 |
from diffusers.utils import export_to_video
|
| 6 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
| 7 |
import uuid
|
| 8 |
import spaces
|
| 9 |
|
|
|
|
| 23 |
adapter = MotionAdapter.from_pretrained("guoyww/animatediff-motion-adapter-v1-5-2", torch_dtype=torch.float16)
|
| 24 |
model_id = "SG161222/Realistic_Vision_V5.1_noVAE"
|
| 25 |
|
| 26 |
+
model_llm = AutoModelForCausalLM.from_pretrained(
|
| 27 |
+
"microsoft/Phi-3-mini-128k-instruct",
|
| 28 |
+
device_map="cuda",
|
| 29 |
+
torch_dtype="auto",
|
| 30 |
+
trust_remote_code=True,
|
| 31 |
+
device="cuda"
|
| 32 |
+
)
|
| 33 |
+
tokenizer_llm = AutoTokenizer.from_pretrained("microsoft/Phi-3-mini-128k-instruct",device="cuda")
|
| 34 |
+
|
| 35 |
+
pipe = AnimateDiffPipeline.from_pretrained(model_id, motion_adapter=adapter, torch_dtype=torch.float16).to(device)
|
| 36 |
+
scheduler = DDIMScheduler.from_pretrained(
|
| 37 |
+
model_id,
|
| 38 |
+
subfolder="scheduler",
|
| 39 |
+
clip_sample=False,
|
| 40 |
+
timestep_spacing="linspace",
|
| 41 |
+
beta_schedule="linear",
|
| 42 |
+
steps_offset=1,
|
| 43 |
+
)
|
| 44 |
+
pipe.scheduler = scheduler
|
| 45 |
+
|
| 46 |
@spaces.GPU
|
| 47 |
def generate_video(prompt,negative_prompt, guidance_scale, num_inference_steps, adapter_choices):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
pipe.to(device)
|
| 50 |
|
| 51 |
+
messages = [
|
| 52 |
+
{"role": "user", "content": "You have to complete my given prompt into a complete description. The description should be heavily detailed. Feel free to add your own fillers if need. The purpose of this description is to descibe a video generation. My Prompt: " + prompt},
|
| 53 |
+
]
|
| 54 |
+
|
| 55 |
+
pipe_llm = pipeline(
|
| 56 |
+
"text-generation",
|
| 57 |
+
model=model_llm,
|
| 58 |
+
tokenizer=tokenizer_llm,
|
| 59 |
+
device="cuda"
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
generation_args = {
|
| 63 |
+
"max_new_tokens": 500,
|
| 64 |
+
"return_full_text": False,
|
| 65 |
+
"temperature": 1,
|
| 66 |
+
"do_sample": False,
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
output = pipe_llm(messages, **generation_args)
|
| 70 |
+
print(output[0]['generated_text'])
|
| 71 |
+
|
| 72 |
# Set adapters based on user selection
|
| 73 |
if adapter_choices:
|
| 74 |
for i in range(len(adapter_choices)):
|