Spaces:
Sleeping
Sleeping
File size: 1,554 Bytes
f43610b e40bfc2 4e646d3 e73617e f43610b 717fd12 f43610b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | 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()
|