DGSpitzer commited on
Commit
1fcf971
1 Parent(s): 677f5d3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -33
app.py CHANGED
@@ -4,6 +4,12 @@ import gradio as gr
4
  import paddlehub as hub
5
  import urllib
6
  import cv2
 
 
 
 
 
 
7
 
8
  import torch
9
 
@@ -95,37 +101,18 @@ def get_result(text_prompts, style_indx):
95
 
96
  interrogate_prompt = img_to_text(imagefile, fn_index=1)[0]
97
  print(interrogate_prompt)
98
- music_output = get_music(interrogate_prompt + ", " + style_list_EN[style_indx])
99
 
100
  video_merged = merge_video(music_output, image_output)
101
- return {video_result:video_merged, status_text:'Success'}
102
 
103
  def get_music(prompt):
104
-
105
- result = text_to_music(prompt, fn_index=0)
106
-
107
- print(f"""—————
108
- NEW RESULTS
109
- prompt : {prompt}
110
- music : {result}
111
- ———————
112
- """)
113
-
114
- url = result
115
- save_as = "file.mp3"
116
-
117
- data = urllib.request.urlopen(url)
118
-
119
- f = open(save_as,'wb')
120
- f.write(data.read())
121
- f.close()
122
-
123
- #wave_file="file.wav"
124
-
125
- #sound = AudioSegment.from_mp3(save_as)
126
- #sound.export(wave_file, format="wav")
127
-
128
- return save_as
129
 
130
  def merge_video(music, img_list):
131
  #Convert to mp3
@@ -446,6 +433,7 @@ with block:
446
  interactive=False
447
  )
448
 
 
449
  video_result = gr.Video(type=None, label='Final Merged video')
450
 
451
  trigger_component = gr.Textbox(vaule="", visible=False) # This component is used for triggering inference funtion.
@@ -458,14 +446,9 @@ with block:
458
 
459
  text.submit(translate_language, inputs=[text], outputs=[language_tips_text, status_text, trigger_component, translated_language])
460
  btn.click(translate_language, inputs=[text], outputs=[language_tips_text, status_text, trigger_component, translated_language])
461
- trigger_component.change(fn=get_result, inputs=[translated_language, styles], outputs=[video_result, status_text])
462
 
463
 
464
- gr.Markdown(
465
- """
466
- ### <u>[Prompt Tutorial 公式教程...](https://github.com/PaddlePaddle/PaddleHub/blob/develop/modules/image/text_to_image/ernie_vilg/README.md#四-prompt-指南)([Explore more...](https://github.com/PaddlePaddle/PaddleHub/blob/develop/modules/image/text_to_image/ernie_vilg/README.md#四-prompt-指南))</u>
467
- """
468
- )
469
  gr.Markdown(
470
  """
471
  Space by [@DGSpitzer](https://www.youtube.com/channel/UCzzsYBF4qwtMwJaPJZ5SuPg)❤️ [@大谷的游戏创作小屋](https://space.bilibili.com/176003)
 
4
  import paddlehub as hub
5
  import urllib
6
  import cv2
7
+ from datasets import load_dataset
8
+ import re
9
+ import os
10
+ import requests
11
+
12
+ from share_btn import community_icon_html, loading_icon_html, share_js
13
 
14
  import torch
15
 
 
101
 
102
  interrogate_prompt = img_to_text(imagefile, fn_index=1)[0]
103
  print(interrogate_prompt)
104
+ spec_image, music_output = get_music(interrogate_prompt + ", " + style_list_EN[style_indx])
105
 
106
  video_merged = merge_video(music_output, image_output)
107
+ return {spec_result:spec_image, video_result:video_merged, status_text:'Success'}
108
 
109
  def get_music(prompt):
110
+ spec = pipe(prompt).images[0]
111
+ print(spec)
112
+ wav = wav_bytes_from_spectrogram_image(spec)
113
+ with open("output.wav", "wb") as f:
114
+ f.write(wav[0].getbuffer())
115
+ return spec, 'output.wav'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
 
117
  def merge_video(music, img_list):
118
  #Convert to mp3
 
433
  interactive=False
434
  )
435
 
436
+ spec_result = gr.Image()
437
  video_result = gr.Video(type=None, label='Final Merged video')
438
 
439
  trigger_component = gr.Textbox(vaule="", visible=False) # This component is used for triggering inference funtion.
 
446
 
447
  text.submit(translate_language, inputs=[text], outputs=[language_tips_text, status_text, trigger_component, translated_language])
448
  btn.click(translate_language, inputs=[text], outputs=[language_tips_text, status_text, trigger_component, translated_language])
449
+ trigger_component.change(fn=get_result, inputs=[translated_language, styles], outputs=[spec_result, video_result, status_text])
450
 
451
 
 
 
 
 
 
452
  gr.Markdown(
453
  """
454
  Space by [@DGSpitzer](https://www.youtube.com/channel/UCzzsYBF4qwtMwJaPJZ5SuPg)❤️ [@大谷的游戏创作小屋](https://space.bilibili.com/176003)