HongcanGuo commited on
Commit
ec79982
·
verified ·
1 Parent(s): 45423d7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -85,15 +85,15 @@ def text2vid(input_text):
85
  generator=torch.Generator("cpu").manual_seed(0)
86
  )
87
  frames = output.frames[0]
88
- export_to_gif(frames, f"data/{index+1}.gif")
89
 
90
  # 定义生成最终视频的函数
91
  def video_generate():
92
  frame_rate = 24
93
- gif_files = sorted(glob.glob('./data/*.gif'))
94
  clips = [VideoFileClip(gif) for gif in gif_files]
95
  final_clip = concatenate_videoclips(clips, method="compose")
96
- final_clip.write_videofile('data/output_video.mp4', codec='libx264')
97
 
98
  # 定义文本到音频函数
99
  def text2audio(text_input, duration_seconds):
@@ -102,14 +102,14 @@ def text2audio(text_input, duration_seconds):
102
  inputs = processor(text=[text_input], padding=True, return_tensors="pt")
103
  max_new_tokens = int((duration_seconds / 5) * 256)
104
  audio_values = model.generate(**inputs, max_new_tokens=max_new_tokens)
105
- scipy.io.wavfile.write("data/bgm.wav", rate=model.config.audio_encoder.sampling_rate, data=audio_values[0, 0].numpy())
106
 
107
  # 定义生成结果视频的函数
108
  def result_generate():
109
- video = VideoFileClip("data/output_video.mp4")
110
- audio = AudioFileClip("data/bgm.wav")
111
  video = video.set_audio(audio)
112
- video.write_videofile("output/result.mp4", codec="libx264", audio_codec="aac")
113
 
114
  # 定义删除所有文件的函数
115
  def delete_all_files(directory):
@@ -132,12 +132,12 @@ def generate_video(image):
132
  sentences = text2text(text)
133
  text2vid(sentences)
134
  video_generate()
135
- video = VideoFileClip("data/output_video.mp4")
136
  duration = video.duration
137
  audio_text = text2text(text)
138
  text2audio(audio_text, duration)
139
  result_generate()
140
- return "output/result.mp4"
141
 
142
  # 定义 Gradio 接口
143
  # interface = gr.Interface(
 
85
  generator=torch.Generator("cpu").manual_seed(0)
86
  )
87
  frames = output.frames[0]
88
+ export_to_gif(frames, f"./{index+1}.gif")
89
 
90
  # 定义生成最终视频的函数
91
  def video_generate():
92
  frame_rate = 24
93
+ gif_files = sorted(glob.glob('./*.gif'))
94
  clips = [VideoFileClip(gif) for gif in gif_files]
95
  final_clip = concatenate_videoclips(clips, method="compose")
96
+ final_clip.write_videofile('output_video.mp4', codec='libx264')
97
 
98
  # 定义文本到音频函数
99
  def text2audio(text_input, duration_seconds):
 
102
  inputs = processor(text=[text_input], padding=True, return_tensors="pt")
103
  max_new_tokens = int((duration_seconds / 5) * 256)
104
  audio_values = model.generate(**inputs, max_new_tokens=max_new_tokens)
105
+ scipy.io.wavfile.write("bgm.wav", rate=model.config.audio_encoder.sampling_rate, data=audio_values[0, 0].numpy())
106
 
107
  # 定义生成结果视频的函数
108
  def result_generate():
109
+ video = VideoFileClip("output_video.mp4")
110
+ audio = AudioFileClip("bgm.wav")
111
  video = video.set_audio(audio)
112
+ video.write_videofile("result.mp4", codec="libx264", audio_codec="aac")
113
 
114
  # 定义删除所有文件的函数
115
  def delete_all_files(directory):
 
132
  sentences = text2text(text)
133
  text2vid(sentences)
134
  video_generate()
135
+ video = VideoFileClip("output_video.mp4")
136
  duration = video.duration
137
  audio_text = text2text(text)
138
  text2audio(audio_text, duration)
139
  result_generate()
140
+ return "result.mp4"
141
 
142
  # 定义 Gradio 接口
143
  # interface = gr.Interface(