Spaces:
Sleeping
Sleeping
Commit
·
818da35
1
Parent(s):
7e41912
Initial
Browse files
app.py
CHANGED
@@ -5,13 +5,26 @@ import os
|
|
5 |
client = OpenAI(api_key=os.environ['OPENAI_API_KEY'])
|
6 |
|
7 |
|
8 |
-
def generate_story(topic):
|
9 |
-
prompt = f"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
response = client.chat.completions.create(
|
11 |
-
model="gpt-4.5-preview
|
12 |
messages=[{"role": "user", "content": prompt}],
|
13 |
-
max_tokens=
|
14 |
-
temperature=0.
|
15 |
)
|
16 |
story = response.choices[0].message.content.strip()
|
17 |
return story
|
@@ -19,10 +32,13 @@ def generate_story(topic):
|
|
19 |
|
20 |
iface = gr.Interface(
|
21 |
fn=generate_story,
|
22 |
-
inputs=
|
|
|
|
|
|
|
23 |
outputs=gr.Textbox(label="Generated Story"),
|
24 |
-
title="✨
|
25 |
-
description="Enter a topic
|
26 |
)
|
27 |
|
28 |
iface.launch()
|
|
|
5 |
client = OpenAI(api_key=os.environ['OPENAI_API_KEY'])
|
6 |
|
7 |
|
8 |
+
def generate_story(topic, language):
|
9 |
+
prompt = f"""You are a professional storyteller. Your task is to take any given topic and creatively transform it into an engaging, captivating, and imaginative fairy tale, preserving the core elements and characteristics of the original subject. Your fairy tale should have a clear structure:
|
10 |
+
|
11 |
+
Introduction: Set the scene, describe the setting, and introduce the main characters.
|
12 |
+
|
13 |
+
Development: Narrate the adventures, challenges, or conflicts faced by the characters.
|
14 |
+
|
15 |
+
Conclusion: Present a resolution or moral lesson derived from the characters' experiences.
|
16 |
+
|
17 |
+
Use a vivid, fluid, and warm narrative style that draws the audience into the story.
|
18 |
+
|
19 |
+
Now, create a fairy tale based on the following topic in {language}:
|
20 |
+
|
21 |
+
Topic: {topic}
|
22 |
+
"""
|
23 |
response = client.chat.completions.create(
|
24 |
+
model="gpt-4.5-preview",
|
25 |
messages=[{"role": "user", "content": prompt}],
|
26 |
+
max_tokens=2048,
|
27 |
+
temperature=0.1
|
28 |
)
|
29 |
story = response.choices[0].message.content.strip()
|
30 |
return story
|
|
|
32 |
|
33 |
iface = gr.Interface(
|
34 |
fn=generate_story,
|
35 |
+
inputs=[
|
36 |
+
gr.Textbox(label="Story Topic", placeholder="E.g., Adventures of a brave rabbit..."),
|
37 |
+
gr.Radio(label="Language", choices=["English", "French", "Turkish"], value="English")
|
38 |
+
],
|
39 |
outputs=gr.Textbox(label="Generated Story"),
|
40 |
+
title="✨ UmaiMother ✨",
|
41 |
+
description="Enter a topic and select a language, then a fun story will be automatically generated for you!"
|
42 |
)
|
43 |
|
44 |
iface.launch()
|