Update app.py
Browse files
app.py
CHANGED
@@ -18,14 +18,14 @@ system_prompt = '''
|
|
18 |
You are an educational podcast generator. You have to create short conversations between Alice and Bob that gives an overview of the News given by the user.
|
19 |
Please provide the script in the following JSON format directly:
|
20 |
{
|
21 |
-
"title": "
|
22 |
"content": {
|
23 |
-
"Alice_0": "
|
24 |
-
"BOB_0": "
|
25 |
...
|
26 |
}
|
27 |
}
|
28 |
-
Please note that the
|
29 |
No more than five rounds of conversation.
|
30 |
'''
|
31 |
|
@@ -48,12 +48,15 @@ footer {
|
|
48 |
}
|
49 |
"""
|
50 |
|
|
|
|
|
51 |
model = AutoModelForCausalLM.from_pretrained(
|
52 |
-
|
53 |
-
torch_dtype=
|
54 |
device_map="auto"
|
55 |
-
)
|
56 |
-
|
|
|
57 |
|
58 |
|
59 |
def validate_url(url):
|
@@ -121,25 +124,15 @@ async def gen_show(script):
|
|
121 |
|
122 |
return output_filename
|
123 |
|
124 |
-
@spaces.GPU
|
125 |
def generator(messages):
|
126 |
-
|
127 |
-
messages,
|
128 |
-
tokenize=
|
129 |
-
|
130 |
)
|
131 |
-
|
132 |
-
|
133 |
-
generated_ids = model.generate(
|
134 |
-
model_inputs.input_ids,
|
135 |
-
max_new_tokens=4096
|
136 |
-
)
|
137 |
-
|
138 |
-
generated_ids = [
|
139 |
-
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
|
140 |
-
]
|
141 |
-
|
142 |
-
results = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
143 |
return results
|
144 |
|
145 |
|
@@ -167,9 +160,6 @@ async def main(link):
|
|
167 |
if not generated_script or not generated_script.strip().startswith('{'):
|
168 |
raise ValueError("Failed to generate a valid script.")
|
169 |
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
script_json = json.loads(generated_script) # Use the generated script as input
|
174 |
output_filename = await gen_show(script_json)
|
175 |
print("Output File:"+output_filename)
|
|
|
18 |
You are an educational podcast generator. You have to create short conversations between Alice and Bob that gives an overview of the News given by the user.
|
19 |
Please provide the script in the following JSON format directly:
|
20 |
{
|
21 |
+
"title": "Strings",
|
22 |
"content": {
|
23 |
+
"Alice_0": "Strings",
|
24 |
+
"BOB_0": "Strings",
|
25 |
...
|
26 |
}
|
27 |
}
|
28 |
+
Please note that the Strings you generate now must be based on the tone of people's daily life, and the punctuation marks only include commas and periods.
|
29 |
No more than five rounds of conversation.
|
30 |
'''
|
31 |
|
|
|
48 |
}
|
49 |
"""
|
50 |
|
51 |
+
MODEL_ID = "01-ai/Yi-1.5-6B-Chat"
|
52 |
+
|
53 |
model = AutoModelForCausalLM.from_pretrained(
|
54 |
+
MODEL_ID,
|
55 |
+
torch_dtype=torch.float16,
|
56 |
device_map="auto"
|
57 |
+
).eval()
|
58 |
+
|
59 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
|
60 |
|
61 |
|
62 |
def validate_url(url):
|
|
|
124 |
|
125 |
return output_filename
|
126 |
|
127 |
+
@spaces.GPU
|
128 |
def generator(messages):
|
129 |
+
input_ids = tokenizer.apply_chat_template(
|
130 |
+
conversation=messages,
|
131 |
+
tokenize=True,
|
132 |
+
return_tensors='pt'
|
133 |
)
|
134 |
+
output_ids = model.generate(input_ids.to('cuda'), eos_token_id=tokenizer.eos_token_id)
|
135 |
+
results = tokenizer.decode(output_ids[0][input_ids.shape[1]:], skip_special_tokens=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
return results
|
137 |
|
138 |
|
|
|
160 |
if not generated_script or not generated_script.strip().startswith('{'):
|
161 |
raise ValueError("Failed to generate a valid script.")
|
162 |
|
|
|
|
|
|
|
163 |
script_json = json.loads(generated_script) # Use the generated script as input
|
164 |
output_filename = await gen_show(script_json)
|
165 |
print("Output File:"+output_filename)
|