Updating it
Browse files
app.py
DELETED
|
@@ -1,112 +0,0 @@
|
|
| 1 |
-
"""Kids Rhyme Studio: simple, four-language Gradio app."""
|
| 2 |
-
|
| 3 |
-
from audio_engine import make_sung_song
|
| 4 |
-
from dataclasses import asdict
|
| 5 |
-
import gradio as gr
|
| 6 |
-
from rhyme_engine import parse_request, validate_lyric_for_audio, write_rhyme
|
| 7 |
-
from themes import THEME_CHOICES
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
CSS = """
|
| 11 |
-
.gradio-container {max-width: 1100px !important; margin: auto !important;}
|
| 12 |
-
#hero {background: linear-gradient(120deg,#fff0f7,#fff6d5 72%,#e7f5ff);
|
| 13 |
-
border: 1px solid #ffdfe9; border-radius: 24px; padding: 24px 30px;
|
| 14 |
-
margin: 12px 0 20px;}
|
| 15 |
-
#hero h1 {font-size: clamp(2rem,5vw,3.5rem); margin: 0 0 8px; color:#42204d;}
|
| 16 |
-
#hero p {font-size: 1.09rem; margin: 0; color:#584a61;}
|
| 17 |
-
#instruction {margin: 2px 0 8px; color:#5d5061;}
|
| 18 |
-
#make-rhyme, #make-audio {border-radius: 12px !important; font-weight: 700;}
|
| 19 |
-
#lyrics textarea {line-height: 1.9; font-size: 1.06rem;}
|
| 20 |
-
"""
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
def create_rhyme(name, words, goal, language, mood, theme, use_ai):
|
| 24 |
-
try:
|
| 25 |
-
req = parse_request(name, words, goal, language, mood, theme)
|
| 26 |
-
except ValueError as exc:
|
| 27 |
-
raise gr.Error(str(exc)) from exc
|
| 28 |
-
rhyme, writer = write_rhyme(req, use_ai)
|
| 29 |
-
return rhyme, asdict(req), f"✨ {language} rhyme ready · {theme} ({writer}). You can edit it, then sing it.", None
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
def create_audio(lyrics, settings, name, words, goal, language, mood, theme):
|
| 33 |
-
try:
|
| 34 |
-
if not settings:
|
| 35 |
-
raise ValueError("Write a rhyme first, then make its song.")
|
| 36 |
-
req = parse_request(name, words, goal, language, mood, theme)
|
| 37 |
-
if asdict(req) != settings:
|
| 38 |
-
raise ValueError("Your options changed. Click Make my rhyme again so the lyrics match your language and theme.")
|
| 39 |
-
safe_lyrics = validate_lyric_for_audio(lyrics)
|
| 40 |
-
result, status = make_sung_song(safe_lyrics, req.language, req.mood, req.theme, req.goal)
|
| 41 |
-
return result, f"🎤 {language} · {theme} — {status}"
|
| 42 |
-
except (ValueError, RuntimeError) as exc:
|
| 43 |
-
raise gr.Error(str(exc)) from exc
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
with gr.Blocks(title="Kids Rhyme Studio") as demo:
|
| 47 |
-
gr.HTML("""
|
| 48 |
-
<section id="hero">
|
| 49 |
-
<h1>🎵 Kids Rhyme Studio</h1>
|
| 50 |
-
<p>Choose a theme, add favorite words, and make a little learning song.</p>
|
| 51 |
-
</section>
|
| 52 |
-
""")
|
| 53 |
-
gr.Markdown("**1. Add words → 2. Make a rhyme → 3. Sing and download**", elem_id="instruction")
|
| 54 |
-
|
| 55 |
-
settings = gr.State(value=None)
|
| 56 |
-
with gr.Row():
|
| 57 |
-
with gr.Column(scale=1):
|
| 58 |
-
name = gr.Textbox(label="Child's first name (optional)", placeholder="Maya", max_length=32)
|
| 59 |
-
words = gr.Textbox(label="Words to use (1–10)", placeholder="moon, bunny, stars, rainbow…",
|
| 60 |
-
info="Separate up to 10 words with commas. In Telugu, try Telugu words.",
|
| 61 |
-
max_length=300)
|
| 62 |
-
with gr.Row():
|
| 63 |
-
language = gr.Dropdown(["English", "Español", "తెలుగు", "Deutsch"],
|
| 64 |
-
value="English", label="Language")
|
| 65 |
-
mood = gr.Dropdown(["Bouncy", "Calm"], value="Bouncy", label="Music mood")
|
| 66 |
-
theme = gr.Dropdown(THEME_CHOICES, value="Good Habits", label="Song theme")
|
| 67 |
-
goal = gr.Textbox(label="Theme prompt (optional; required for Custom theme)",
|
| 68 |
-
placeholder="Teach washing hands before meals and putting toys away",
|
| 69 |
-
info="Use the chosen language for your words and prompt. Leave blank to use the theme's suggested lesson.",
|
| 70 |
-
lines=2, max_length=160)
|
| 71 |
-
with gr.Accordion("Optional: AI writer", open=False):
|
| 72 |
-
use_ai = gr.Checkbox(
|
| 73 |
-
label="Use AI for more varied lyrics",
|
| 74 |
-
info="If enabled, the name, words, theme, and prompt are sent to a hosted model. A Space token must be configured.",
|
| 75 |
-
value=False,
|
| 76 |
-
)
|
| 77 |
-
rhyme_button = gr.Button("✨ Make my rhyme", variant="primary", elem_id="make-rhyme")
|
| 78 |
-
gr.Examples(
|
| 79 |
-
examples=[
|
| 80 |
-
["Maya", "soap, toothbrush, toys", "", "English", "Bouncy", "Good Habits"],
|
| 81 |
-
["Maya", "moon, bunny, stars, rainbow, puddle, pencil, apple, rocket, kitten, garden",
|
| 82 |
-
"", "English", "Bouncy", "Animals & Nature"],
|
| 83 |
-
["Sofía", "luna, conejo, estrellas", "", "Español", "Calm", "Bedtime"],
|
| 84 |
-
["అను", "చందమామ, బొమ్మ, నక్షత్రం", "", "తెలుగు", "Calm", "Bedtime"],
|
| 85 |
-
["Emil", "Apfel, Hase, Sterne", "", "Deutsch", "Bouncy", "Counting"],
|
| 86 |
-
["Maya", "bus, school, friends", "Feeling brave on the first day of school", "English", "Bouncy", "Custom theme"],
|
| 87 |
-
],
|
| 88 |
-
inputs=[name, words, goal, language, mood, theme],
|
| 89 |
-
label="Try an example",
|
| 90 |
-
)
|
| 91 |
-
with gr.Column(scale=1):
|
| 92 |
-
lyrics = gr.Textbox(label="Your rhyme • you can edit it", lines=13, max_lines=15,
|
| 93 |
-
buttons=["copy"], elem_id="lyrics")
|
| 94 |
-
audio_button = gr.Button("🎤 Sing my rhyme", elem_id="make-audio")
|
| 95 |
-
audio = gr.Audio(label="Sung song • listen or download WAV", interactive=False,
|
| 96 |
-
buttons=["download"])
|
| 97 |
-
status = gr.Markdown("Your rhyme will appear here. Song creation uses a GPU and may take a minute.")
|
| 98 |
-
|
| 99 |
-
gr.Markdown(
|
| 100 |
-
"<small>Made for playful practice. A parent should review each rhyme. "
|
| 101 |
-
"The song model sings the rhyme; pronunciation and exact words can vary. "
|
| 102 |
-
"Use a nickname; this app keeps no account or rhyme database.</small>"
|
| 103 |
-
)
|
| 104 |
-
|
| 105 |
-
rhyme_button.click(create_rhyme, [name, words, goal, language, mood, theme, use_ai],
|
| 106 |
-
[lyrics, settings, status, audio], concurrency_limit=2)
|
| 107 |
-
audio_button.click(create_audio, [lyrics, settings, name, words, goal, language, mood, theme],
|
| 108 |
-
[audio, status], concurrency_limit=1)
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
if __name__ == "__main__":
|
| 112 |
-
demo.queue().launch(theme=gr.themes.Soft(primary_hue="pink", secondary_hue="yellow"), css=CSS)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|