Skip to content

Instantly share code, notes, and snippets.

@seandavi
Created August 16, 2024 19:35
Show Gist options
  • Save seandavi/9e6404cd414be8584f1299fdf8bc3926 to your computer and use it in GitHub Desktop.
Save seandavi/9e6404cd414be8584f1299fdf8bc3926 to your computer and use it in GitHub Desktop.
Powerpoint from python code

Powerpoint from code

Using code for a powerpoint is a useful approach to have chatgpt and other LLMs create powerpoint slides from documents or a textual description.

Usage

pip install -r requirements.txt
python make_powerpoint.py
from pptx import Presentation
from pptx.util import Inches
from pptx.enum.chart import XL_CHART_TYPE
# Create a presentation object
prs = Presentation()
# Add a title slide
slide_layout = prs.slide_layouts[0] # 0 is the layout for the title slide
slide = prs.slides.add_slide(slide_layout)
title = slide.shapes.title
subtitle = slide.placeholders[1]
title.text = "Welcome to the Presentation"
subtitle.text = "This presentation contains text, a table, and a chart."
# Add a slide with a title and content
slide_layout = prs.slide_layouts[1] # 1 is the layout for title and content
slide = prs.slides.add_slide(slide_layout)
title = slide.shapes.title
content = slide.placeholders[1]
title.text = "Agenda"
content.text = "1. Introduction\n2. Main Content\n3. Conclusion"
# Add a slide with a table
slide_layout = prs.slide_layouts[5] # 5 is the layout for title and content
slide = prs.slides.add_slide(slide_layout)
title = slide.shapes.title
title.text = "Data Table"
# Define table dimensions
rows = 3
cols = 4
left = Inches(2)
top = Inches(2)
width = Inches(6)
height = Inches(1.5)
# Add table
table = slide.shapes.add_table(rows, cols, left, top, width, height).table
# Set column headings
table.columns[0].width = Inches(1.5)
table.columns[1].width = Inches(1.5)
table.columns[2].width = Inches(1.5)
table.columns[3].width = Inches(1.5)
table.cell(0, 0).text = 'Header 1'
table.cell(0, 1).text = 'Header 2'
table.cell(0, 2).text = 'Header 3'
table.cell(0, 3).text = 'Header 4'
# Add data to the table
table.cell(1, 0).text = 'Data 1'
table.cell(1, 1).text = 'Data 2'
table.cell(1, 2).text = 'Data 3'
table.cell(1, 3).text = 'Data 4'
table.cell(2, 0).text = 'Data 5'
table.cell(2, 1).text = 'Data 6'
table.cell(2, 2).text = 'Data 7'
table.cell(2, 3).text = 'Data 8'
prs.save('combined_presentation.pptx')
@samaaesmail2111-oss
Copy link

from pptx import Presentation
from pptx.util import Inches, Pt

Create a PowerPoint presentation

prs = Presentation()

Set slide dimensions

prs.slide_width = Inches(13.33)
prs.slide_height = Inches(7.5)

Add a blank slide

slide = prs.slides.add_slide(prs.slide_layouts[6])

Add main title

title_box = slide.shapes.add_textbox(Inches(0.5), Inches(0.2), Inches(12), Inches(1))
title_frame = title_box.text_frame
title_frame.text = "Gut Microbiota Profile in Type 2 Diabetes: With vs. Without Metformin"
title_frame.paragraphs[0].font.size = Pt(32)
title_frame.paragraphs[0].font.bold = True

Add left panel - Without Metformin

left_box = slide.shapes.add_textbox(Inches(0.5), Inches(1.5), Inches(6), Inches(5))
left_frame = left_box.text_frame
left_frame.word_wrap = True
p1 = left_frame.add_paragraph()
p1.text = (
"❌ Without Metformin:\n"
"- Low microbial diversity\n"
"- ↑ Clostridiaceae\n"
"- ↑ A type of Prevotella\n"
"- ↓ Enterococcus casseliflavus\n\n"
"Microbiota less beneficial"
)
p1.font.size = Pt(20)

Add right panel - With Metformin

right_box = slide.shapes.add_textbox(Inches(6.8), Inches(1.5), Inches(6), Inches(5))
right_frame = right_box.text_frame
right_frame.word_wrap = True
p2 = right_frame.add_paragraph()
p2.text = (
"✅ With Metformin:\n"
"- Increased Akkermansia muciniphila (mucin-degrading)\n"
"- ↑ SCFA-producing bacteria:\n"
" • Butyrivibrio\n"
" • Bifidobacterium bifidum\n"
" • Megasphaera\n"
" • Prevotella\n"
"- SCFA Benefits:\n"
" • Improved insulin sensitivity\n"
" • Reduced inflammation\n"
" • Energy for colon cells"
)
p2.font.size = Pt(20)

Save the presentation

prs.save("Gut_Microbiota_Metformin_Infographic.pptx")

@kurian-hub
Copy link

from pptx import Presentation from pptx.util import Inches, Pt from pptx.dml.color import RGBColor

Create presentation

prs = Presentation()

Title Slide

title_slide_layout = prs.slide_layouts[0] slide = prs.slides.add_slide(title_slide_layout) title = slide.shapes.title title.text = "Iron Deficiency Anemia" subtitle = slide.placeholders[1] subtitle.text = "Lecture for MBBS Students"

Function to add a slide with bullet points

def add_bullet_slide(title_text, bullet_points): slide_layout = prs.slide_layouts[1] slide = prs.slides.add_slide(slide_layout) title = slide.shapes.title title.text = title_text content = slide.placeholders[1] tf = content.text_frame tf.clear() for point in bullet_points: p = tf.add_paragraph() p.text = point p.font.size = Pt(20)

Overview

add_bullet_slide("Overview", [ "Most common cause of anemia worldwide", "Microcytic, hypochromic red cells", "Common in children, women of reproductive age, elderly", "Hb <130 g/L (men), <120 g/L (women)" ])

Etiology

add_bullet_slide("Etiology", [ "Blood loss: GI bleeding, menorrhagia, NSAIDs", "Reduced intake: poor diet, vegetarian/vegan", "Malabsorption: celiac disease, gastrectomy", "Increased demand: pregnancy, growth spurts" ])

Clinical Features

add_bullet_slide("Clinical Features", [ "Symptoms: fatigue, dyspnoea, pica, headache", "Signs: pallor, angular cheilitis, koilonychia, glossitis", "Severe: tachycardia, murmurs, heart failure" ])

Pathophysiology

add_bullet_slide("Pathophysiology", [ "Loss of iron → reduced Hb synthesis", "Stages: 1) Depleted ferritin, 2) Impaired erythropoiesis, 3) Microcytosis & hypochromia", "Peripheral smear: microcytic, hypochromic, anisopoikilocytosis", "Bone marrow: absent iron stores (Prussian blue stain)" ])

Diagnosis

add_bullet_slide("Diagnosis", [ "CBC: low Hb, MCV, MCH, high RDW", "Iron studies: low ferritin, low transferrin saturation, high TIBC", "Peripheral smear: microcytic, hypochromic, elliptocytes", "Stages: ferritin ↓ → impaired erythropoiesis → microcytosis" ])

Management

add_bullet_slide("Management", [ "Treat underlying cause", "Oral iron: ferrous sulphate 200 mg/d × 3 months post-Hb

@mirsawalsmanas-cyber
Copy link

from pptx import Presentation

Membuat presentasi baru

prs = Presentation()

Slide 1: Judul

slide = prs.slides.add_slide(prs.slide_layouts[0])
title = slide.shapes.title
subtitle = slide.placeholders[1]
title.text = "Larangan ASN dan Implementasinya"
subtitle.text = "Dibuat oleh ChatGPT | 2025"

Slide 2: Pendahuluan

slide = prs.slides.add_slide(prs.slide_layouts[1])
slide.shapes.title.text = "Pendahuluan"
slide.placeholders[1].text = (
"ASN memiliki peran strategis dalam penyelenggaraan pemerintahan dan pelayanan publik. "
"Untuk menjaga integritas dan profesionalisme birokrasi, berbagai larangan diterapkan "
"agar ASN tidak terlibat dalam politik praktis, penyalahgunaan wewenang, atau konflik kepentingan."
)

Slide 3: Asas-asas Penyelenggaraan ASN

slide = prs.slides.add_slide(prs.slide_layouts[1])
slide.shapes.title.text = "Asas-asas Penyelenggaraan ASN"
slide.placeholders[1].text = (
"Berdasarkan UU

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment