vilarin commited on
Commit
f55597f
·
verified ·
1 Parent(s): f0f4b7b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -28
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": "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,12 +48,15 @@ footer {
48
  }
49
  """
50
 
 
 
51
  model = AutoModelForCausalLM.from_pretrained(
52
- "Qwen/Qwen1.5-1.8B-Chat",
53
- torch_dtype="auto",
54
  device_map="auto"
55
- )
56
- tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen1.5-1.8B-Chat")
 
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(duration=100)
125
  def generator(messages):
126
- answer = tokenizer.apply_chat_template(
127
- messages,
128
- tokenize=False,
129
- add_generation_prompt=True
130
  )
131
- model_inputs = tokenizer([answer], return_tensors="pt").to(0)
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)