Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from openai import OpenAI
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
OPENAI_API_KEY = "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"
|
| 5 |
+
client = OpenAI(api_key=OPENAI_API_KEY)
|
| 6 |
+
|
| 7 |
+
system_prompt = """
|
| 8 |
+
You are The Story Engine, an AI built to turn any user prompt into a full fantasy story.
|
| 9 |
+
Your job is to take even the simplest idea — a word, phrase, or sentence — and transform it into a magical, creative tale.
|
| 10 |
+
The user wants stories rich with fantasy elements: enchanted lands, strange creatures, magical powers, ancient prophecies, or epic journeys.
|
| 11 |
+
Your stories must have a clear beginning, middle, and end, and should feel imaginative and complete.
|
| 12 |
+
You may write in a serious, humorous, dark, or light tone based on user preference.
|
| 13 |
+
Always remain within the fantasy genre, unless the user clearly asks for something else.
|
| 14 |
+
If the input is too vague or empty to build a story from, politely ask the user to give a bit more detail or a clearer fantasy idea to begin with."
|
| 15 |
+
"""
|
| 16 |
+
|
| 17 |
+
def the_story_engine(user_input):
|
| 18 |
+
response = client.chat.completions.create(
|
| 19 |
+
model="gpt-4o-mini",
|
| 20 |
+
messages=[
|
| 21 |
+
{"role": "system", "content": system_prompt},
|
| 22 |
+
{"role": "user", "content": user_input}
|
| 23 |
+
]
|
| 24 |
+
)
|
| 25 |
+
return response.choices[0].message.content
|
| 26 |
+
|
| 27 |
+
interface = gr.Interface(
|
| 28 |
+
fn=the_story_engine,
|
| 29 |
+
inputs=gr.Textbox(lines=3, placeholder="Make your story here...", label="Your Story Idea"),
|
| 30 |
+
outputs=gr.Textbox(label="Your Story"),
|
| 31 |
+
title="The Story Engine 🎈",
|
| 32 |
+
description="Give me an idea and i'll make a story"
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
interface.launch()
|