{"id":12,"date":"2023-05-08T22:39:41","date_gmt":"2023-05-08T22:39:41","guid":{"rendered":"https:\/\/learnlearn.uk\/ai\/?p=12"},"modified":"2023-05-10T21:01:32","modified_gmt":"2023-05-10T21:01:32","slug":"automatically-creating-powerpoints-using-chatgpt-and-python","status":"publish","type":"post","link":"https:\/\/learnlearn.uk\/ai\/2023\/05\/08\/automatically-creating-powerpoints-using-chatgpt-and-python\/","title":{"rendered":"Automatically Creating Powerpoints using ChatGPT and Python"},"content":{"rendered":"<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-17 size-medium\" src=\"https:\/\/learnlearn.uk\/ai\/wp-content\/uploads\/sites\/26\/2023\/05\/robot-slideshow-600x400.jpg?_t=1683752471\" alt=\"\" width=\"600\" height=\"400\" srcset=\"https:\/\/learnlearn.uk\/ai\/wp-content\/uploads\/sites\/26\/2023\/05\/robot-slideshow-600x400.jpg 600w, https:\/\/learnlearn.uk\/ai\/wp-content\/uploads\/sites\/26\/2023\/05\/robot-slideshow-930x620.jpg 930w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/p>\n<h3>Introduction<\/h3>\n<p>In this post we look at how you can combine ChatGPT and Python to create Powerpoint files automatically.<\/p>\n<h3>Getting Started<\/h3>\n<p>Before we can start coding we need to do a few things first:<\/p>\n<p><strong>1 Install the Python PPTX module<\/strong><\/p>\n<p><a href=\"https:\/\/python-pptx.readthedocs.io\/en\/latest\/user\/install.html\">Install python-pptx (and dependencies)<\/a><\/p>\n<p><strong>2. Install the OpenAI Python Module<\/strong><\/p>\n<p><a href=\"https:\/\/pypi.org\/project\/openai\/\">Install OpenAI Python module<\/a><\/p>\n<p><strong>3. Sign up for the API and generate an API Key<\/strong><\/p>\n<p><a href=\"https:\/\/platform.openai.com\/\">Sign up for the OpenAI API here<\/a><\/p>\n<h3>Tutorial Video<\/h3>\n<p><iframe loading=\"lazy\" title=\"YouTube video player\" src=\"https:\/\/www.youtube.com\/embed\/z8vAVKw3ei4\" width=\"560\" height=\"315\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><span data-mce-type=\"bookmark\" style=\"display: inline-block; width: 0px; overflow: hidden; line-height: 0;\" class=\"mce_SELRES_start\">\ufeff<\/span><\/iframe><\/p>\n<h3>Project Source Code<\/h3>\n<p>Here is the full source code for reference as you follow along with the video.<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">openai<\/span><span style=\"color: #333333;\">,<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">json<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">from<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">pptx<\/span> <span style=\"color: #008800; font-weight: bold;\">import<\/span> Presentation\r\nopenai<span style=\"color: #333333;\">.<\/span>api_key <span style=\"color: #333333;\">=<\/span> \"YOUR_API_KEY_HERE\"\r\n\r\npresentation_title <span style=\"color: #333333;\">=<\/span> <span style=\"color: #007020;\">input<\/span>(<span style=\"background-color: #fff0f0;\">\"What do you want to make a presentation about?\"<\/span>)\r\n\r\nquery_json <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"\"\"\"{<\/span>\r\n<span style=\"background-color: #fff0f0;\">    \"input_text\": \"[[QUERY]]\",<\/span>\r\n<span style=\"background-color: #fff0f0;\">    \"output_format\": \"json\",<\/span>\r\n<span style=\"background-color: #fff0f0;\">    \"json_structure\": {<\/span>\r\n<span style=\"background-color: #fff0f0;\">        \"slides\":\"{{presentation_slides}}\"<\/span>\r\n<span style=\"background-color: #fff0f0;\">       }<\/span>\r\n<span style=\"background-color: #fff0f0;\">    }\"\"\"<\/span>\r\n       \r\nquestion <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"Generate a 10 slide presentation for the topic. Produce 50 to 60 words per slide. \"<\/span> <span style=\"color: #333333;\">+<\/span> presentation_title <span style=\"color: #333333;\">+<\/span> <span style=\"background-color: #fff0f0;\">\".Each slide should have a  {{header}}, {{content}}. The final slide should be a list of discussion questions. Return as JSON.\"<\/span>\r\n\r\nprompt <span style=\"color: #333333;\">=<\/span> query_json<span style=\"color: #333333;\">.<\/span>replace(<span style=\"background-color: #fff0f0;\">\"[[QUERY]]\"<\/span>,question)\r\n<span style=\"color: #008800; font-weight: bold;\">print<\/span>(prompt)\r\ncompletion <span style=\"color: #333333;\">=<\/span> openai<span style=\"color: #333333;\">.<\/span>ChatCompletion<span style=\"color: #333333;\">.<\/span>create(model <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"gpt-3.5-turbo\"<\/span>, messages <span style=\"color: #333333;\">=<\/span>[{<span style=\"background-color: #fff0f0;\">\"role\"<\/span>:<span style=\"background-color: #fff0f0;\">\"user\"<\/span>,<span style=\"background-color: #fff0f0;\">\"content\"<\/span>:prompt}])\r\nresponse <span style=\"color: #333333;\">=<\/span> completion<span style=\"color: #333333;\">.<\/span>choices[<span style=\"color: #0000dd; font-weight: bold;\">0<\/span>]<span style=\"color: #333333;\">.<\/span>message<span style=\"color: #333333;\">.<\/span>content\r\n\r\n<span style=\"color: #008800; font-weight: bold;\">print<\/span>(response)\r\n\r\nr <span style=\"color: #333333;\">=<\/span> json<span style=\"color: #333333;\">.<\/span>loads(response)\r\n\r\nslide_data <span style=\"color: #333333;\">=<\/span> r[<span style=\"background-color: #fff0f0;\">\"slides\"<\/span>]\r\n\r\nprs <span style=\"color: #333333;\">=<\/span> Presentation()\r\n\r\n<span style=\"color: #008800; font-weight: bold;\">for<\/span> slide <span style=\"color: #000000; font-weight: bold;\">in<\/span> slide_data:\r\n    slide_layout <span style=\"color: #333333;\">=<\/span> prs<span style=\"color: #333333;\">.<\/span>slide_layouts[<span style=\"color: #0000dd; font-weight: bold;\">1<\/span>]\r\n    new_slide <span style=\"color: #333333;\">=<\/span> prs<span style=\"color: #333333;\">.<\/span>slides<span style=\"color: #333333;\">.<\/span>add_slide(slide_layout)\r\n    \r\n    <span style=\"color: #008800; font-weight: bold;\">if<\/span> slide[<span style=\"background-color: #fff0f0;\">'header'<\/span>]:\r\n        title <span style=\"color: #333333;\">=<\/span> new_slide<span style=\"color: #333333;\">.<\/span>shapes<span style=\"color: #333333;\">.<\/span>title\r\n        title<span style=\"color: #333333;\">.<\/span>text <span style=\"color: #333333;\">=<\/span> slide[<span style=\"background-color: #fff0f0;\">'header'<\/span>]\r\n    \r\n    <span style=\"color: #008800; font-weight: bold;\">if<\/span> slide[<span style=\"background-color: #fff0f0;\">'content'<\/span>]:\r\n       shapes <span style=\"color: #333333;\">=<\/span> new_slide<span style=\"color: #333333;\">.<\/span>shapes\r\n       body_shape <span style=\"color: #333333;\">=<\/span> shapes<span style=\"color: #333333;\">.<\/span>placeholders[<span style=\"color: #0000dd; font-weight: bold;\">1<\/span>]\r\n       tf <span style=\"color: #333333;\">=<\/span> body_shape<span style=\"color: #333333;\">.<\/span>text_frame\r\n       tf<span style=\"color: #333333;\">.<\/span>text <span style=\"color: #333333;\">=<\/span> slide[<span style=\"background-color: #fff0f0;\">'content'<\/span>]\r\n       tf<span style=\"color: #333333;\">.<\/span>fit_text(font_family<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"Calibri\"<\/span>, max_size<span style=\"color: #333333;\">=<\/span><span style=\"color: #0000dd; font-weight: bold;\">18<\/span>, bold<span style=\"color: #333333;\">=<\/span><span style=\"color: #007020;\">True<\/span>)\r\n       \r\nprs<span style=\"color: #333333;\">.<\/span>save(<span style=\"background-color: #fff0f0;\">\"output.pptx\"<\/span>)\r\n    \r\n<\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Introduction In this post we look at how you can combine ChatGPT and Python to create Powerpoint files automatically. Getting Started Before we can start coding we need to do a few things first: 1 Install the Python PPTX module Install python-pptx (and dependencies) 2. Install the OpenAI Python Module Install OpenAI Python module 3.&hellip;&nbsp;<a href=\"https:\/\/learnlearn.uk\/ai\/2023\/05\/08\/automatically-creating-powerpoints-using-chatgpt-and-python\/\" class=\"\" rel=\"bookmark\">Read More &raquo;<span class=\"screen-reader-text\">Automatically Creating Powerpoints using ChatGPT and Python<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"off","neve_meta_content_width":70,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":""},"categories":[1],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Automatically Creating Powerpoints using ChatGPT and Python - ChatGPT &amp; AI<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/learnlearn.uk\/ai\/2023\/05\/08\/automatically-creating-powerpoints-using-chatgpt-and-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Automatically Creating Powerpoints using ChatGPT and Python - ChatGPT &amp; AI\" \/>\n<meta property=\"og:description\" content=\"Introduction In this post we look at how you can combine ChatGPT and Python to create Powerpoint files automatically. Getting Started Before we can start coding we need to do a few things first: 1 Install the Python PPTX module Install python-pptx (and dependencies) 2. Install the OpenAI Python Module Install OpenAI Python module 3.&hellip;&nbsp;Read More &raquo;Automatically Creating Powerpoints using ChatGPT and Python\" \/>\n<meta property=\"og:url\" content=\"https:\/\/learnlearn.uk\/ai\/2023\/05\/08\/automatically-creating-powerpoints-using-chatgpt-and-python\/\" \/>\n<meta property=\"og:site_name\" content=\"ChatGPT &amp; AI\" \/>\n<meta property=\"article:published_time\" content=\"2023-05-08T22:39:41+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-05-10T21:01:32+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/learnlearn.uk\/ai\/wp-content\/uploads\/sites\/26\/2023\/05\/robot-slideshow-600x400.jpg?_t=1683752471\" \/>\n<meta name=\"author\" content=\"learnlearnadmin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"learnlearnadmin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/learnlearn.uk\/ai\/2023\/05\/08\/automatically-creating-powerpoints-using-chatgpt-and-python\/\",\"url\":\"https:\/\/learnlearn.uk\/ai\/2023\/05\/08\/automatically-creating-powerpoints-using-chatgpt-and-python\/\",\"name\":\"Automatically Creating Powerpoints using ChatGPT and Python - ChatGPT &amp; AI\",\"isPartOf\":{\"@id\":\"https:\/\/learnlearn.uk\/ai\/#website\"},\"datePublished\":\"2023-05-08T22:39:41+00:00\",\"dateModified\":\"2023-05-10T21:01:32+00:00\",\"author\":{\"@id\":\"https:\/\/learnlearn.uk\/ai\/#\/schema\/person\/37d61760b611e12d655e20de44b12f02\"},\"breadcrumb\":{\"@id\":\"https:\/\/learnlearn.uk\/ai\/2023\/05\/08\/automatically-creating-powerpoints-using-chatgpt-and-python\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/learnlearn.uk\/ai\/2023\/05\/08\/automatically-creating-powerpoints-using-chatgpt-and-python\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/learnlearn.uk\/ai\/2023\/05\/08\/automatically-creating-powerpoints-using-chatgpt-and-python\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/learnlearn.uk\/ai\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Automatically Creating Powerpoints using ChatGPT and Python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/learnlearn.uk\/ai\/#website\",\"url\":\"https:\/\/learnlearn.uk\/ai\/\",\"name\":\"ChatGPT &amp; AI\",\"description\":\"Just another My Blog site\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/learnlearn.uk\/ai\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/learnlearn.uk\/ai\/#\/schema\/person\/37d61760b611e12d655e20de44b12f02\",\"name\":\"learnlearnadmin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/learnlearn.uk\/ai\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/07a2ee7e04b8bee91a78709b019de541?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/07a2ee7e04b8bee91a78709b019de541?s=96&d=mm&r=g\",\"caption\":\"learnlearnadmin\"},\"url\":\"https:\/\/learnlearn.uk\/ai\/author\/learnlearnadmin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Automatically Creating Powerpoints using ChatGPT and Python - ChatGPT &amp; AI","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/learnlearn.uk\/ai\/2023\/05\/08\/automatically-creating-powerpoints-using-chatgpt-and-python\/","og_locale":"en_US","og_type":"article","og_title":"Automatically Creating Powerpoints using ChatGPT and Python - ChatGPT &amp; AI","og_description":"Introduction In this post we look at how you can combine ChatGPT and Python to create Powerpoint files automatically. Getting Started Before we can start coding we need to do a few things first: 1 Install the Python PPTX module Install python-pptx (and dependencies) 2. Install the OpenAI Python Module Install OpenAI Python module 3.&hellip;&nbsp;Read More &raquo;Automatically Creating Powerpoints using ChatGPT and Python","og_url":"https:\/\/learnlearn.uk\/ai\/2023\/05\/08\/automatically-creating-powerpoints-using-chatgpt-and-python\/","og_site_name":"ChatGPT &amp; AI","article_published_time":"2023-05-08T22:39:41+00:00","article_modified_time":"2023-05-10T21:01:32+00:00","og_image":[{"url":"https:\/\/learnlearn.uk\/ai\/wp-content\/uploads\/sites\/26\/2023\/05\/robot-slideshow-600x400.jpg?_t=1683752471"}],"author":"learnlearnadmin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"learnlearnadmin","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/learnlearn.uk\/ai\/2023\/05\/08\/automatically-creating-powerpoints-using-chatgpt-and-python\/","url":"https:\/\/learnlearn.uk\/ai\/2023\/05\/08\/automatically-creating-powerpoints-using-chatgpt-and-python\/","name":"Automatically Creating Powerpoints using ChatGPT and Python - ChatGPT &amp; AI","isPartOf":{"@id":"https:\/\/learnlearn.uk\/ai\/#website"},"datePublished":"2023-05-08T22:39:41+00:00","dateModified":"2023-05-10T21:01:32+00:00","author":{"@id":"https:\/\/learnlearn.uk\/ai\/#\/schema\/person\/37d61760b611e12d655e20de44b12f02"},"breadcrumb":{"@id":"https:\/\/learnlearn.uk\/ai\/2023\/05\/08\/automatically-creating-powerpoints-using-chatgpt-and-python\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/learnlearn.uk\/ai\/2023\/05\/08\/automatically-creating-powerpoints-using-chatgpt-and-python\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/learnlearn.uk\/ai\/2023\/05\/08\/automatically-creating-powerpoints-using-chatgpt-and-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/learnlearn.uk\/ai\/"},{"@type":"ListItem","position":2,"name":"Automatically Creating Powerpoints using ChatGPT and Python"}]},{"@type":"WebSite","@id":"https:\/\/learnlearn.uk\/ai\/#website","url":"https:\/\/learnlearn.uk\/ai\/","name":"ChatGPT &amp; AI","description":"Just another My Blog site","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/learnlearn.uk\/ai\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/learnlearn.uk\/ai\/#\/schema\/person\/37d61760b611e12d655e20de44b12f02","name":"learnlearnadmin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/learnlearn.uk\/ai\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/07a2ee7e04b8bee91a78709b019de541?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/07a2ee7e04b8bee91a78709b019de541?s=96&d=mm&r=g","caption":"learnlearnadmin"},"url":"https:\/\/learnlearn.uk\/ai\/author\/learnlearnadmin\/"}]}},"rttpg_featured_image_url":null,"rttpg_author":{"display_name":"learnlearnadmin","author_link":"https:\/\/learnlearn.uk\/ai\/author\/learnlearnadmin\/"},"rttpg_comment":0,"rttpg_category":"<a href=\"https:\/\/learnlearn.uk\/ai\/category\/uncategorized\/\" rel=\"category tag\">Uncategorized<\/a>","rttpg_excerpt":"Introduction In this post we look at how you can combine ChatGPT and Python to create Powerpoint files automatically. Getting Started Before we can start coding we need to do a few things first: 1 Install the Python PPTX module Install python-pptx (and dependencies) 2. Install the OpenAI Python Module Install OpenAI Python module 3.&hellip;&nbsp;Read&hellip;","_links":{"self":[{"href":"https:\/\/learnlearn.uk\/ai\/wp-json\/wp\/v2\/posts\/12"}],"collection":[{"href":"https:\/\/learnlearn.uk\/ai\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/learnlearn.uk\/ai\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/learnlearn.uk\/ai\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/learnlearn.uk\/ai\/wp-json\/wp\/v2\/comments?post=12"}],"version-history":[{"count":5,"href":"https:\/\/learnlearn.uk\/ai\/wp-json\/wp\/v2\/posts\/12\/revisions"}],"predecessor-version":[{"id":51,"href":"https:\/\/learnlearn.uk\/ai\/wp-json\/wp\/v2\/posts\/12\/revisions\/51"}],"wp:attachment":[{"href":"https:\/\/learnlearn.uk\/ai\/wp-json\/wp\/v2\/media?parent=12"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/learnlearn.uk\/ai\/wp-json\/wp\/v2\/categories?post=12"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/learnlearn.uk\/ai\/wp-json\/wp\/v2\/tags?post=12"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}