Jayahae commited on
Commit
7e279b4
1 Parent(s): 098de07

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -0
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Import necessary libraries
2
+ import gradio as gr
3
+ from gtts import gTTS
4
+
5
+ # Define the text-to-speech function
6
+ def text_to_speech(text):
7
+ tts = gTTS(text)
8
+ tts.save("output.mp3")
9
+ return "output.mp3"
10
+
11
+ # Predefined sentences
12
+ sentences = [
13
+ "In a small coastal town edged by jagged cliffs and vast, open sea, stood an old lighthouse that had guarded the mariners for generations.",
14
+ "The lighthouse keeper, Mr. Elias, was an elderly man who had spent many years ensuring the light never failed, keeping ships safe from the dangerous rocks below.",
15
+ "Elias's grandson, Jamie, loved to visit the lighthouse.",
16
+ "He was fascinated by the stories his grandfather told of ships from distant lands and the many storms the lighthouse had withstood.",
17
+ "However, over the years, fewer ships passed by, and the town council questioned the need to keep the lighthouse operational.",
18
+ "They proposed using modern technology, which was cheaper and required less maintenance.",
19
+ "One evening, as a fierce storm brewed, the council decided to test their new electronic navigation system, planning to retire the old lighthouse lamp after proving the new system's efficiency.",
20
+ "Elias was heartbroken but knew he had to comply.",
21
+ "That night, with the storm at its peak and the new system in place, the unthinkable happened—the electronic system failed due to the severe weather conditions."
22
+ "In a panic, the town council realized their error. Without the lighthouse’s beam, ships at sea would be in grave danger.",
23
+ "They rushed to Elias, asking for his help. Elias turned to Jamie, handing him a small, old lantern — a backup they had never thought they’d use.",
24
+ "Hurry, take this to the top! It isn’t as bright, but it might just guide them in until we can fix the main light.",
25
+ "Braving the howling wind and pelting rain, Jamie climbed the winding stairs of the lighthouse with the lantern.",
26
+ "Reaching the top, he held the lantern high, its light flickering but steady. All he could do was hope it was enough.",
27
+ "Miraculously, the small light was seen by a nearby ship. The captain, familiar with the lighthouse’s position, navigated away from the cliffs just in time, guiding the ship safely into the harbor.",
28
+ "The town breathed a sigh of relief, and the council members were humbled by their near-disastrous decision.",
29
+ "From that day on, the council reinstated the old lighthouse, restoring it and even enhancing its light to ensure higher visibility.",
30
+ "Jamie learned the importance of resilience and tradition, and he took great pride in helping his grandfather.",
31
+ "Inspired by the event, he started learning more about navigational technology, combining new methods with the reliable old ways.",
32
+ "Years later, Jamie became the lighthouse keeper, just like his grandfather.",
33
+ "He maintained the tradition of the lighthouse while integrating modern technology responsibly, ensuring that the lighthouse continued to be a beacon of safety and a symbol of the town’s enduring spirit.",
34
+ "The story of the lighthouse keeper’s lantern became a cherished tale, reminding everyone that sometimes, the simplest solutions are the most effective in times of need.",
35
+ "It taught the town the value of wisdom, experience, and the importance of blending the old with the new to navigate the future safely."
36
+ ]
37
+
38
+ # Create the Gradio interface
39
+ interface = gr.Interface(
40
+ fn=text_to_speech,
41
+ inputs=gr.Dropdown(choices=sentences, label="Select a sentence"),
42
+ outputs=gr.Audio(type="filepath"),
43
+ title="Text-to-Speech App",
44
+ description="Select a sentence and hear it read aloud using Google Text-to-Speech."
45
+ )
46
+
47
+ # Launch the interface
48
+ interface.launch()