Spaces:
Runtime error
Runtime error
revise: PPT script reader
Browse files
app.py
CHANGED
|
@@ -6,6 +6,7 @@ import time
|
|
| 6 |
import numpy as np
|
| 7 |
import pandas as pd
|
| 8 |
import PyPDF2
|
|
|
|
| 9 |
import openai
|
| 10 |
import subprocess
|
| 11 |
|
|
@@ -117,16 +118,31 @@ def text2ppt(token_key, input_prompt, input_theme):
|
|
| 117 |
def ppt2script(token_key, input_file, input_type):
|
| 118 |
openai.api_key = token_key
|
| 119 |
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
-
# κ° νμ΄μ§μ λ΄μ©μ λ¬Έμμ΄λ‘ λ³νν©λλ€.
|
| 125 |
text = ""
|
| 126 |
-
|
| 127 |
-
|
| 128 |
text += "[PAGE_NUM " + str(page_num + 1) + "]"
|
| 129 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
|
| 131 |
header = """
|
| 132 |
λλλ PPT λ°νμ λμμ μ£Όλ μ‘°λ ₯μμΌ.
|
|
|
|
| 6 |
import numpy as np
|
| 7 |
import pandas as pd
|
| 8 |
import PyPDF2
|
| 9 |
+
from pptx import Presentation
|
| 10 |
import openai
|
| 11 |
import subprocess
|
| 12 |
|
|
|
|
| 118 |
def ppt2script(token_key, input_file, input_type):
|
| 119 |
openai.api_key = token_key
|
| 120 |
|
| 121 |
+
if input_type=="PDF":
|
| 122 |
+
with open(input_file, 'rb') as pdf_file:
|
| 123 |
+
pdf_reader = PyPDF2.PdfReader(pdf_file)
|
| 124 |
+
num_pages = len(pdf_reader.pages)
|
| 125 |
+
|
| 126 |
+
# κ° νμ΄μ§μ λ΄μ©μ λ¬Έμμ΄λ‘ λ³νν©λλ€.
|
| 127 |
+
text = ""
|
| 128 |
+
for page_num in range(num_pages):
|
| 129 |
+
page = pdf_reader.pages[page_num]
|
| 130 |
+
text += "[PAGE_NUM " + str(page_num + 1) + "]"
|
| 131 |
+
text += page.extract_text()
|
| 132 |
+
else:
|
| 133 |
+
prs = Presentation(path_to_presentation)
|
| 134 |
|
|
|
|
| 135 |
text = ""
|
| 136 |
+
page_num = 0
|
| 137 |
+
for slide in prs.slides:
|
| 138 |
text += "[PAGE_NUM " + str(page_num + 1) + "]"
|
| 139 |
+
page_num += 1
|
| 140 |
+
for shape in slide.shapes:
|
| 141 |
+
if not shape.has_text_frame:
|
| 142 |
+
continue
|
| 143 |
+
for paragraph in shape.text_frame.paragraphs:
|
| 144 |
+
for run in paragraph.runs:
|
| 145 |
+
text += run.text
|
| 146 |
|
| 147 |
header = """
|
| 148 |
λλλ PPT λ°νμ λμμ μ£Όλ μ‘°λ ₯μμΌ.
|