-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerator1.py
More file actions
46 lines (38 loc) · 1.22 KB
/
generator1.py
File metadata and controls
46 lines (38 loc) · 1.22 KB
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
39
40
41
42
43
44
45
46
# generator.py
import os
import openai
from dotenv import load_dotenv
load_dotenv()
openai.api_key = os.getenv("OPENAI_API_KEY")
// Enter your Open API key
def generate_youtube_content(topic, audience, tone, language):
prompt = f"""
Create a YouTube video:
- Topic: {topic}
- Audience: {audience}
- Tone: {tone}
- Language: {language}
Return the following:
TITLE:
DESCRIPTION:
SCRIPT:
"""
try:
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a creative YouTube content writer."},
{"role": "user", "content": prompt}
],
temperature=0.7,
max_tokens=1500
)
content = response.choices[0].message.content
parts = content.split("SCRIPT:")
desc_title = parts[0].split("DESCRIPTION:")
title = desc_title[0].replace("TITLE:", "").strip()
description = desc_title[1].strip()
script = parts[1].strip()
return title, description, script
except Exception as e:
raise Exception("Failed to generate content: " + str(e))