orrinin commited on
Commit
fb34af7
·
verified ·
1 Parent(s): 2c66e7e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -40
app.py CHANGED
@@ -1,6 +1,5 @@
1
  #Using codes from killerz3/PodGen & eswardivi/Podcastify
2
  import json
3
- import spaces
4
  import httpx
5
  import os
6
  import re
@@ -10,24 +9,23 @@ import torch
10
  import tempfile
11
  import gradio as gr
12
  import gradio_client
 
13
  from pydub import AudioSegment
14
- from transformers import AutoModelForCausalLM, AutoTokenizer
15
-
16
  from moviepy.editor import AudioFileClip, concatenate_audioclips
17
 
18
  system_prompt = '''
19
- You are an talkshow podcast generator. You have to create short conversations between Alice and Bob that gives an overview of the News given by the user.
20
  Please provide the script and output strictly in the following JSON format:
21
  {
22
  "title": "[string]",
23
  "content": {
24
- "Alice_0": "[string]",
25
- "BOB_0": "[string]",
26
  ...
27
  }
28
  }
29
- #Please note that the [string] you generate now must be in based on the tone of people's daily life.
30
- #No more than five rounds of conversation, be concise.
31
  '''
32
 
33
  DESCRIPTION = '''
@@ -52,15 +50,8 @@ footer {
52
  }
53
  """
54
 
55
- MODEL_ID = "01-ai/Yi-1.5-6B-Chat"
56
-
57
- model = AutoModelForCausalLM.from_pretrained(
58
- MODEL_ID,
59
- torch_dtype=torch.float16,
60
- device_map="auto"
61
- ).eval()
62
-
63
- tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
64
 
65
 
66
  def validate_url(url):
@@ -98,7 +89,7 @@ async def gen_show(script):
98
  for key, text in content.items():
99
  speaker = key.split('_')[0] # Extract the speaker name
100
  index = key.split('_')[1] # Extract the dialogue index
101
- voice = "en-US-JennyNeural" if speaker == "Alice" else "en-US-GuyNeural"
102
 
103
  # Create temporary file for each speaker's dialogue
104
  temp_file = tempfile.NamedTemporaryFile(suffix='.mp3', delete=False)
@@ -128,26 +119,6 @@ async def gen_show(script):
128
 
129
  return output_filename
130
 
131
- @spaces.GPU
132
- def generator(messages):
133
- input_ids = tokenizer.apply_chat_template(
134
- conversation=messages,
135
- add_generation_prompt=True,
136
- tokenize=True,
137
- return_tensors='pt'
138
- )
139
-
140
- output_ids = model.generate(
141
- input_ids.to('cuda'),
142
- eos_token_id=tokenizer.eos_token_id,
143
- max_new_tokens=4096,
144
- temperature=0.5,
145
- repetition_penalty=1.2,
146
- )
147
-
148
- results = tokenizer.decode(output_ids[0][input_ids.shape[1]:], skip_special_tokens=True)
149
- print(results)
150
- return results
151
 
152
  def extract_content(text):
153
  """Extracts the JSON content from the given text."""
@@ -172,8 +143,15 @@ async def main(link):
172
  {"role": "system", "content": system_prompt},
173
  {"role": "user", "content": prompt},
174
  ]
175
-
176
- generated_script = extract_content(generator(messages))
 
 
 
 
 
 
 
177
 
178
  print("Generated Script:"+generated_script)
179
 
 
1
  #Using codes from killerz3/PodGen & eswardivi/Podcastify
2
  import json
 
3
  import httpx
4
  import os
5
  import re
 
9
  import tempfile
10
  import gradio as gr
11
  import gradio_client
12
+ from openai import OpenAI
13
  from pydub import AudioSegment
 
 
14
  from moviepy.editor import AudioFileClip, concatenate_audioclips
15
 
16
  system_prompt = '''
17
+ You are an talk-show podcast generator. You have to create short conversations between Xiaoxiao and Yunjian that gives an overview of the News given by the user.
18
  Please provide the script and output strictly in the following JSON format:
19
  {
20
  "title": "[string]",
21
  "content": {
22
+ "Xiaoxiao: "[string]",
23
+ "Yunjian": "[string]",
24
  ...
25
  }
26
  }
27
+ #Please note that the [string] you generate now must be in easy-and-understandable Chinese.
28
+ #Be concise.
29
  '''
30
 
31
  DESCRIPTION = '''
 
50
  }
51
  """
52
 
53
+ apikey = os.environ.get("API_KEY")
54
+ client = OpenAI(api_key=apikey, base_url="https://api.deepseek.com")
 
 
 
 
 
 
 
55
 
56
 
57
  def validate_url(url):
 
89
  for key, text in content.items():
90
  speaker = key.split('_')[0] # Extract the speaker name
91
  index = key.split('_')[1] # Extract the dialogue index
92
+ voice = "zh-CN-XiaoxiaoNeural" if speaker == "Xiaoxiao" else "zh-CN-YunjianNeural"
93
 
94
  # Create temporary file for each speaker's dialogue
95
  temp_file = tempfile.NamedTemporaryFile(suffix='.mp3', delete=False)
 
119
 
120
  return output_filename
121
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
 
123
  def extract_content(text):
124
  """Extracts the JSON content from the given text."""
 
143
  {"role": "system", "content": system_prompt},
144
  {"role": "user", "content": prompt},
145
  ]
146
+ completion = client.chat.completions.create(
147
+ model="deepseek-chat",
148
+ messages=messages,
149
+ max_tokens=4096,
150
+ temperature=0.7,
151
+ stream=False
152
+ )
153
+
154
+ generated_script = completion.choices[0].message.content
155
 
156
  print("Generated Script:"+generated_script)
157