kokuma commited on
Commit
8099795
Β·
1 Parent(s): cddb846

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -33
app.py CHANGED
@@ -9,24 +9,23 @@ from pydub import AudioSegment
9
  img_to_text = gr.Blocks.load(name="spaces/pharma/CLIP-Interrogator")
10
  text_to_music = gr.Interface.load("spaces/fffiloni/text-2-music")
11
 
12
- from share_btn import community_icon_html, loading_icon_html, share_js
13
-
14
  def get_prompts(uploaded_image):
15
-
16
  prompt = img_to_text(uploaded_image, "ViT-L (best for Stable Diffusion 1.*)", "fast", fn_index=1)[0]
17
-
18
  music_result = get_music(prompt)
19
-
20
- return music_result
 
 
 
 
21
 
22
  def get_music(prompt):
23
 
24
  result = text_to_music(prompt, fn_index=0)
25
 
26
  print(f"""β€”β€”β€”β€”β€”
27
- NEW RESULTS
28
- prompt : {prompt}
29
- music : {result}
30
  β€”β€”β€”β€”β€”β€”β€”
31
  """)
32
 
@@ -44,7 +43,8 @@ def get_music(prompt):
44
  sound = AudioSegment.from_mp3(save_as)
45
  sound.export(wave_file, format="wav")
46
 
47
- return wave_file, gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
 
48
 
49
  css = """
50
  #col-container {max-width: 700px; margin-left: auto; margin-right: auto;}
@@ -60,22 +60,6 @@ a {text-decoration-line: underline; font-weight: 600;}
60
  transform: rotate(360deg);
61
  }
62
  }
63
- #share-btn-container {
64
- display: flex; padding-left: 0.5rem !important; padding-right: 0.5rem !important; background-color: #000000; justify-content: center; align-items: center; border-radius: 9999px !important; width: 13rem;
65
- }
66
- #share-btn {
67
- all: initial; color: #ffffff;font-weight: 600; cursor:pointer; font-family: 'IBM Plex Sans', sans-serif; margin-left: 0.5rem !important; padding-top: 0.25rem !important; padding-bottom: 0.25rem !important;right:0;
68
- }
69
- #share-btn * {
70
- all: unset;
71
- }
72
- #share-btn-container div:nth-child(-n+2){
73
- width: auto !important;
74
- min-height: 0px !important;
75
- }
76
- #share-btn-container .wrap {
77
- display: none !important;
78
- }
79
  """
80
 
81
  with gr.Blocks(css=css) as demo:
@@ -105,13 +89,8 @@ with gr.Blocks(css=css) as demo:
105
  generate = gr.Button("Generate Music from Image")
106
 
107
  music_output = gr.Audio(label="Result", type="filepath", elem_id="music-output")
108
-
109
- with gr.Group(elem_id="share-btn-container"):
110
- community_icon = gr.HTML(community_icon_html, visible=False)
111
- loading_icon = gr.HTML(loading_icon_html, visible=False)
112
- share_button = gr.Button("Share to community", elem_id="share-btn", visible=False)
113
 
114
- generate.click(get_prompts, inputs=[input_img], outputs=[music_output, share_button, community_icon, loading_icon], api_name="i2m")
115
- share_button.click(None, [], [], _js=share_js)
116
 
117
  demo.queue(max_size=32, concurrency_count=20).launch()
 
9
  img_to_text = gr.Blocks.load(name="spaces/pharma/CLIP-Interrogator")
10
  text_to_music = gr.Interface.load("spaces/fffiloni/text-2-music")
11
 
 
 
12
  def get_prompts(uploaded_image):
 
13
  prompt = img_to_text(uploaded_image, "ViT-L (best for Stable Diffusion 1.*)", "fast", fn_index=1)[0]
 
14
  music_result = get_music(prompt)
15
+ print(f"""β€”β€”β€”β€”β€”
16
+ PROMPT: {prompt}
17
+ β€”β€”β€”β€”β€”β€”β€”
18
+ """)
19
+ return music_result, prompt
20
+
21
 
22
  def get_music(prompt):
23
 
24
  result = text_to_music(prompt, fn_index=0)
25
 
26
  print(f"""β€”β€”β€”β€”β€”
27
+ MUSIC
28
+ prompt: {result}
 
29
  β€”β€”β€”β€”β€”β€”β€”
30
  """)
31
 
 
43
  sound = AudioSegment.from_mp3(save_as)
44
  sound.export(wave_file, format="wav")
45
 
46
+ return wave_file
47
+
48
 
49
  css = """
50
  #col-container {max-width: 700px; margin-left: auto; margin-right: auto;}
 
60
  transform: rotate(360deg);
61
  }
62
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  """
64
 
65
  with gr.Blocks(css=css) as demo:
 
89
  generate = gr.Button("Generate Music from Image")
90
 
91
  music_output = gr.Audio(label="Result", type="filepath", elem_id="music-output")
92
+ prompt_text = gr.Textbox(label="Prompt")
 
 
 
 
93
 
94
+ generate.click(get_prompts, inputs=[input_img], outputs=[music_output, prompt_text], api_name="i2m")
 
95
 
96
  demo.queue(max_size=32, concurrency_count=20).launch()