fffiloni commited on
Commit
9ac6b43
1 Parent(s): cad988b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+
4
+ from langchain import PromptTemplate
5
+ from langchain.chains import LLMChain
6
+ from langchain.llms import OpenAI
7
+
8
+ openai_api_key = os.environ("OPENAI_API_KEY")
9
+
10
+ llm = OpenAI(temperature=0.9)
11
+
12
+ def generate_story(text):
13
+ """Generate a story using the langchain library and OpenAI's GPT-3 model."""
14
+ prompt = PromptTemplate(
15
+ input_variables=["text"],
16
+ template="""
17
+ You are a fun and seasoned storyteller. Generate a story for me about {text}.
18
+ """
19
+ )
20
+ story = LLMChain(llm=llm, prompt=prompt)
21
+ return story.run(text=text)
22
+
23
+ def generate_audio(text, voice):
24
+ """Convert the generated story to audio using the Eleven Labs API."""
25
+ audio = generate(text=text, voice=voice, api_key=eleven_api_key)
26
+ return audio
27
+
28
+ def generate_images(story_text):
29
+ """Generate images using the story text using the Replicate API."""
30
+ output = replicate.run(
31
+ "stability-ai/stable-diffusion:db21e45d3f7023abc2a46ee38a23973f6dce16bb082a930b0c49861f96d1e5bf",
32
+ input={"prompt": story_text}
33
+ )
34
+ return output
35
+
36
+ def app(text):
37
+ story = generate_story(text)
38
+ return story
39
+