thomasanto7001 commited on
Commit
f324360
·
verified ·
1 Parent(s): cc790c1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -60
app.py CHANGED
@@ -1,60 +0,0 @@
1
- from groq import Groq
2
- import gradio as gr
3
- from gtts import gTTS
4
-
5
- # 🗝️ Your Groq API Key
6
- client = Groq(api_key="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")
7
-
8
- # 🧠 System prompt for mythological storytelling
9
- def initialize_messages():
10
- return [{"role": "system",
11
- "content": "You are a talented mythological storyteller. Tell short, engaging Indian mythology stories in a simple, emotional style. End every story with a moral."}]
12
-
13
- messages_prmt = initialize_messages()
14
-
15
- # 💬 LLM + Text-to-Speech logic
16
- def generate_story(user_input):
17
- global messages_prmt
18
-
19
- messages_prmt.append({"role": "user", "content": user_input})
20
-
21
- response = client.chat.completions.create(
22
- messages=messages_prmt,
23
- model="llama3-8b-8192",
24
- )
25
-
26
- story = response.choices[0].message.content
27
- messages_prmt.append({"role": "assistant", "content": story})
28
-
29
- # 🎧 Convert story to audio
30
- tts = gTTS(story)
31
- audio_path = "story.mp3"
32
- tts.save(audio_path)
33
-
34
- return story, audio_path
35
-
36
- # 🎨 Modern, clean UI using gr.Blocks
37
- with gr.Blocks(theme=gr.themes.Soft()) as app:
38
- gr.Markdown(
39
- """
40
- # 🕉️ **Mythology Storyteller Bot**
41
- _Get engaging Indian mythology stories with a moral. Now with audio playback!_
42
- """
43
- )
44
-
45
- with gr.Row():
46
- with gr.Column(scale=2):
47
- user_input = gr.Textbox(
48
- placeholder="Ask for a mythological story (e.g., Tell me a story about Hanuman)",
49
- label="Your Prompt",
50
- lines=2
51
- )
52
- generate_btn = gr.Button("🪄 Generate Story", size="lg")
53
-
54
- with gr.Column(scale=3):
55
- story_output = gr.Textbox(label="📜 Generated Story", lines=8, interactive=False)
56
- audio_output = gr.Audio(label="🔊 Listen to the Story", autoplay=True)
57
-
58
- generate_btn.click(fn=generate_story, inputs=user_input, outputs=[story_output, audio_output])
59
-
60
- app.launch(share=True)