BedtimeStory / app.py
fffiloni's picture
Update app.py
af74651
raw
history blame
1.24 kB
import os
import gradio as gr
from langchain import PromptTemplate
from langchain.chains import LLMChain
from langchain.llms import OpenAI
openai_api_key = os.environ("OPENAI_API_KEY")
llm = OpenAI(temperature=0.9)
def generate_story(text):
"""Generate a story using the langchain library and OpenAI's GPT-3 model."""
prompt = PromptTemplate(
input_variables=["text"],
template="""
You are a fun and seasoned storyteller. Generate a story for me about {text}.
"""
)
story = LLMChain(llm=llm, prompt=prompt)
return story.run(text=text)
def generate_audio(text, voice):
"""Convert the generated story to audio using the Eleven Labs API."""
audio = generate(text=text, voice=voice, api_key=eleven_api_key)
return audio
def generate_images(story_text):
"""Generate images using the story text using the Replicate API."""
output = replicate.run(
"stability-ai/stable-diffusion:db21e45d3f7023abc2a46ee38a23973f6dce16bb082a930b0c49861f96d1e5bf",
input={"prompt": story_text}
)
return output
def app(text):
story = generate_story(text)
return story
gr.Interface(fn=app, inputs=[gr.Textbox()], outputs=[gr.Textbox()]).launch()