Spaces:
Sleeping
Sleeping
Commit
·
df4b649
1
Parent(s):
ac7470d
Initial
Browse files- app.py +18 -5
- requirements.txt +1 -0
app.py
CHANGED
|
@@ -1,13 +1,15 @@
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
from openai import OpenAI
|
|
|
|
|
|
|
| 4 |
|
| 5 |
client = OpenAI(api_key=os.environ['OPENAI_API_KEY'])
|
| 6 |
|
| 7 |
|
| 8 |
def generate_story(password, topic, language):
|
| 9 |
if password != os.environ.get("PASSWORD"):
|
| 10 |
-
return "Incorrect password!"
|
| 11 |
|
| 12 |
prompt = f"""You are a professional storyteller. Your task is to take any given topic and creatively transform it
|
| 13 |
into an engaging, captivating, and imaginative fairy tale, preserving the core elements and characteristics of the
|
|
@@ -33,19 +35,30 @@ Topic: {topic}
|
|
| 33 |
temperature=0.5
|
| 34 |
)
|
| 35 |
story = response.choices[0].message.content.strip()
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
|
| 39 |
iface = gr.Interface(
|
| 40 |
fn=generate_story,
|
| 41 |
inputs=[
|
| 42 |
-
gr.Textbox(label="Story Topic", placeholder="e.g., The adventures of a brave rabbit..."),
|
| 43 |
gr.Textbox(label="Password", type="password", placeholder="Enter your password..."),
|
|
|
|
| 44 |
gr.Radio(label="Language", choices=["French", "English", "Turkish"], value="English")
|
| 45 |
],
|
| 46 |
-
outputs=
|
|
|
|
|
|
|
|
|
|
| 47 |
title="✨ UmaiMother ✨",
|
| 48 |
-
description="Please enter the correct password, specify the story topic and choose a language."
|
| 49 |
)
|
| 50 |
|
| 51 |
iface.launch()
|
|
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
from openai import OpenAI
|
| 4 |
+
from gtts import gTTS
|
| 5 |
+
import tempfile
|
| 6 |
|
| 7 |
client = OpenAI(api_key=os.environ['OPENAI_API_KEY'])
|
| 8 |
|
| 9 |
|
| 10 |
def generate_story(password, topic, language):
|
| 11 |
if password != os.environ.get("PASSWORD"):
|
| 12 |
+
return "Incorrect password!", None
|
| 13 |
|
| 14 |
prompt = f"""You are a professional storyteller. Your task is to take any given topic and creatively transform it
|
| 15 |
into an engaging, captivating, and imaginative fairy tale, preserving the core elements and characteristics of the
|
|
|
|
| 35 |
temperature=0.5
|
| 36 |
)
|
| 37 |
story = response.choices[0].message.content.strip()
|
| 38 |
+
|
| 39 |
+
lang_code = {"English": "en", "French": "fr", "Turkish": "tr"}.get(language, "en")
|
| 40 |
+
|
| 41 |
+
tts = gTTS(text=story, lang=lang_code)
|
| 42 |
+
|
| 43 |
+
audio_file = tempfile.NamedTemporaryFile(delete=False, suffix=".mp3")
|
| 44 |
+
tts.save(audio_file.name)
|
| 45 |
+
|
| 46 |
+
return story, audio_file.name
|
| 47 |
|
| 48 |
|
| 49 |
iface = gr.Interface(
|
| 50 |
fn=generate_story,
|
| 51 |
inputs=[
|
|
|
|
| 52 |
gr.Textbox(label="Password", type="password", placeholder="Enter your password..."),
|
| 53 |
+
gr.Textbox(label="Story Topic", placeholder="e.g., The adventures of a brave rabbit..."),
|
| 54 |
gr.Radio(label="Language", choices=["French", "English", "Turkish"], value="English")
|
| 55 |
],
|
| 56 |
+
outputs=[
|
| 57 |
+
gr.Textbox(label="Generated Story"),
|
| 58 |
+
gr.Audio(label="Listen to the Story", type="filepath")
|
| 59 |
+
],
|
| 60 |
title="✨ UmaiMother ✨",
|
| 61 |
+
description="Please enter the correct password, specify the story topic, and choose a language."
|
| 62 |
)
|
| 63 |
|
| 64 |
iface.launch()
|
requirements.txt
CHANGED
|
@@ -1,2 +1,3 @@
|
|
| 1 |
gradio
|
| 2 |
openai
|
|
|
|
|
|
| 1 |
gradio
|
| 2 |
openai
|
| 3 |
+
gTTS
|