SRankChatGpt/Presentation-Assistant
2
1import os2import presentation_assistant.env_set as env3env.env_set()4print(os.getcwd())5 6import streamlit as st7import PyPDF28import openai9import subprocess10from io import BytesIO11from pptx import Presentation12 13 14import presentation_assistant.presentation_assistant as pa15 16tab1, tab2, tab3 = st.tabs(['What is PA!?', 'Text2PPT', 'PPT2Script'])17 18with tab1:19 st.header('Introduction')20 st.title('PA!(Presentation Assistant):sparkles:')21 contents = """22 ▶ Based on the content entered by the user, it :blue[automatically creates] PPT and23 provides a presentation :red[script] to improve presentation skills!"""24 st.markdown(contents)25 st.markdown('-------------------------')26 st.header('How to use')27 st.subheader('Text2PPT')28 contents = """29 ▶ If the user provides a link or file, we will :blue[create a presentation material] for you!30 The user only needs to select the desired theme (template) type and number of pages!"""31 st.markdown(contents)32 st.subheader('PPT2Script')33 contents = """34 ▶ If the user provides PPT or PDF presentation materials, we will automatically create a :blue[presentation script] for you!"""35 st.markdown(contents)36 37 # Test38 # test_ppt_theme = "--reference-doc="+"/home/user/app/template/blue"+".pptx"39 # subprocess.run(["/home/user/app/pandoc-2.14.2/bin/pandoc", "text2ppt_test.md", "-t", "pptx", test_ppt_theme, "-o", "output.pptx"], capture_output=True)40 # print(os.listdir(os.getcwd()))41 # prs = Presentation("output.pptx")42 # binary_output = BytesIO()43 # prs.save(binary_output)44 # st.download_button(label="Download PPT",45 # data = binary_output.getvalue(),46 # file_name="export_output.pptx",47 # mime='application/octet-stream', key = "<Text2PPT_test_download>")48 49 50with tab2:51 st.header('Text2PPT')52 gpt_token = st.text_input('Please enter your ChatGPT API token.', key="<Text2PPT_token>")53 st.markdown('-------------------------')54 55 st.subheader(':computer: PPT Auto Generator :computer:')56 57 thema_select = st.selectbox(58 'Please select the template you want.',59 ['default', 'yellow', 'gradation_green', 'blue', 'green', 'custom'])60 61 if thema_select == "custom":62 uploaded_template_file = st.file_uploader('Choose File!', type='pptx', key="<template_uploader>")63 64 st.markdown('-------------------------')65 66 page_choice = st.slider('Number of PPT pages', min_value=2, max_value=10, step=1, value=5)67 68 st.markdown('-------------------------')69 70 my_order = ['Text', 'Link', 'PDF']71 status = st.radio('Please select the file type and enter the content! :smile: ', my_order)72 73 # First method74 if status == my_order[0]:75 input_text = st.text_area('Enter TEXT', height=5)76 77 elif status == my_order[1]:78 input_text = st.text_area('Enter URL', height=5)79 80 elif status == my_order[2]:81 input_text = st.file_uploader('Upload PDF', type=['pdf'])82 83 input_text_check = st.button('Confirm', key="<Text2PPT_start>")84 85 st.markdown('-------------------------')86 87 if input_text_check == True:88 with st.spinner('Wait for it...'):89 pa.text2ppt(gpt_token, pa.generate_text2ppt_input_prompt(status, input_text, page_choice), thema_select)90 prs = Presentation("text2ppt_output.pptx")91 binary_output = BytesIO()92 prs.save(binary_output)93 st.success('Done!')94 st.download_button(label="Download PPT",95 data = binary_output.getvalue(),96 file_name="export_output.pptx",97 mime='application/octet-stream', key = "<Text2PPT_download>")98 99with tab3:100 st.header('PPT2Script')101 st.subheader(':computer: Script Auto Generator :computer:')102 gpt_token = st.text_input('Please enter your ChatGPT API token.', key="<PPT2Script_token>")103 st.markdown('-------------------------')104 105 st.subheader(':bookmark_tabs: Presentation Script Generator')106 107 file_order = ['PDF', 'PPT']108 choose = st.radio('Please select the file format of the presentation material', file_order)109 110 if choose == file_order[0]:111 uploaded_file = st.file_uploader('Choose File!', type='pdf', key="<PPT2Script_pdf_uploader>")112 elif choose == file_order[1]:113 uploaded_file = st.file_uploader('Choose File!', type='pptx', key="<PPT2Script_ppt_uploader>")114 115 input_file_check = st.button('Confirm', key="<PPT2Script_start>") # When this button is pressed, the input file should be passed116 st.markdown('-------------------------')117 118 if input_file_check == True:119 with st.spinner('Wait for it...'):120 with open(uploaded_file.name, mode='wb') as w:121 w.write(uploaded_file.getvalue())122 123 script = pa.ppt2script(gpt_token, uploaded_file.name, choose)124 125 st.success('Done!')126 st.download_button('Download Script',127 data=script, file_name="script_output.txt", key="<PPT2Script_download>")128 