Update python-pptx/python-pptx.py
Browse files- python-pptx/python-pptx.py +53 -0
    	
        python-pptx/python-pptx.py
    CHANGED
    
    | @@ -0,0 +1,53 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            #https://huggingface.co/spaces/MisterAI/GenDoc_05
         | 
| 2 | 
            +
            #/home/user/python-pptx/python-pptx.py_01
         | 
| 3 | 
            +
             | 
| 4 | 
            +
             | 
| 5 | 
            +
            from pptx import Presentation
         | 
| 6 | 
            +
            from pptx.util import Inches, Pt
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            class PresentationGenerator:
         | 
| 9 | 
            +
                def __init__(self):
         | 
| 10 | 
            +
                    pass
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                def parse_presentation_content(self, content):
         | 
| 13 | 
            +
                    slides = []
         | 
| 14 | 
            +
                    current_slide = None
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                    for line in content.split('\n'):
         | 
| 17 | 
            +
                        line = line.strip()
         | 
| 18 | 
            +
                        if line.startswith('TITRE:'):
         | 
| 19 | 
            +
                            slides.append({'type': 'title', 'title': line[6:].strip()})
         | 
| 20 | 
            +
                        elif line.startswith('DIAPO'):
         | 
| 21 | 
            +
                            if current_slide:
         | 
| 22 | 
            +
                                slides.append(current_slide)
         | 
| 23 | 
            +
                            current_slide = {'type': 'content', 'title': '', 'points': []}
         | 
| 24 | 
            +
                        elif line.startswith('Titre:') and current_slide:
         | 
| 25 | 
            +
                            current_slide['title'] = line[6:].strip()
         | 
| 26 | 
            +
                        elif line.startswith('- ') and current_slide:
         | 
| 27 | 
            +
                            current_slide['points'].append(line[2:].strip())
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                    if current_slide:
         | 
| 30 | 
            +
                        slides.append(current_slide)
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                    return slides
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                def create_presentation(self, slides):
         | 
| 35 | 
            +
                    prs = Presentation()
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                    title_slide = prs.slides.add_slide(prs.slide_layouts[0])
         | 
| 38 | 
            +
                    title_slide.shapes.title.text = slides[0]['title']
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                    for slide in slides[1:]:
         | 
| 41 | 
            +
                        content_slide = prs.slides.add_slide(prs.slide_layouts[1])
         | 
| 42 | 
            +
                        content_slide.shapes.title.text = slide['title']
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                        if slide['points']:
         | 
| 45 | 
            +
                            body = content_slide.shapes.placeholders[1].text_frame
         | 
| 46 | 
            +
                            body.clear()
         | 
| 47 | 
            +
                            for point in slide['points']:
         | 
| 48 | 
            +
                                p = body.add_paragraph()
         | 
| 49 | 
            +
                                p.text = point
         | 
| 50 | 
            +
                                p.level = 0
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                    return prs
         | 
| 53 | 
            +
             |