Ansa12 commited on
Commit
7903146
Β·
verified Β·
1 Parent(s): b9b7294

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -15
app.py CHANGED
@@ -4,7 +4,9 @@ import gradio as gr
4
  from gtts import gTTS
5
  import re
6
 
7
- # Get API key from Hugging Face Secrets
 
 
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("πŸ‘Ά *Child's Age*")
204
  age_input = gr.Dropdown(age_options, value="5", show_label=False)
205
 
206
  with gr.Group():
207
- gr.Markdown("🎭 *Story Theme*")
208
  theme_input = gr.Dropdown(theme_options, value="Adventure", show_label=False)
209
 
210
  with gr.Group():
211
- gr.Markdown("🌍 *Language*")
212
  language_input = gr.Dropdown(language_options, value="English", show_label=False)
213
 
214
  with gr.Group():
215
- gr.Markdown("πŸ”Š *Audio Options*")
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 __name__ == "__main__":
242
- iface.launch()
 
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()