Spaces:
Running
Running
Add exception handling for JSON parsing and slide deck generation
Browse files- chat_app.py +15 -9
- strings.json +4 -3
chat_app.py
CHANGED
@@ -139,12 +139,11 @@ def set_up_chat_ui():
|
|
139 |
progress_bar_pptx.progress(100, text='Done!')
|
140 |
|
141 |
|
142 |
-
def generate_slide_deck(json_str: str)
|
143 |
"""
|
144 |
Create a slide deck.
|
145 |
|
146 |
:param json_str: The content in *valid* JSON format.
|
147 |
-
:return: A list of all slide headers and the title.
|
148 |
"""
|
149 |
|
150 |
if DOWNLOAD_FILE_KEY in st.session_state:
|
@@ -157,15 +156,22 @@ def generate_slide_deck(json_str: str) -> List:
|
|
157 |
logger.debug('DOWNLOAD_FILE_KEY not found in session')
|
158 |
|
159 |
logger.debug('Creating PPTX file: %s...', st.session_state[DOWNLOAD_FILE_KEY])
|
160 |
-
all_headers = pptx_helper.generate_powerpoint_presentation(
|
161 |
-
json_str,
|
162 |
-
slides_template=pptx_template,
|
163 |
-
output_file_path=path
|
164 |
-
)
|
165 |
|
166 |
-
|
|
|
|
|
|
|
|
|
|
|
167 |
|
168 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
169 |
|
170 |
|
171 |
def _clean_json(json_str: str) -> str:
|
|
|
139 |
progress_bar_pptx.progress(100, text='Done!')
|
140 |
|
141 |
|
142 |
+
def generate_slide_deck(json_str: str):
|
143 |
"""
|
144 |
Create a slide deck.
|
145 |
|
146 |
:param json_str: The content in *valid* JSON format.
|
|
|
147 |
"""
|
148 |
|
149 |
if DOWNLOAD_FILE_KEY in st.session_state:
|
|
|
156 |
logger.debug('DOWNLOAD_FILE_KEY not found in session')
|
157 |
|
158 |
logger.debug('Creating PPTX file: %s...', st.session_state[DOWNLOAD_FILE_KEY])
|
|
|
|
|
|
|
|
|
|
|
159 |
|
160 |
+
try:
|
161 |
+
pptx_helper.generate_powerpoint_presentation(
|
162 |
+
json_str,
|
163 |
+
slides_template=pptx_template,
|
164 |
+
output_file_path=path
|
165 |
+
)
|
166 |
|
167 |
+
_display_download_button(path)
|
168 |
+
except ValueError as ve:
|
169 |
+
st.error(APP_TEXT['json_parsing_error'])
|
170 |
+
logger.error('%s', APP_TEXT['json_parsing_error'])
|
171 |
+
logger.error('Additional error info: %s', str(ve))
|
172 |
+
except Exception as ex:
|
173 |
+
st.error(APP_TEXT['content_generation_error'])
|
174 |
+
logger.error('Caught a generic exception: %s', str(ex))
|
175 |
|
176 |
|
177 |
def _clean_json(json_str: str) -> str:
|
strings.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
{
|
2 |
"app_name": ":green[SlideDeck AI $^{[Reloaded]}$]",
|
3 |
-
"caption": "Converse, create, iterate, and improve your next PowerPoint slide deck",
|
4 |
"section_headers": [
|
5 |
"Step 1: Generate your content",
|
6 |
"Step 2: Make it structured",
|
@@ -23,13 +23,14 @@
|
|
23 |
],
|
24 |
"urls_info": "Here is a list of some online resources that you can consult for further information on this topic:",
|
25 |
"image_info": "Got some more minutes? We are also trying to deliver an AI-generated art on the presentation topic, fresh off the studio, just for you!",
|
26 |
-
"
|
|
|
27 |
"tos": "SlideDeck AI is an experimental prototype, and it has its limitations.\nPlease carefully review any and all AI-generated content.",
|
28 |
"tos2": "By using SlideDeck AI, you agree to fair and responsible usage.\nNo liability assumed by any party.",
|
29 |
"ai_greetings": [
|
30 |
"How may I help you today?",
|
31 |
"Stuck with creating your presentation? Let me help you.",
|
32 |
-
"Looks like you have a looming deadline. Can I help you
|
33 |
"Hello! What topic do you have on your mind today?"
|
34 |
],
|
35 |
"chat_placeholder": "Write the topic or instructions here"
|
|
|
1 |
{
|
2 |
"app_name": ":green[SlideDeck AI $^{[Reloaded]}$]",
|
3 |
+
"caption": "*Converse, create, iterate, and improve your next PowerPoint slide deck*",
|
4 |
"section_headers": [
|
5 |
"Step 1: Generate your content",
|
6 |
"Step 2: Make it structured",
|
|
|
23 |
],
|
24 |
"urls_info": "Here is a list of some online resources that you can consult for further information on this topic:",
|
25 |
"image_info": "Got some more minutes? We are also trying to deliver an AI-generated art on the presentation topic, fresh off the studio, just for you!",
|
26 |
+
"content_generation_error": "Unfortunately, SlideDeck AI failed to generate any content for you! Please try again later.",
|
27 |
+
"json_parsing_error": "Unfortunately, SlideDeck AI failed to parse the response from LLM! Please try again by rephrasing the query or refreshing the page.",
|
28 |
"tos": "SlideDeck AI is an experimental prototype, and it has its limitations.\nPlease carefully review any and all AI-generated content.",
|
29 |
"tos2": "By using SlideDeck AI, you agree to fair and responsible usage.\nNo liability assumed by any party.",
|
30 |
"ai_greetings": [
|
31 |
"How may I help you today?",
|
32 |
"Stuck with creating your presentation? Let me help you.",
|
33 |
+
"Looks like you have a looming deadline. Can I help you get started with your slide deck?",
|
34 |
"Hello! What topic do you have on your mind today?"
|
35 |
],
|
36 |
"chat_placeholder": "Write the topic or instructions here"
|