Spaces:
Runtime error
Runtime error
update: revise korean to english prompt
Browse files
presentation_assistant/presentation_assistant.py
CHANGED
|
@@ -8,20 +8,20 @@ import sys
|
|
| 8 |
|
| 9 |
sys.path.append("/home/user/app")
|
| 10 |
|
| 11 |
-
# text2ppt
|
| 12 |
def generate_text2ppt_input_prompt(input_type, input_value, input_pages):
|
| 13 |
header = """
|
| 14 |
-
|
| 15 |
-
+++
|
| 16 |
+++
|
| 17 |
""" % input_pages
|
| 18 |
|
| 19 |
summary_value = ""
|
| 20 |
|
| 21 |
-
if input_type == "
|
| 22 |
summary_value += input_value
|
| 23 |
summary_value += "\n"
|
| 24 |
-
elif input_type == "
|
| 25 |
summary_value += input_value
|
| 26 |
summary_value += "\n"
|
| 27 |
elif input_type == "PDF":
|
|
@@ -29,7 +29,7 @@ def generate_text2ppt_input_prompt(input_type, input_value, input_pages):
|
|
| 29 |
pdf_reader = PyPDF2.PdfReader(pdf_file)
|
| 30 |
num_pages = len(pdf_reader.pages)
|
| 31 |
|
| 32 |
-
#
|
| 33 |
text = ""
|
| 34 |
for page_num in range(num_pages):
|
| 35 |
page = pdf_reader.pages[page_num]
|
|
@@ -37,31 +37,31 @@ def generate_text2ppt_input_prompt(input_type, input_value, input_pages):
|
|
| 37 |
summary_value += text
|
| 38 |
summary_value += "\n"
|
| 39 |
else:
|
| 40 |
-
print("ERROR:
|
| 41 |
|
| 42 |
rule_value = """
|
| 43 |
===
|
| 44 |
-
-
|
| 45 |
-
-
|
| 46 |
-
-
|
| 47 |
-
-
|
| 48 |
-
-
|
| 49 |
-
- Slide 1
|
| 50 |
-
- PPT
|
| 51 |
-
-
|
| 52 |
-
-
|
| 53 |
~~~
|
| 54 |
-
<!-- Slide 0.
|
| 55 |
-
#
|
| 56 |
-
![
|
| 57 |
-
-
|
| 58 |
-
-
|
| 59 |
""" % input_pages
|
| 60 |
|
| 61 |
return header + summary_value + rule_value
|
| 62 |
|
| 63 |
|
| 64 |
-
#
|
| 65 |
def text2ppt(token_key, input_prompt, input_theme):
|
| 66 |
openai.api_key = token_key
|
| 67 |
|
|
@@ -106,7 +106,7 @@ def ppt2script(token_key, input_file, input_type):
|
|
| 106 |
pdf_reader = PyPDF2.PdfReader(pdf_file)
|
| 107 |
num_pages = len(pdf_reader.pages)
|
| 108 |
|
| 109 |
-
#
|
| 110 |
text = ""
|
| 111 |
for page_num in range(num_pages):
|
| 112 |
page = pdf_reader.pages[page_num]
|
|
@@ -128,12 +128,12 @@ def ppt2script(token_key, input_file, input_type):
|
|
| 128 |
text += run.text
|
| 129 |
|
| 130 |
header = """
|
| 131 |
-
|
| 132 |
-
|
| 133 |
~~~
|
| 134 |
-
- [PAGE_NUM 1]
|
| 135 |
-
-
|
| 136 |
-
-
|
| 137 |
---
|
| 138 |
"""
|
| 139 |
|
|
@@ -156,4 +156,4 @@ def ppt2script(token_key, input_file, input_type):
|
|
| 156 |
reply = chat.choices[0].message.content
|
| 157 |
messages.append({"role": "assistant", "content": reply})
|
| 158 |
|
| 159 |
-
return reply
|
|
|
|
| 8 |
|
| 9 |
sys.path.append("/home/user/app")
|
| 10 |
|
| 11 |
+
# Function to generate text2ppt input prompt
|
| 12 |
def generate_text2ppt_input_prompt(input_type, input_value, input_pages):
|
| 13 |
header = """
|
| 14 |
+
Assume you are a designer creating a PPT using markdown syntax, and write a PPT of %s pages.
|
| 15 |
+
+++ Summarize the content or link below in markdown language, adhering to the rules in ===, and refer to the slide examples in ~~~.
|
| 16 |
+++
|
| 17 |
""" % input_pages
|
| 18 |
|
| 19 |
summary_value = ""
|
| 20 |
|
| 21 |
+
if input_type == "Link":
|
| 22 |
summary_value += input_value
|
| 23 |
summary_value += "\n"
|
| 24 |
+
elif input_type == "Text":
|
| 25 |
summary_value += input_value
|
| 26 |
summary_value += "\n"
|
| 27 |
elif input_type == "PDF":
|
|
|
|
| 29 |
pdf_reader = PyPDF2.PdfReader(pdf_file)
|
| 30 |
num_pages = len(pdf_reader.pages)
|
| 31 |
|
| 32 |
+
# Convert the content of each page to a string.
|
| 33 |
text = ""
|
| 34 |
for page_num in range(num_pages):
|
| 35 |
page = pdf_reader.pages[page_num]
|
|
|
|
| 37 |
summary_value += text
|
| 38 |
summary_value += "\n"
|
| 39 |
else:
|
| 40 |
+
print("ERROR: Invalid input")
|
| 41 |
|
| 42 |
rule_value = """
|
| 43 |
===
|
| 44 |
+
- Write factually only about the content or link provided.
|
| 45 |
+
- Always use --- as a slide divider.
|
| 46 |
+
- Design and arrange the slides diversely with appropriate shapes, images(, https://unsplash.com/ko/images/stock/non-copyrighted for actual use), tables(|-|), quotes(>), emphasis(bold, ``), emojis(https://kr.piliapp.com/twitter-symbols/), icons (https://kr.piliapp.com/symbol/#popular).
|
| 47 |
+
- Use emojis only once in every two pages, and use various other designs.
|
| 48 |
+
- When using images and tables, specify the size considering the page size so that all the text content appears.
|
| 49 |
+
- Make Slide 1 the title, for a total of %s pages.
|
| 50 |
+
- Write the content of the PPT richly in markdown.
|
| 51 |
+
- Don't explain slide by slide, just write the code.
|
| 52 |
+
- Don't write using the content of the example, just refer to the format.
|
| 53 |
~~~
|
| 54 |
+
<!-- Slide 0. Slide Topic -->
|
| 55 |
+
# Slide Title
|
| 56 |
+

|
| 57 |
+
- This is π€**TEXT2PPT service PA!** using ChatGPT.
|
| 58 |
+
- Converts `link`,`text`, `PDF` input or upload into PPT.
|
| 59 |
""" % input_pages
|
| 60 |
|
| 61 |
return header + summary_value + rule_value
|
| 62 |
|
| 63 |
|
| 64 |
+
# Function to execute text2ppt
|
| 65 |
def text2ppt(token_key, input_prompt, input_theme):
|
| 66 |
openai.api_key = token_key
|
| 67 |
|
|
|
|
| 106 |
pdf_reader = PyPDF2.PdfReader(pdf_file)
|
| 107 |
num_pages = len(pdf_reader.pages)
|
| 108 |
|
| 109 |
+
# Convert the content of each page to a string.
|
| 110 |
text = ""
|
| 111 |
for page_num in range(num_pages):
|
| 112 |
page = pdf_reader.pages[page_num]
|
|
|
|
| 128 |
text += run.text
|
| 129 |
|
| 130 |
header = """
|
| 131 |
+
You are an assistant helping with PPT presentations.
|
| 132 |
+
~~~Follow the rules below and write a presentation script for the PPT content below.
|
| 133 |
~~~
|
| 134 |
+
- When [PAGE_NUM 1], where 1 is the page number, write a presentation script for each page number.
|
| 135 |
+
- Write only in text without using markdown language.
|
| 136 |
+
- Add additional explanations or examples to the PPT content.
|
| 137 |
---
|
| 138 |
"""
|
| 139 |
|
|
|
|
| 156 |
reply = chat.choices[0].message.content
|
| 157 |
messages.append({"role": "assistant", "content": reply})
|
| 158 |
|
| 159 |
+
return reply
|