Avoid error if spaces is not imported
Browse files
app.py
CHANGED
@@ -3,7 +3,11 @@ import json
|
|
3 |
import torch
|
4 |
import time
|
5 |
import random
|
6 |
-
|
|
|
|
|
|
|
|
|
7 |
|
8 |
from tqdm import tqdm
|
9 |
from huggingface_hub import snapshot_download
|
@@ -111,7 +115,6 @@ def update_output(output_format, output_number):
|
|
111 |
gr.update(visible = False)
|
112 |
]
|
113 |
|
114 |
-
@spaces.GPU(duration=420)
|
115 |
def text2audio(
|
116 |
prompt,
|
117 |
output_number,
|
@@ -147,12 +150,18 @@ def text2audio(
|
|
147 |
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.")
|
148 |
]
|
149 |
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
# Gradio interface
|
151 |
with gr.Blocks() as interface:
|
152 |
gr.Markdown("""
|
153 |
<p style="text-align: center;">
|
154 |
<b><big><big><big>Text-to-Audio</big></big></big></b>
|
155 |
-
<br/>Generates 10 seconds of sound effects from description, freely, without account, without watermark
|
156 |
</p>
|
157 |
<br/>
|
158 |
<br/>
|
@@ -163,7 +172,7 @@ with gr.Blocks() as interface:
|
|
163 |
<li>If you need to generate <b>music</b>, I recommend to use <i>MusicGen</i>,</li>
|
164 |
</ul>
|
165 |
<br/>
|
166 |
-
""" + ("πββοΈ Estimated time: few minutes." if torch.cuda.is_available() else "π Slow process... ~5 min.") + """
|
167 |
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/>
|
168 |
<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>
|
169 |
<br/>
|
|
|
3 |
import torch
|
4 |
import time
|
5 |
import random
|
6 |
+
try:
|
7 |
+
# Only on HuggingFace
|
8 |
+
import spaces
|
9 |
+
except ImportError:
|
10 |
+
"ignore"
|
11 |
|
12 |
from tqdm import tqdm
|
13 |
from huggingface_hub import snapshot_download
|
|
|
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/>
|