Fabrice-TIERCELIN commited on
Commit
87d6ca7
Β·
verified Β·
1 Parent(s): 851252a

Avoid error if spaces is not imported

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -115,7 +115,6 @@ def update_output(output_format, output_number):
115
  gr.update(visible = False)
116
  ]
117
 
118
- @spaces.GPU(duration=420)
119
  def text2audio(
120
  prompt,
121
  output_number,
@@ -151,12 +150,18 @@ def text2audio(
151
  gr.update(visible = True, value = "Start again to get a different result. The output have been generated in " + ((str(hours) + " h, ") if hours != 0 else "") + ((str(minutes) + " min, ") if hours != 0 or minutes != 0 else "") + str(secondes) + " sec.")
152
  ]
153
 
 
 
 
 
 
 
154
  # Gradio interface
155
  with gr.Blocks() as interface:
156
  gr.Markdown("""
157
  <p style="text-align: center;">
158
  <b><big><big><big>Text-to-Audio</big></big></big></b>
159
- <br/>Generates 10 seconds of sound effects from description, freely, without account, without watermark.
160
  </p>
161
  <br/>
162
  <br/>
@@ -167,7 +172,7 @@ with gr.Blocks() as interface:
167
  <li>If you need to generate <b>music</b>, I recommend to use <i>MusicGen</i>,</li>
168
  </ul>
169
  <br/>
170
- """ + ("πŸƒβ€β™€οΈ Estimated time: few minutes." if torch.cuda.is_available() else "🐌 Slow process... ~5 min.") + """
171
  Your computer must <b><u>not</u></b> enter into standby mode.<br/>You can duplicate this space on a free account, it's designed to work on CPU, GPU and ZeroGPU.<br/>
172
  <a href='https://huggingface.co/spaces/Fabrice-TIERCELIN/Text-to-Audio?duplicate=true&hidden=public&hidden=public'><img src='https://img.shields.io/badge/-Duplicate%20Space-blue?labelColor=white&style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAP5JREFUOE+lk7FqAkEURY+ltunEgFXS2sZGIbXfEPdLlnxJyDdYB62sbbUKpLbVNhyYFzbrrA74YJlh9r079973psed0cvUD4A+4HoCjsA85X0Dfn/RBLBgBDxnQPfAEJgBY+A9gALA4tcbamSzS4xq4FOQAJgCDwV2CPKV8tZAJcAjMMkUe1vX+U+SMhfAJEHasQIWmXNN3abzDwHUrgcRGmYcgKe0bxrblHEB4E/pndMazNpSZGcsZdBlYJcEL9Afo75molJyM2FxmPgmgPqlWNLGfwZGG6UiyEvLzHYDmoPkDDiNm9JR9uboiONcBXrpY1qmgs21x1QwyZcpvxt9NS09PlsPAAAAAElFTkSuQmCC&logoWidth=14'></a>
173
  <br/>
 
115
  gr.update(visible = False)
116
  ]
117
 
 
118
  def text2audio(
119
  prompt,
120
  output_number,
 
150
  gr.update(visible = True, value = "Start again to get a different result. The output have been generated in " + ((str(hours) + " h, ") if hours != 0 else "") + ((str(minutes) + " min, ") if hours != 0 or minutes != 0 else "") + str(secondes) + " sec.")
151
  ]
152
 
153
+ try:
154
+ # Only on HuggingFace
155
+ text2audio = spaces.GPU(text2audio, duration = 420)
156
+ except Error:
157
+ text2audio = text2audio
158
+
159
  # Gradio interface
160
  with gr.Blocks() as interface:
161
  gr.Markdown("""
162
  <p style="text-align: center;">
163
  <b><big><big><big>Text-to-Audio</big></big></big></b>
164
+ <br/>Generates 10 seconds of sound effects from description, freely, without account, without watermark
165
  </p>
166
  <br/>
167
  <br/>
 
172
  <li>If you need to generate <b>music</b>, I recommend to use <i>MusicGen</i>,</li>
173
  </ul>
174
  <br/>
175
+ """ + ("πŸƒβ€β™€οΈ Estimated time: few minutes. Current device: GPU." if torch.cuda.is_available() else "🐌 Slow process... ~5 min. Current device: CPU.") + """
176
  Your computer must <b><u>not</u></b> enter into standby mode.<br/>You can duplicate this space on a free account, it's designed to work on CPU, GPU and ZeroGPU.<br/>
177
  <a href='https://huggingface.co/spaces/Fabrice-TIERCELIN/Text-to-Audio?duplicate=true&hidden=public&hidden=public'><img src='https://img.shields.io/badge/-Duplicate%20Space-blue?labelColor=white&style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAP5JREFUOE+lk7FqAkEURY+ltunEgFXS2sZGIbXfEPdLlnxJyDdYB62sbbUKpLbVNhyYFzbrrA74YJlh9r079973psed0cvUD4A+4HoCjsA85X0Dfn/RBLBgBDxnQPfAEJgBY+A9gALA4tcbamSzS4xq4FOQAJgCDwV2CPKV8tZAJcAjMMkUe1vX+U+SMhfAJEHasQIWmXNN3abzDwHUrgcRGmYcgKe0bxrblHEB4E/pndMazNpSZGcsZdBlYJcEL9Afo75molJyM2FxmPgmgPqlWNLGfwZGG6UiyEvLzHYDmoPkDDiNm9JR9uboiONcBXrpY1qmgs21x1QwyZcpvxt9NS09PlsPAAAAAElFTkSuQmCC&logoWidth=14'></a>
178
  <br/>