Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from gtts import gTTS
|
| 3 |
-
import os
|
| 4 |
from io import BytesIO
|
| 5 |
|
| 6 |
def text_to_speech(text, language="en"):
|
|
@@ -20,7 +19,7 @@ def text_to_speech(text, language="en"):
|
|
| 20 |
except Exception as e:
|
| 21 |
return f"Error: {str(e)}", None
|
| 22 |
|
| 23 |
-
#
|
| 24 |
html_content = """
|
| 25 |
<!DOCTYPE html>
|
| 26 |
<html lang="en">
|
|
@@ -169,11 +168,15 @@ html_content = """
|
|
| 169 |
// Show loading status
|
| 170 |
statusDiv.innerHTML = "Converting... Please wait.";
|
| 171 |
|
| 172 |
-
//
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
audioPlayer.style.display = "block";
|
| 178 |
|
| 179 |
// Show success popup using SweetAlert2
|
|
@@ -182,30 +185,19 @@ html_content = """
|
|
| 182 |
title: 'Conversion Successful!',
|
| 183 |
text: 'Your text has been converted to speech.',
|
| 184 |
});
|
| 185 |
-
}
|
|
|
|
|
|
|
|
|
|
| 186 |
}
|
| 187 |
</script>
|
| 188 |
</body>
|
| 189 |
</html>
|
| 190 |
"""
|
| 191 |
|
| 192 |
-
# Gradio interface setup
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
],
|
| 199 |
-
outputs=[
|
| 200 |
-
gr.Textbox(label="Status"),
|
| 201 |
-
gr.Audio(label="Generated Speech"),
|
| 202 |
-
],
|
| 203 |
-
title="AI Text-to-Speech Web App",
|
| 204 |
-
description="Convert text into natural-sounding speech using AI. Select a language, type text, and download the audio!",
|
| 205 |
-
allow_flagging="never",
|
| 206 |
-
live=True,
|
| 207 |
-
)
|
| 208 |
-
|
| 209 |
-
# Launch the interface
|
| 210 |
-
if __name__ == "__main__":
|
| 211 |
-
interface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from gtts import gTTS
|
|
|
|
| 3 |
from io import BytesIO
|
| 4 |
|
| 5 |
def text_to_speech(text, language="en"):
|
|
|
|
| 19 |
except Exception as e:
|
| 20 |
return f"Error: {str(e)}", None
|
| 21 |
|
| 22 |
+
# HTML content with animations, styling, and JavaScript
|
| 23 |
html_content = """
|
| 24 |
<!DOCTYPE html>
|
| 25 |
<html lang="en">
|
|
|
|
| 168 |
// Show loading status
|
| 169 |
statusDiv.innerHTML = "Converting... Please wait.";
|
| 170 |
|
| 171 |
+
// Call the backend to get the audio file (we simulate it here)
|
| 172 |
+
fetch('/convert', {
|
| 173 |
+
method: 'POST',
|
| 174 |
+
body: JSON.stringify({ text: text, language: language }),
|
| 175 |
+
headers: { 'Content-Type': 'application/json' }
|
| 176 |
+
})
|
| 177 |
+
.then(response => response.blob())
|
| 178 |
+
.then(blob => {
|
| 179 |
+
audioPlayer.src = URL.createObjectURL(blob);
|
| 180 |
audioPlayer.style.display = "block";
|
| 181 |
|
| 182 |
// Show success popup using SweetAlert2
|
|
|
|
| 185 |
title: 'Conversion Successful!',
|
| 186 |
text: 'Your text has been converted to speech.',
|
| 187 |
});
|
| 188 |
+
})
|
| 189 |
+
.catch(error => {
|
| 190 |
+
statusDiv.innerHTML = "Error: Could not convert text to speech.";
|
| 191 |
+
});
|
| 192 |
}
|
| 193 |
</script>
|
| 194 |
</body>
|
| 195 |
</html>
|
| 196 |
"""
|
| 197 |
|
| 198 |
+
# Gradio interface setup for integrating frontend
|
| 199 |
+
def gradio_interface():
|
| 200 |
+
return gr.HTML(html_content)
|
| 201 |
+
|
| 202 |
+
interface = gr.Interface(fn=text_to_speech, inputs=[gr.Textbox(), gr.Dropdown()], outputs=[gr.Textbox(), gr.Audio()])
|
| 203 |
+
interface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|