Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,170 +1,16 @@
|
|
1 |
-
import env_set
|
2 |
import os
|
|
|
3 |
env_set.env_set()
|
4 |
|
5 |
import streamlit as st
|
6 |
-
import time
|
7 |
-
import numpy as np
|
8 |
-
import pandas as pd
|
9 |
import PyPDF2
|
10 |
-
from pptx import Presentation
|
11 |
import openai
|
12 |
import subprocess
|
13 |
from io import BytesIO
|
|
|
14 |
|
|
|
15 |
|
16 |
-
# text2ppt ํ๋กฌํํธ ์์ฑ ํจ์
|
17 |
-
def generate_text2ppt_input_prompt(input_type, input_value, input_pages):
|
18 |
-
header = """
|
19 |
-
๋๊ฐ markdown ๋ฌธ๋ฒ์ผ๋ก PPT๋ฅผ ์ ์ํ๋ ๋์์ด๋๋ผ๊ณ ๊ฐ์ ํ๊ณ , %s์ฅ์ PPT๋ฅผ ์์ฑํด.
|
20 |
-
+++ ์๋ ๋ด์ฉ ๋๋ ๋งํฌ๋ฅผ ์์ฝํด์ markdown ์ธ์ด๋ก ์์ฑํ๋๋ฐ, === ์๋ ๊ท์น๊ณผ ์งํค๊ณ , ~~~ ์๋ ์ฌ๋ผ์ด๋ ์์๋ฅผ ์ฐธ๊ณ ํด.
|
21 |
-
+++
|
22 |
-
""" % input_pages
|
23 |
-
|
24 |
-
summary_value = ""
|
25 |
-
|
26 |
-
if input_type == "๋งํฌ":
|
27 |
-
summary_value += input_value
|
28 |
-
summary_value += "ํ
์คํธ"
|
29 |
-
elif input_type == "text":
|
30 |
-
summary_value += input_value
|
31 |
-
summary_value += "\n"
|
32 |
-
elif input_type == "PDF":
|
33 |
-
with open(input_value, 'rb') as pdf_file:
|
34 |
-
pdf_reader = PyPDF2.PdfReader(pdf_file)
|
35 |
-
num_pages = len(pdf_reader.pages)
|
36 |
-
|
37 |
-
# ๊ฐ ํ์ด์ง์ ๋ด์ฉ์ ๋ฌธ์์ด๋ก ๋ณํํฉ๋๋ค.
|
38 |
-
text = ""
|
39 |
-
for page_num in range(num_pages):
|
40 |
-
page = pdf_reader.pages[page_num]
|
41 |
-
text += page.extract_text()
|
42 |
-
summary_value += text
|
43 |
-
summary_value += "\n"
|
44 |
-
else:
|
45 |
-
print("ERROR: ์๋ชป๋ ์
๋ ฅ")
|
46 |
-
|
47 |
-
rule_value = """
|
48 |
-
===
|
49 |
-
- ์ ์ํ ๋ด์ฉ ๋๋ ๋งํฌ์ ๋ด์ฉ์ ๋ํด์๋ง ์ฌ์ค์ ์ผ๋ก ์์ฑํด์ค.
|
50 |
-
- ์ฌ๋ผ์ด๋ ๊ตฌ๋ถ์๋ก ---๋ฅผ ๋ฌด์กฐ๊ฑด ์ฌ์ฉํด์ค.
|
51 |
-
- ์ฃผ์ ์ ์ ์ ํ ๋ํ, ์ด๋ฏธ์ง(, https://unsplash.com/ko/images/stock/non-copyrighted ์์ ์ค์ ๋ก ์ฌ์ฉ ๊ฐ๋ฅํ), ํ(|-|), ์ธ์ฉ(>), ๊ฐ์กฐ(bold, ``), ์ด๋ชจ์ง(https://kr.piliapp.com/twitter-symbols/), ์์ด์ฝ (https://kr.piliapp.com/symbol/#popular) ๋ฑ์ด ๋ค์ํ๊ฒ ์ฌ๋ผ์ด๋๋ฅผ ๋์์ธํ๊ณ ๋ฐฐ์นํด์ค.
|
52 |
-
- ์ด๋ชจ์ง๋ ์ต๋ 2 ํ์ด์ง์ ํ ๋ฒ๋ง ์ฌ์ฉํ๊ณ , ๋ค๋ฅธ ๋์์ธ์ ๋ค์ํ๊ฒ ์ฌ์ฉํด์ค.
|
53 |
-
- ์ด๋ฏธ์ง์ ํ๋ฅผ ์ฌ์ฉํ ๋, ํ์ด์ง ํฌ๊ธฐ์ ๊ณ ๋ คํด์ ๊ธ ๋ด์ฉ์ด ๋ชจ๋ ๋ํ๋๋๋ก ํฌ๊ธฐ๋ฅผ ์ง์ ํด์ค.
|
54 |
-
- Slide 1๋ฅผ ์ ๋ชฉ์ผ๋ก ํด์ ์ด %s์ฅ์ด์ผ.
|
55 |
-
- PPT์ ๋ด์ฉ์ ํ๋ถํ๊ฒ ๋งํฌ๋ค์ด์ผ๋ก ์์ฑํด์ค.
|
56 |
-
- ์ฌ๋ผ์ด๋ ๋ณ๋ก ์ค๋ช
ํ์ง๋ง๊ณ , ์ฝ๋๋ง ์์ฑํด์ค.
|
57 |
-
- ์์์ ๋ด์ฉ์ ์ฌ์ฉํด์ ์์ฑํ์ง๋ง๊ณ , ํ์๋ง ์ฐธ๊ณ ํด.
|
58 |
-
~~~
|
59 |
-
<!-- Slide 0. ์ฌ๋ผ์ด๋ ์ฃผ์ -->
|
60 |
-
# ์ฌ๋ผ์ด๋ ์ ๋ชฉ
|
61 |
-

|
62 |
-
- ChatGPT๋ฅผ ํ์ฉํ ๐ค**TEXT2PPT ์๋น์ค PA!**์
๋๋ค.
|
63 |
-
- `๋งํฌ`,`ํ
์คํธ`, `PDF`๋ฅผ ์
๋ ฅ ๋๋ ์
๋ก๋ํ๋ฉด, PPT๋ก ๋ณํํฉ๋๋ค.
|
64 |
-
""" % input_pages
|
65 |
-
|
66 |
-
return header + summary_value + rule_value
|
67 |
-
|
68 |
-
|
69 |
-
# text2ppt ์คํ ํจ์
|
70 |
-
def text2ppt(token_key, input_prompt, input_theme):
|
71 |
-
openai.api_key = token_key
|
72 |
-
|
73 |
-
messages = [
|
74 |
-
{"role": "system", "content": "You are a kind helpful PPT designer."},
|
75 |
-
]
|
76 |
-
|
77 |
-
message = input_prompt
|
78 |
-
|
79 |
-
if message:
|
80 |
-
messages.append(
|
81 |
-
{"role": "user", "content": message},
|
82 |
-
)
|
83 |
-
chat = openai.ChatCompletion.create(
|
84 |
-
model="gpt-3.5-turbo-0301", messages=messages
|
85 |
-
)
|
86 |
-
|
87 |
-
reply = chat.choices[0].message.content
|
88 |
-
messages.append({"role": "assistant", "content": reply})
|
89 |
-
|
90 |
-
md_text = reply[4:] if reply[:3] == "---" else reply
|
91 |
-
md_text_list = md_text.split('\n')
|
92 |
-
|
93 |
-
f = open("text2ppt_input.md", 'w')
|
94 |
-
for i in range(0, len(md_text_list)):
|
95 |
-
data = md_text_list[i] + "\n"
|
96 |
-
f.write(data)
|
97 |
-
f.close()
|
98 |
-
|
99 |
-
if input_theme == 'default':
|
100 |
-
subprocess.run(["./pandoc-2.14.2/bin/pandoc", "text2ppt_input.md", "-t", "pptx", "-o", "text2ppt_output.pptx"], capture_output=True)
|
101 |
-
else:
|
102 |
-
ppt_theme = "--reference-doc="+input_theme+".pptx"
|
103 |
-
subprocess.run(["./pandoc-2.14.2/bin/pandoc", "text2ppt_input.md", "-t", "pptx", ppt_theme, "-o", "text2ppt_output.pptx"], capture_output=True)
|
104 |
-
|
105 |
-
|
106 |
-
def ppt2script(token_key, input_file, input_type):
|
107 |
-
openai.api_key = token_key
|
108 |
-
|
109 |
-
if input_type=="PDF":
|
110 |
-
with open(input_file, 'rb') as pdf_file:
|
111 |
-
pdf_reader = PyPDF2.PdfReader(pdf_file)
|
112 |
-
num_pages = len(pdf_reader.pages)
|
113 |
-
|
114 |
-
# ๊ฐ ํ์ด์ง์ ๋ด์ฉ์ ๋ฌธ์์ด๋ก ๋ณํํฉ๋๋ค.
|
115 |
-
text = ""
|
116 |
-
for page_num in range(num_pages):
|
117 |
-
page = pdf_reader.pages[page_num]
|
118 |
-
text += "[PAGE_NUM " + str(page_num + 1) + "]"
|
119 |
-
text += page.extract_text()
|
120 |
-
else:
|
121 |
-
prs = Presentation(input_file)
|
122 |
-
|
123 |
-
text = ""
|
124 |
-
page_num = 0
|
125 |
-
for slide in prs.slides:
|
126 |
-
text += "[PAGE_NUM " + str(page_num + 1) + "]"
|
127 |
-
page_num += 1
|
128 |
-
for shape in slide.shapes:
|
129 |
-
if not shape.has_text_frame:
|
130 |
-
continue
|
131 |
-
for paragraph in shape.text_frame.paragraphs:
|
132 |
-
for run in paragraph.runs:
|
133 |
-
text += run.text
|
134 |
-
|
135 |
-
header = """
|
136 |
-
๋๋๋ PPT ๋ฐํ์ ๋์์ ์ฃผ๋ ์กฐ๋ ฅ์์ผ.
|
137 |
-
~~~์๋ ๊ท์น์ ์งํค๊ณ , --- ์๋ PPT ๋ด์ฉ์ ๋ํด ๋ฐํ ์คํฌ๋ฆฝํธ๋ฅผ ํ๊ธ๋ก ์์ฑํด.
|
138 |
-
~~~
|
139 |
-
- [PAGE_NUM 1] ์ผ ๋, ์ฌ๊ธฐ์ 1์ ํ์ด์ง ๋ฒํธ์ธ๋ฐ, ํ์ด์ง ๋ฒํธ๋ง๋ค ๋ฐํ ์คํฌ๋ฆฝํธ๋ฅผ ์์ฑํด.
|
140 |
-
- ๋งํฌ๋ค์ด ์ธ์ด๋ฅผ ์ฐ์ง์๊ณ , ํ
์คํธ๋ก๋ง ์์ฑํด.
|
141 |
-
- PPT ๋ด์ฉ์ ์ถ๊ฐ์ ์ธ ์ค๋ช
์ด๋ ์ฌ๋ก๋ฅผ ๋ง๋ถ์ฌ์ค.
|
142 |
-
---
|
143 |
-
"""
|
144 |
-
|
145 |
-
input_prompt = header + text
|
146 |
-
|
147 |
-
messages = [
|
148 |
-
{"role": "system", "content": "You are a kind helpful PPT Assistant."},
|
149 |
-
]
|
150 |
-
|
151 |
-
message = input_prompt
|
152 |
-
|
153 |
-
if message:
|
154 |
-
messages.append(
|
155 |
-
{"role": "user", "content": message},
|
156 |
-
)
|
157 |
-
chat = openai.ChatCompletion.create(
|
158 |
-
model="gpt-3.5-turbo-0301", messages=messages
|
159 |
-
)
|
160 |
-
|
161 |
-
reply = chat.choices[0].message.content
|
162 |
-
messages.append({"role": "assistant", "content": reply})
|
163 |
-
|
164 |
-
return reply
|
165 |
-
|
166 |
-
|
167 |
-
####### ํ๋ฉด ์์ ########
|
168 |
tab1, tab2, tab3 = st.tabs(['PA!๋?', 'Text2PPT', 'PPT2Script'])
|
169 |
|
170 |
with tab1:
|
@@ -238,7 +84,7 @@ with tab2:
|
|
238 |
|
239 |
if input_text_check == True:
|
240 |
with st.spinner('Wait for it...'):
|
241 |
-
text2ppt(gpt_token, generate_text2ppt_input_prompt(status, input_text, page_choice), thema_select)
|
242 |
prs = Presentation("text2ppt_output.pptx")
|
243 |
binary_output = BytesIO()
|
244 |
prs.save(binary_output)
|
@@ -271,7 +117,7 @@ with tab3:
|
|
271 |
with open(uploaded_file.name, mode='wb') as w:
|
272 |
w.write(uploaded_file.getvalue())
|
273 |
|
274 |
-
script = ppt2script(gpt_token, uploaded_file.name, choose)
|
275 |
|
276 |
st.success('Done!')
|
277 |
st.download_button('Download Script',
|
|
|
|
|
1 |
import os
|
2 |
+
import env_set
|
3 |
env_set.env_set()
|
4 |
|
5 |
import streamlit as st
|
|
|
|
|
|
|
6 |
import PyPDF2
|
|
|
7 |
import openai
|
8 |
import subprocess
|
9 |
from io import BytesIO
|
10 |
+
from pptx import Presentation
|
11 |
|
12 |
+
import presentation_assistant as pa
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
tab1, tab2, tab3 = st.tabs(['PA!๋?', 'Text2PPT', 'PPT2Script'])
|
15 |
|
16 |
with tab1:
|
|
|
84 |
|
85 |
if input_text_check == True:
|
86 |
with st.spinner('Wait for it...'):
|
87 |
+
pa.text2ppt(gpt_token, generate_text2ppt_input_prompt(status, input_text, page_choice), thema_select)
|
88 |
prs = Presentation("text2ppt_output.pptx")
|
89 |
binary_output = BytesIO()
|
90 |
prs.save(binary_output)
|
|
|
117 |
with open(uploaded_file.name, mode='wb') as w:
|
118 |
w.write(uploaded_file.getvalue())
|
119 |
|
120 |
+
script = pa.ppt2script(gpt_token, uploaded_file.name, choose)
|
121 |
|
122 |
st.success('Done!')
|
123 |
st.download_button('Download Script',
|