Views
No views yet
In this task, your goal is to expand the user's short query into a detailed and well-structured English prompt for generating short videos.
Please ensure that the generated video prompt adheres to the following principles:
1. **Harmless**: The prompt must be safe, respectful, and free from any harmful, offensive, or unethical content.
2. **Aligned**: The prompt should fully preserve the user's intent, incorporating all relevant details from the original query while ensuring clarity and coherence.
3. **Helpful for High-Quality Video Generation**: The prompt should be descriptive and vivid to facilitate high-quality video creation. Keep the scene feasible and well-suited for a brief duration, avoiding unnecessary complexity or unrealistic elements not mentioned in the query.
User Query:{user prompt}
Video Prompt:1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3model_path = ''
4
5prompt_template = """In this task, your goal is to expand the user's short query into a detailed and well-structured English prompt for generating short videos.
6
7Please ensure that the generated video prompt adheres to the following principles:
8
91. **Harmless**: The prompt must be safe, respectful, and free from any harmful, offensive, or unethical content.
102. **Aligned**: The prompt should fully preserve the user's intent, incorporating all relevant details from the original query while ensuring clarity and coherence.
113. **Helpful for High-Quality Video Generation**: The prompt should be descriptive and vivid to facilitate high-quality video creation. Keep the scene feasible and well-suited for a brief duration, avoiding unnecessary complexity or unrealistic elements not mentioned in the query.
12
13User Query:{}
14
15Video Prompt:"""
16
17device = 'cuda:0'
18model = AutoModelForCausalLM.from_pretrained(model_path).half().eval().to(device)
19# for 8bit
20# model = AutoModelForCausalLM.from_pretrained(model_path, device_map=device, load_in_8bit=True)
21tokenizer = AutoTokenizer.from_pretrained(model_path)
22
23text = "a cute dog on the grass"
24messgae = [{'role': 'user', 'content': prompt_template.format(text)}]
25
26model_inputs = tokenizer.apply_chat_template(messgae, add_generation_prompt=True, tokenize=True, return_tensors="pt").to(device)
27output = model.generate(model_inputs, max_new_tokens=1024, do_sample=True, top_p=1.0, temperature=0.7, num_beams=1)
28resp = tokenizer.decode(output[0]).split('<|start_header_id|>assistant<|end_header_id|>')[1].split('<|eot_id|>')[0].strip()
29
30print(resp)