mirror of
https://github.com/Paillat-dev/FABLE.git
synced 2026-01-02 01:06:20 +00:00
feat(ideas.py): add support for generating ideas for a specific subject
feat(ideas.py): add support for appending new ideas to existing ideas.json file
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import openai
|
import openai
|
||||||
import os
|
import os
|
||||||
|
import json
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
||||||
@@ -10,16 +11,22 @@ with open('prompts/ideas.txt') as f:
|
|||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
|
||||||
async def generate_ideas():
|
async def generate_ideas(path):
|
||||||
with open('ideas/ideas.json', 'r') as f:
|
with open(f'{path}/ideas.json', 'r') as f:
|
||||||
ideas = f.read()
|
ideas = f.read()
|
||||||
|
ides_json = json.loads(ideas)
|
||||||
f.close()
|
f.close()
|
||||||
prmpt = prompt.replace('[existing ideas]', ideas)
|
prmpt = prompt.replace('[existing ideas]', ideas)
|
||||||
print(prmpt)
|
|
||||||
response = await openai.ChatCompletion.acreate(
|
response = await openai.ChatCompletion.acreate(
|
||||||
model="gpt-3.5-turbo",
|
model="gpt-3.5-turbo",
|
||||||
messages=[
|
messages=[
|
||||||
{"role":"user","content":prmpt},
|
{"role":"user","content":prmpt},
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
return response['choices'][0]['message']['content']
|
json_in_str= response['choices'][0]['message']['content']
|
||||||
|
json_obj = json.loads(json_in_str)
|
||||||
|
for idea in json_obj:
|
||||||
|
ides_json.append(idea)
|
||||||
|
with open(f'{path}/ideas.json', 'w') as f:
|
||||||
|
f.write(json.dumps(ides_json))
|
||||||
|
f.close()
|
||||||
16
main.py
16
main.py
@@ -11,11 +11,17 @@ from generators.miniature import generate_miniature
|
|||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
|
with open('env/subjects.txt', 'r', encoding='utf-8') as f:
|
||||||
|
subjects = f.read().splitlines()
|
||||||
|
f.close()
|
||||||
|
for i in range(len(subjects)):
|
||||||
|
print(str(i) + ". " + subjects[i])
|
||||||
|
subject = int(input("Which subject do you want to generate ideas for? (enter the number): "))
|
||||||
|
subject = subjects[subject]
|
||||||
|
subjectdirpath = subject[:25].replace(" ", "_").replace(":", "")
|
||||||
|
if not os.path.exists(subjectdirpath): os.makedirs(subjectdirpath)
|
||||||
if input("Do you want to generate new ideas? (y/n)") == "y":
|
if input("Do you want to generate new ideas? (y/n)") == "y":
|
||||||
ideas = await generate_ideas()
|
await generate_ideas(subjectdirpath)
|
||||||
if not os.path.exists('ideas'): os.makedirs('ideas')
|
|
||||||
with open('ideas/ideas.json', 'w', encoding='utf-8') as f:
|
|
||||||
f.write(ideas)
|
|
||||||
with open('ideas/ideas.json', 'r', encoding='utf-8') as f:
|
with open('ideas/ideas.json', 'r', encoding='utf-8') as f:
|
||||||
ideas = json.load(f)
|
ideas = json.load(f)
|
||||||
f.close()
|
f.close()
|
||||||
@@ -26,7 +32,7 @@ async def main():
|
|||||||
title = idea['title']
|
title = idea['title']
|
||||||
title = title[:25]
|
title = title[:25]
|
||||||
i = 0
|
i = 0
|
||||||
path = "videos/" + title
|
path = subjectdirpath + "/" + title
|
||||||
path = path.replace(" ", "_").replace(":", "")
|
path = path.replace(" ", "_").replace(":", "")
|
||||||
if not os.path.exists(path + "/script.json"):
|
if not os.path.exists(path + "/script.json"):
|
||||||
script = await generate_script(idea['title'], idea['description'])
|
script = await generate_script(idea['title'], idea['description'])
|
||||||
|
|||||||
Reference in New Issue
Block a user