-
Notifications
You must be signed in to change notification settings - Fork 0
/
Source code.py
68 lines (50 loc) · 2.46 KB
/
Source code.py
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
!pip install python-docx #download this pacakages before running the code
!pip install python-pptx
import docx
from pptx import Presentation
from google.colab import files
# Load the .docx file
docx_file = docx.Document("mathcontent 1.docx") #docx file name here like i have given mathcontent 1
# Create a new PowerPoint presentation
ppt = Presentation()
# Iterate through the paragraphs in the .docx file
for paragraph in docx_file.paragraphs:
# Check if the paragraph contains mathematical content
if any(keyword in paragraph.text.lower() for keyword in ["equation", "graph", "diagram"]):
# Extract the content from the paragraph
content = paragraph.text
# Add logic to process equations
if "equation" in paragraph.text.lower():
equation = process_equation(content) # Function to parse and process the equation
equation_result = calculate_result(equation) # Function to calculate result
# Add the equation and result to the slide
slide_layout = ppt.slide_layouts[1]
slide = ppt.slides.add_slide(slide_layout)
# Use fixed values for positioning and sizing
left = 100
top = 200
width = 400
height = 300
content_box = slide.shapes.add_textbox(left, top, width, height)
content_frame = content_box.text_frame
p = content_frame.add_paragraph()
p.text = f"Equation: {equation}\nResult: {equation_result}"
# Add logic to handle graphs or diagrams
if "graph" in paragraph.text.lower() or "diagram" in paragraph.text.lower():
graph_data = extract_graph_data(content) # Function to extract graph data
graph_image = generate_graph_image(graph_data) # Function to generate graph image
# Add the graph image to the slide
slide_layout = ppt.slide_layouts[1]
slide = ppt.slides.add_slide(slide_layout)
# Use calculated values for positioning and sizing
slide_width = ppt.slide_width
slide_height = ppt.slide_height
width = slide_width * 0.8
height = slide_height * 0.6
left = (slide_width - width) / 2
top = (slide_height - height) / 2
content_box = slide.shapes.add_picture(graph_image, left, top, width, height)
# Save the PowerPoint presentation
ppt.save("output.pptx")
# Download the output file
files.download("output.pptx")