Spaces:
Running
Running
Add error message when JSON conversion fails; use empty placeholders to display notice before generating bonus stuff
Browse files
app.py
CHANGED
|
@@ -9,7 +9,6 @@ import llm_helper
|
|
| 9 |
import pptx_helper
|
| 10 |
from global_config import GlobalConfig
|
| 11 |
|
| 12 |
-
|
| 13 |
APP_TEXT = json5.loads(open(GlobalConfig.APP_STRINGS_FILE, 'r').read())
|
| 14 |
|
| 15 |
|
|
@@ -186,14 +185,28 @@ def process_slides_contents(text: str, progress_bar: st.progress):
|
|
| 186 |
"""
|
| 187 |
|
| 188 |
print('JSON button clicked')
|
| 189 |
-
json_str =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 190 |
# yaml_str = llm_helper.text_to_yaml(text)
|
| 191 |
print('=' * 20)
|
| 192 |
print(f'JSON:\n{json_str}')
|
| 193 |
print('=' * 20)
|
| 194 |
st.code(json_str, language='json')
|
| 195 |
|
| 196 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
|
| 198 |
# Now, step 3
|
| 199 |
st.divider()
|
|
@@ -238,41 +251,82 @@ def process_slides_contents(text: str, progress_bar: st.progress):
|
|
| 238 |
with open(output_file_name, 'rb') as f:
|
| 239 |
st.download_button('Download PPTX file', f, file_name=output_file_name)
|
| 240 |
|
| 241 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 242 |
|
| 243 |
st.divider()
|
| 244 |
st.text(APP_TEXT['tos'])
|
| 245 |
st.text(APP_TEXT['tos2'])
|
| 246 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 247 |
|
| 248 |
-
def show_bonus_stuff(
|
|
|
|
|
|
|
|
|
|
| 249 |
"""
|
| 250 |
Show relevant links and images for the presentation topic.
|
| 251 |
|
| 252 |
:param ppt_headers: A list of all slide headers
|
| 253 |
"""
|
| 254 |
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 258 |
|
| 259 |
-
|
| 260 |
|
| 261 |
# Use the presentation title and the slides headers to find relevant info online
|
| 262 |
ppt_text = ' '.join(ppt_headers)
|
| 263 |
search_results = get_web_search_results_wrapper(ppt_text)
|
|
|
|
| 264 |
|
| 265 |
for (title, link) in search_results:
|
| 266 |
-
|
|
|
|
|
|
|
| 267 |
|
| 268 |
-
|
| 269 |
-
|
| 270 |
image = get_ai_image_wrapper(ppt_text)
|
| 271 |
|
| 272 |
if len(image) > 0:
|
| 273 |
image = base64.b64decode(image)
|
| 274 |
-
|
| 275 |
-
|
| 276 |
|
| 277 |
|
| 278 |
def button_clicked(button):
|
|
|
|
| 9 |
import pptx_helper
|
| 10 |
from global_config import GlobalConfig
|
| 11 |
|
|
|
|
| 12 |
APP_TEXT = json5.loads(open(GlobalConfig.APP_STRINGS_FILE, 'r').read())
|
| 13 |
|
| 14 |
|
|
|
|
| 185 |
"""
|
| 186 |
|
| 187 |
print('JSON button clicked')
|
| 188 |
+
json_str = ''
|
| 189 |
+
|
| 190 |
+
try:
|
| 191 |
+
json_str = get_json_wrapper(text)
|
| 192 |
+
except Exception as ex:
|
| 193 |
+
st.error(f'An exception occurred while trying to convert to JSON.'
|
| 194 |
+
f' It could be because of heavy traffic or something else.'
|
| 195 |
+
f' Try doing it again or try again later.\n'
|
| 196 |
+
f' Error message: {ex}')
|
| 197 |
+
# st.stop()
|
| 198 |
+
|
| 199 |
# yaml_str = llm_helper.text_to_yaml(text)
|
| 200 |
print('=' * 20)
|
| 201 |
print(f'JSON:\n{json_str}')
|
| 202 |
print('=' * 20)
|
| 203 |
st.code(json_str, language='json')
|
| 204 |
|
| 205 |
+
if len(json_str) > 0:
|
| 206 |
+
progress_bar.progress(100, text='Done!')
|
| 207 |
+
else:
|
| 208 |
+
st.error('Unfortunately, JSON generation failed, so the next steps would lead to nowhere.'
|
| 209 |
+
' Try again or come back later.')
|
| 210 |
|
| 211 |
# Now, step 3
|
| 212 |
st.divider()
|
|
|
|
| 251 |
with open(output_file_name, 'rb') as f:
|
| 252 |
st.download_button('Download PPTX file', f, file_name=output_file_name)
|
| 253 |
|
| 254 |
+
bonus_divider = st.empty()
|
| 255 |
+
bonus_header = st.empty()
|
| 256 |
+
bonus_caption = st.empty()
|
| 257 |
+
|
| 258 |
+
urls_text = st.empty()
|
| 259 |
+
urls_list = st.empty()
|
| 260 |
+
|
| 261 |
+
img_empty = st.empty()
|
| 262 |
+
img_text = st.empty()
|
| 263 |
+
img_contents = st.empty()
|
| 264 |
+
img_tip = st.empty()
|
| 265 |
|
| 266 |
st.divider()
|
| 267 |
st.text(APP_TEXT['tos'])
|
| 268 |
st.text(APP_TEXT['tos2'])
|
| 269 |
|
| 270 |
+
show_bonus_stuff(
|
| 271 |
+
all_headers,
|
| 272 |
+
bonus_divider,
|
| 273 |
+
bonus_header,
|
| 274 |
+
bonus_caption,
|
| 275 |
+
urls_text,
|
| 276 |
+
urls_list,
|
| 277 |
+
img_empty,
|
| 278 |
+
img_text,
|
| 279 |
+
img_contents,
|
| 280 |
+
img_tip
|
| 281 |
+
)
|
| 282 |
+
|
| 283 |
|
| 284 |
+
def show_bonus_stuff(
|
| 285 |
+
ppt_headers: List,
|
| 286 |
+
*st_placeholders
|
| 287 |
+
):
|
| 288 |
"""
|
| 289 |
Show relevant links and images for the presentation topic.
|
| 290 |
|
| 291 |
:param ppt_headers: A list of all slide headers
|
| 292 |
"""
|
| 293 |
|
| 294 |
+
(
|
| 295 |
+
bonus_divider,
|
| 296 |
+
bonus_header,
|
| 297 |
+
bonus_caption,
|
| 298 |
+
urls_text,
|
| 299 |
+
urls_list,
|
| 300 |
+
img_empty,
|
| 301 |
+
img_text,
|
| 302 |
+
img_contents,
|
| 303 |
+
img_tip
|
| 304 |
+
) = st_placeholders
|
| 305 |
+
|
| 306 |
+
bonus_divider.divider()
|
| 307 |
+
bonus_header.header(APP_TEXT['section_headers'][3])
|
| 308 |
+
bonus_caption.caption(APP_TEXT['section_captions'][3])
|
| 309 |
|
| 310 |
+
urls_text.write(APP_TEXT['urls_info'])
|
| 311 |
|
| 312 |
# Use the presentation title and the slides headers to find relevant info online
|
| 313 |
ppt_text = ' '.join(ppt_headers)
|
| 314 |
search_results = get_web_search_results_wrapper(ppt_text)
|
| 315 |
+
md_text_items = []
|
| 316 |
|
| 317 |
for (title, link) in search_results:
|
| 318 |
+
md_text_items.append(f'[{title}]({link})')
|
| 319 |
+
|
| 320 |
+
urls_list.markdown('\n\n'.join(md_text_items))
|
| 321 |
|
| 322 |
+
img_empty.write('')
|
| 323 |
+
img_text.write(APP_TEXT['image_info'])
|
| 324 |
image = get_ai_image_wrapper(ppt_text)
|
| 325 |
|
| 326 |
if len(image) > 0:
|
| 327 |
image = base64.b64decode(image)
|
| 328 |
+
img_contents.image(image, caption=ppt_text)
|
| 329 |
+
img_tip.info('Tip: Right-click on the image to save it.', icon="ℹ️")
|
| 330 |
|
| 331 |
|
| 332 |
def button_clicked(button):
|