Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -5,10 +5,29 @@ from langchain import PromptTemplate
|
|
5 |
from langchain.chains import LLMChain
|
6 |
from langchain.llms import OpenAI
|
7 |
|
|
|
|
|
8 |
openai_api_key = os.environ.get("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(
|
@@ -18,7 +37,15 @@ def generate_story(text):
|
|
18 |
"""
|
19 |
)
|
20 |
story = LLMChain(llm=llm, prompt=prompt)
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
def app(text):
|
24 |
story = generate_story(text)
|
@@ -28,6 +55,7 @@ with gr.Blocks() as demo:
|
|
28 |
with gr.Column():
|
29 |
text = gr.Textbox()
|
30 |
submit_btn = gr.Button('Submit')
|
|
|
31 |
story = gr.Textbox()
|
32 |
|
33 |
submit_btn.click(fn=app, inputs=[text], outputs=[story])
|
|
|
5 |
from langchain.chains import LLMChain
|
6 |
from langchain.llms import OpenAI
|
7 |
|
8 |
+
eleven = gr.Blocks.load(name="spaces/elevenlabs/tts")
|
9 |
+
|
10 |
openai_api_key = os.environ.get("OPENAI_API_KEY")
|
11 |
|
12 |
llm = OpenAI(temperature=0.9)
|
13 |
|
14 |
+
def split_text(text, max_length):
|
15 |
+
chunks = []
|
16 |
+
current_chunk = ''
|
17 |
+
words = text.split()
|
18 |
+
|
19 |
+
for word in words:
|
20 |
+
if len(current_chunk) + len(word) <= max_length:
|
21 |
+
current_chunk += ' ' + word
|
22 |
+
else:
|
23 |
+
chunks.append(current_chunk.strip())
|
24 |
+
current_chunk = word
|
25 |
+
|
26 |
+
if current_chunk:
|
27 |
+
chunks.append(current_chunk.strip())
|
28 |
+
|
29 |
+
return chunks
|
30 |
+
|
31 |
def generate_story(text):
|
32 |
"""Generate a story using the langchain library and OpenAI's GPT-3 model."""
|
33 |
prompt = PromptTemplate(
|
|
|
37 |
"""
|
38 |
)
|
39 |
story = LLMChain(llm=llm, prompt=prompt)
|
40 |
+
story_result = story.run(text=text)
|
41 |
+
|
42 |
+
max_length = 250
|
43 |
+
|
44 |
+
text_chunks = split_text(large_text, max_length)
|
45 |
+
for chunk in text_chunks:
|
46 |
+
print(chunk)
|
47 |
+
|
48 |
+
return story_result
|
49 |
|
50 |
def app(text):
|
51 |
story = generate_story(text)
|
|
|
55 |
with gr.Column():
|
56 |
text = gr.Textbox()
|
57 |
submit_btn = gr.Button('Submit')
|
58 |
+
audio = gr.Audio()
|
59 |
story = gr.Textbox()
|
60 |
|
61 |
submit_btn.click(fn=app, inputs=[text], outputs=[story])
|