fffiloni commited on
Commit
c09190f
β€’
1 Parent(s): 7368cef

Added community share

Browse files
Files changed (1) hide show
  1. app.py +55 -15
app.py CHANGED
@@ -1,15 +1,18 @@
1
  import gradio as gr
2
  import os
 
 
 
 
 
3
 
4
  img_to_text = gr.Blocks.load(name="spaces/pharma/CLIP-Interrogator")
5
  text_to_music = gr.Interface.load("spaces/fffiloni/text-2-music")
6
 
 
 
7
  def get_prompts(uploaded_image):
8
 
9
- print(f"""β€”β€”β€”β€”β€”
10
- Calling CLIP Interrogator ...
11
- """)
12
-
13
  prompt = img_to_text(uploaded_image, fn_index=1)[0]
14
 
15
  music_result = get_music(prompt)
@@ -18,11 +21,6 @@ def get_prompts(uploaded_image):
18
 
19
  def get_music(prompt):
20
 
21
- print(f"""β€”β€”β€”β€”β€”
22
- Calling now MubertAI ...
23
- β€”β€”β€”β€”β€”β€”β€”
24
- """)
25
-
26
  result = text_to_music(prompt, fn_index=0)
27
 
28
  print(f"""β€”β€”β€”β€”β€”
@@ -32,11 +30,52 @@ def get_music(prompt):
32
  β€”β€”β€”β€”β€”β€”β€”
33
  """)
34
 
35
- return result
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
  css = """
38
  #col-container {max-width: 700px; margin-left: auto; margin-right: auto;}
39
  a {text-decoration-line: underline; font-weight: 600;}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  """
41
 
42
  with gr.Blocks(css=css) as demo:
@@ -67,11 +106,12 @@ with gr.Blocks(css=css) as demo:
67
 
68
  music_output = gr.Audio(label="Result", type="filepath", elem_id="music-output")
69
 
70
- #with gr.Group(elem_id="share-btn-container"):
71
- # community_icon = gr.HTML(community_icon_html, visible=False)
72
- # loading_icon = gr.HTML(loading_icon_html, visible=False)
73
- # share_button = gr.Button("Share to community", elem_id="share-btn", visible=False)
74
 
75
- generate.click(get_prompts, inputs=[input_img], outputs=[music_output])
 
76
 
77
  demo.queue(max_size=32, concurrency_count=20).launch()
 
1
  import gradio as gr
2
  import os
3
+ import requests
4
+ import urllib
5
+
6
+ from os import path
7
+ from pydub import AudioSegment
8
 
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, fn_index=1)[0]
17
 
18
  music_result = get_music(prompt)
 
21
 
22
  def get_music(prompt):
23
 
 
 
 
 
 
24
  result = text_to_music(prompt, fn_index=0)
25
 
26
  print(f"""β€”β€”β€”β€”β€”
 
30
  β€”β€”β€”β€”β€”β€”β€”
31
  """)
32
 
33
+ url = result
34
+ save_as = "file.mp3"
35
+
36
+ data = urllib.request.urlopen(url)
37
+
38
+ f = open(save_as,'wb')
39
+ f.write(data.read())
40
+ f.close()
41
+
42
+ wave_file="file.wav"
43
+
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;}
51
  a {text-decoration-line: underline; font-weight: 600;}
52
+ .animate-spin {
53
+ animation: spin 1s linear infinite;
54
+ }
55
+ @keyframes spin {
56
+ from {
57
+ transform: rotate(0deg);
58
+ }
59
+ to {
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;
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:
 
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])
115
+ share_button.click(None, [], [], _js=share_js)
116
 
117
  demo.queue(max_size=32, concurrency_count=20).launch()