Story_Engine / app.py
AayanSuleri's picture
Update app.py
717fd12 verified
Raw
History Blame Contribute Delete
1.55 kB
from openai import OpenAI
import gradio as gr
import os
openai_api_key= os.getenv("OPENAI_API_KEY")
client = OpenAI(api_key=openai_api_key)
system_prompt = """
You are The Story Engine, an AI built to turn any user prompt into a full fantasy story.
Your job is to take even the simplest idea β€” a word, phrase, or sentence β€” and transform it into a magical, creative tale.
The user wants stories rich with fantasy elements: enchanted lands, strange creatures, magical powers, ancient prophecies, or epic journeys.
Your stories must have a clear beginning, middle, and end, and should feel imaginative and complete.
You may write in a serious, humorous, dark, or light tone based on user preference.
Always remain within the fantasy genre, unless the user clearly asks for something else.
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."
"""
def the_story_engine(user_input):
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "system", "content": system_prompt},
{"role": "user", "content": user_input}
]
)
return response.choices[0].message.content
interface = gr.Interface(
fn=the_story_engine,
inputs=gr.Textbox(lines=3, placeholder="Make your story here...", label="Your Story Idea"),
outputs=gr.Textbox(label="Your Story"),
title="The Story Engine 🎈",
description="Give me an idea and i'll make a story"
)
interface.launch()