Hyeonseo's picture
Update app.py
e392417
raw
history blame
5.14 kB
import os
import presentation_assistant.env_set as env
env.env_set()
print(os.getcwd())
import streamlit as st
import PyPDF2
import openai
import subprocess
from io import BytesIO
from pptx import Presentation
import presentation_assistant.presentation_assistant as pa
tab1, tab2, tab3 = st.tabs(['PA!λž€?', 'Text2PPT', 'PPT2Script'])
with tab1:
st.header('μ†Œκ°œ')
st.title('PA!(Presentation Assistant):sparkles:')
contents = """
β–Ά μ‚¬μš©μžκ°€ μž…λ ₯ν•œ λ‚΄μš©μ„ 기반으둜 PPTλ₯Ό :blue[μžλ™ μ œμž‘]ν•˜κ³ ,
ν”„λ ˆμ  ν…Œμ΄μ…˜ :red[슀크립트λ₯Ό 제곡]ν•˜μ—¬ ν”„λ ˆμ  ν…Œμ΄μ…˜ μ—­λŸ‰μ„ ν–₯μƒμ‹œν‚΅λ‹ˆλ‹€!"""
st.markdown(contents)
st.markdown('-------------------------')
st.header('μ‚¬μš©λ²•')
st.subheader('Text2PPT')
contents = """
β–Ά μ‚¬μš©μžμ—κ²Œ λ§ν¬λ‚˜ νŒŒμΌμ„ μ „λ‹¬λ°›μœΌλ©΄ κ·Έ λ‚΄μš©μœΌλ‘œ :blue[λ°œν‘œ 자료λ₯Ό μ œμž‘]ν•΄ λ“œλ¦½λ‹ˆλ‹€!
μ‚¬μš©μžλŠ” μ›ν•˜λŠ” ν…Œλ§ˆ(ν…œν”Œλ¦Ώ) μ’…λ₯˜μ™€ νŽ˜μ΄μ§€ 수만 μ„ νƒν•˜μ„Έμš”!"""
st.markdown(contents)
st.subheader('PPT2Script')
contents = """
β–Ά PPT λ˜λŠ” PDF λ°œν‘œ 자료λ₯Ό μ‚¬μš©μžλ‘œλΆ€ν„° μ œκ³΅λ°›μœΌλ©΄ μžλ™μœΌλ‘œ :blue[λ°œν‘œ λŒ€λ³Έ]을 λ§Œλ“€μ–΄λ“œλ¦½λ‹ˆλ‹€!"""
st.markdown(contents)
# ν…ŒμŠ€νŠΈ
test_ppt_theme = "--reference-doc="+"/home/user/app/template/blue"+".pptx"
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)
print(os.listdir(os.getcwd()))
prs = Presentation("output.pptx")
binary_output = BytesIO()
prs.save(binary_output)
st.download_button(label="Download PPT",
data = binary_output.getvalue(),
file_name="export_output.pptx",
mime='application/octet-stream', key = "<Text2PPT_test_download>")
with tab2:
st.header('Text2PPT')
gpt_token = st.text_input('μ±—GPT API 토큰을 μž…λ ₯ν•΄μ£Όμ„Έμš”.', key="<Text2PPT_token>")
st.markdown('-------------------------')
st.subheader(':computer:PPT μžλ™ 생성기:computer:')
thema_select = st.selectbox(
'μ›ν•˜λŠ” ν…œν”Œλ¦Ώμ„ μ„ νƒν•˜μ„Έμš”.',
['default', 'yellow', 'blue', 'green', 'custom'])
if thema_select == "custom":
uploaded_template_file = st.file_uploader('Choose File!', type='pptx', key="<template_uploader>")
st.markdown('-------------------------')
page_choice = st.slider('PPT νŽ˜μ΄μ§€ μž₯수', min_value=2, max_value=10, step=1, value=5)
st.markdown('-------------------------')
my_order = ['ν…μŠ€νŠΈ', '링크', 'PDF']
status = st.radio('파일 μ’…λ₯˜λ₯Ό μ„ νƒν•˜κ³  λ‚΄μš©μ„ μž…λ ₯ν•˜μ„Έμš”! :smile: ', my_order)
# 첫번째 방법
if status == my_order[0]:
input_text = st.text_area('TEXTλ₯Ό μž…λ ₯ν•˜μ„Έμš”', height=5)
elif status == my_order[1]:
input_text = st.text_area('URL을 μž…λ ₯ν•˜μ„Έμš”', height=5)
elif status == my_order[2]:
input_text = st.file_uploader('PDFλ₯Ό μ—…λ‘œλ“œ ν•˜μ„Έμš”', type=['pdf'])
input_text_check = st.button('확인', key="<Text2PPT_start>")
st.markdown('-------------------------')
if input_text_check == True:
with st.spinner('Wait for it...'):
pa.text2ppt(gpt_token, pa.generate_text2ppt_input_prompt(status, input_text, page_choice), thema_select)
prs = Presentation("text2ppt_output.pptx")
binary_output = BytesIO()
prs.save(binary_output)
st.success('Done!')
st.download_button(label="Download PPT",
data = binary_output.getvalue(),
file_name="export_output.pptx",
mime='application/octet-stream', key = "<Text2PPT_download>")
with tab3:
st.header('PPT2Script')
st.subheader(':computer:Script μžλ™ 생성기:computer:')
gpt_token = st.text_input('μ±—GPT API 토큰을 μž…λ ₯ν•΄μ£Όμ„Έμš”.', key="<PPT2Script_token>")
st.markdown('-------------------------')
st.subheader(':bookmark_tabs:λ°œν‘œ λŒ€λ³Έ 생성기')
file_order = ['PDF', 'PPT']
choose = st.radio('λ°œν‘œ 자료의 파일 ν˜•μ‹μ„ 선택해 μ£Όμ„Έμš”', file_order)
if choose == file_order[0]:
uploaded_file = st.file_uploader('Choose File!', type='pdf', key="<PPT2Script_pdf_uploader>")
elif choose == file_order[1]:
uploaded_file = st.file_uploader('Choose File!', type='pptx', key="<PPT2Script_ppt_uploader>")
input_file_check = st.button('확인', key="<PPT2Script_start>") # 이 λ²„νŠΌ λˆ„λ₯΄λ©΄ μž…λ ₯ 파일이 λ„˜μ–΄κ°€κ²Œ 해야함
st.markdown('-------------------------')
if input_file_check == True:
with st.spinner('Wait for it...'):
with open(uploaded_file.name, mode='wb') as w:
w.write(uploaded_file.getvalue())
script = pa.ppt2script(gpt_token, uploaded_file.name, choose)
st.success('Done!')
st.download_button('Download Script',
data=script, file_name="script_output.txt", key="<PPT2Script_download>")