Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,7 +4,9 @@ import gradio as gr
|
|
| 4 |
from gtts import gTTS
|
| 5 |
import re
|
| 6 |
|
| 7 |
-
#
|
|
|
|
|
|
|
| 8 |
groq_key = os.environ.get("Groq_API_Key")
|
| 9 |
if not groq_key:
|
| 10 |
raise ValueError("Groq_API_Key not found in environment variables. Please add it to your Hugging Face Space secrets.")
|
|
@@ -46,7 +48,6 @@ def generate_story(age, theme, language):
|
|
| 46 |
|
| 47 |
return response.choices[0].message.content.strip()
|
| 48 |
|
| 49 |
-
|
| 50 |
# -------------------------------------------------------------
|
| 51 |
# TEXT TO SPEECH
|
| 52 |
# -------------------------------------------------------------
|
|
@@ -56,7 +57,6 @@ def story_to_speech(story, language_code="en"):
|
|
| 56 |
tts.save(filename)
|
| 57 |
return filename
|
| 58 |
|
| 59 |
-
|
| 60 |
# -------------------------------------------------------------
|
| 61 |
# PROCESS STORY + AUDIO
|
| 62 |
# -------------------------------------------------------------
|
|
@@ -86,7 +86,6 @@ def create_story_interface(age, theme, language, tts_option):
|
|
| 86 |
audio_file = story_to_speech(story, lang_code) if tts_option else None
|
| 87 |
return story_html, audio_file
|
| 88 |
|
| 89 |
-
|
| 90 |
# -------------------------------------------------------------
|
| 91 |
# UI OPTIONS
|
| 92 |
# -------------------------------------------------------------
|
|
@@ -98,7 +97,6 @@ theme_options = [
|
|
| 98 |
]
|
| 99 |
language_options = ["English", "Urdu"]
|
| 100 |
|
| 101 |
-
|
| 102 |
# -------------------------------------------------------------
|
| 103 |
# CUSTOM CSS
|
| 104 |
# -------------------------------------------------------------
|
|
@@ -181,13 +179,10 @@ custom_css = """
|
|
| 181 |
}
|
| 182 |
"""
|
| 183 |
|
| 184 |
-
|
| 185 |
# -------------------------------------------------------------
|
| 186 |
# BUILD GRADIO INTERFACE
|
| 187 |
# -------------------------------------------------------------
|
| 188 |
-
with gr.Blocks as iface:
|
| 189 |
-
|
| 190 |
-
# Inject CSS manually
|
| 191 |
gr.HTML(f"<style>{custom_css}</style>")
|
| 192 |
|
| 193 |
gr.HTML('<div class="main-header">π StoryTime AIπͺ</div>')
|
|
@@ -200,19 +195,19 @@ with gr.Blocks as iface:
|
|
| 200 |
gr.Markdown("### π¨ Story Settings")
|
| 201 |
|
| 202 |
with gr.Group():
|
| 203 |
-
gr.Markdown("πΆ
|
| 204 |
age_input = gr.Dropdown(age_options, value="5", show_label=False)
|
| 205 |
|
| 206 |
with gr.Group():
|
| 207 |
-
gr.Markdown("π
|
| 208 |
theme_input = gr.Dropdown(theme_options, value="Adventure", show_label=False)
|
| 209 |
|
| 210 |
with gr.Group():
|
| 211 |
-
gr.Markdown("π
|
| 212 |
language_input = gr.Dropdown(language_options, value="English", show_label=False)
|
| 213 |
|
| 214 |
with gr.Group():
|
| 215 |
-
gr.Markdown("π
|
| 216 |
tts_input = gr.Checkbox(label="π΅ Include Audio Story", value=True)
|
| 217 |
|
| 218 |
generate_btn = gr.Button("β¨ Create Magical Story! β¨", elem_classes="generate-btn")
|
|
@@ -238,5 +233,5 @@ with gr.Blocks as iface:
|
|
| 238 |
# -------------------------------------------------------------
|
| 239 |
# LAUNCH APP
|
| 240 |
# -------------------------------------------------------------
|
| 241 |
-
if
|
| 242 |
-
|
|
|
|
| 4 |
from gtts import gTTS
|
| 5 |
import re
|
| 6 |
|
| 7 |
+
# -------------------------------------------------------------
|
| 8 |
+
# GET API KEY
|
| 9 |
+
# -------------------------------------------------------------
|
| 10 |
groq_key = os.environ.get("Groq_API_Key")
|
| 11 |
if not groq_key:
|
| 12 |
raise ValueError("Groq_API_Key not found in environment variables. Please add it to your Hugging Face Space secrets.")
|
|
|
|
| 48 |
|
| 49 |
return response.choices[0].message.content.strip()
|
| 50 |
|
|
|
|
| 51 |
# -------------------------------------------------------------
|
| 52 |
# TEXT TO SPEECH
|
| 53 |
# -------------------------------------------------------------
|
|
|
|
| 57 |
tts.save(filename)
|
| 58 |
return filename
|
| 59 |
|
|
|
|
| 60 |
# -------------------------------------------------------------
|
| 61 |
# PROCESS STORY + AUDIO
|
| 62 |
# -------------------------------------------------------------
|
|
|
|
| 86 |
audio_file = story_to_speech(story, lang_code) if tts_option else None
|
| 87 |
return story_html, audio_file
|
| 88 |
|
|
|
|
| 89 |
# -------------------------------------------------------------
|
| 90 |
# UI OPTIONS
|
| 91 |
# -------------------------------------------------------------
|
|
|
|
| 97 |
]
|
| 98 |
language_options = ["English", "Urdu"]
|
| 99 |
|
|
|
|
| 100 |
# -------------------------------------------------------------
|
| 101 |
# CUSTOM CSS
|
| 102 |
# -------------------------------------------------------------
|
|
|
|
| 179 |
}
|
| 180 |
"""
|
| 181 |
|
|
|
|
| 182 |
# -------------------------------------------------------------
|
| 183 |
# BUILD GRADIO INTERFACE
|
| 184 |
# -------------------------------------------------------------
|
| 185 |
+
with gr.Blocks() as iface: # Removed theme argument
|
|
|
|
|
|
|
| 186 |
gr.HTML(f"<style>{custom_css}</style>")
|
| 187 |
|
| 188 |
gr.HTML('<div class="main-header">π StoryTime AIπͺ</div>')
|
|
|
|
| 195 |
gr.Markdown("### π¨ Story Settings")
|
| 196 |
|
| 197 |
with gr.Group():
|
| 198 |
+
gr.Markdown("πΆ Child's Age")
|
| 199 |
age_input = gr.Dropdown(age_options, value="5", show_label=False)
|
| 200 |
|
| 201 |
with gr.Group():
|
| 202 |
+
gr.Markdown("π Story Theme")
|
| 203 |
theme_input = gr.Dropdown(theme_options, value="Adventure", show_label=False)
|
| 204 |
|
| 205 |
with gr.Group():
|
| 206 |
+
gr.Markdown("π Language")
|
| 207 |
language_input = gr.Dropdown(language_options, value="English", show_label=False)
|
| 208 |
|
| 209 |
with gr.Group():
|
| 210 |
+
gr.Markdown("π Audio Options")
|
| 211 |
tts_input = gr.Checkbox(label="π΅ Include Audio Story", value=True)
|
| 212 |
|
| 213 |
generate_btn = gr.Button("β¨ Create Magical Story! β¨", elem_classes="generate-btn")
|
|
|
|
| 233 |
# -------------------------------------------------------------
|
| 234 |
# LAUNCH APP
|
| 235 |
# -------------------------------------------------------------
|
| 236 |
+
if _name_ == "_main_":
|
| 237 |
+
Β Β iface.launch()
|