Skip to content

Instantly share code, notes, and snippets.

@RageshAntony
Last active February 6, 2023 08:51
Show Gist options
  • Save RageshAntony/89b3ec60241e3882752074f82862d404 to your computer and use it in GitHub Desktop.
Save RageshAntony/89b3ec60241e3882752074f82862d404 to your computer and use it in GitHub Desktop.
Open AI - TV Series Generator
import json
import requests
from types import SimpleNamespace
movieSchema = {
"id": "<unique id of the web series",
"plot": "<plot of the Web Series>",
"maturity": "<Random Int value from (13+,16+,18+)>",
"release": "<Date when the Series released. in YYYY-MM-DD format>",
"seasons": 1,
"trailerUrl": "https://picsum.photos/300/300?random",
"studios": "<A imaginary Production Studio name>",
"genre": "<genre of the web series based on the title",
"title": "<Title for the web series according to the Plot>",
"posterUrl": "https://picsum.photos/300/300?random",
"episodes": [
{
"id": "<unique id of the episode>",
"episodeIndex": "<Episode number of this episode>",
"title": "<Title for this episode as per the plot>",
"description": "<Plot of this episode as per the series plot and title>",
"airDate": "<Air date of this episode. In YYYY-MM-DD format>",
"durationMins": "<Runtime of this epiosde in Integer value>",
"posterUrl": "https://picsum.photos/300/300?random",
"videoUrl": "<tiny random url>",
"series": "<id of the web series above>",
"season": 1
}
]
}
url = "https://api.openai.com/v1/completions"
payload = json.dumps({
"model": "text-davinci-003",
"prompt": 'Generate a valid JSON object based on this schema for Web Series info.episodes field is a Json '
'array of 3 objects which have info about episodes.' + json.dumps(movieSchema),
"temperature": 1,
"max_tokens": 3000,
"top_p": 1,
"frequency_penalty": 0,
"presence_penalty": 1
})
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer sk-apikeyapikey'
}
#print(json.dumps(payload))
print("Fetching ...")
response = requests.request("POST", url, headers=headers, data=payload)
pretty_object = json.dumps(response.json(), indent=4)
x = json.loads(pretty_object, object_hook=lambda d: SimpleNamespace(**d))
print(x.choices[0].text)
{
"id": "ABC0419RTB",
"plot": "In a dystopian future, human survival is dependent on the safekeeping and replenishment of resources. A group of young people rebel against the totalitarian rule and use their wits to keep the colony alive.",
"maturity": "18+",
"release": "2019-05-09",
"seasons": 1,
"trailerUrl":"https://picsum.photos/300/300?random",
"studios": "Genesis Productions",
"genre": "Sci-Fi Drama",
"title": "The Resource Seekers",
"posterUrl": "https://picsum.photos/300/300?random",
"episodes": [
{
"id": "ABC0419EPI01",
"episodeIndex": 1,
"title": "The Revolution Begins",
"description": "The revolt against the oppressive forces starts with a single spark and quickly catches fire when a leader emerges.",
"airDate": "2019-05-09",
"durationMins": 60,
"posterUrl": "https://picsum.photos/300/300?random",
"videoUrl": "<https://tinyurl.com/v2348x>",
"series": "ABC0419RTB",
"season": 1
},
{
"id": "ABC0419EPI02",
"episodeIndex": 2,
"title": "The Stakes are High",
"description": "The stakes in the war for justice mount as the rebels realize that their actions will determine the fate of the colony.",
"airDate": "2019-05-16",
"durationMins": 50,
"posterUrl": "https://picsum.photos/300/300?random",
"videoUrl": "<https://tinyurl.com/o87sew>",
"series": "ABC0419RTB",
"season": 1
},
{
"id": "ABC0419EPI03",
"episodeIndex": 3,
"title": "The Rising Tide",
"description": "The tide turns in favor of the rebellion as the tides of public opinion turn in their favor.",
"airDate": "2019-05-23",
"durationMins": 45,
"posterUrl": "https://picsum.photos/300/300?random",
"videoUrl": "<https://tinyurl.com/m9ksmu>",
"series": "ABC0419RTB",
"season": 1
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment