PPT / app.py
shuhayas's picture
Update app.py
7a4a464 verified
import streamlit as st
import requests
import asyncio
import json
openai_api_key = st.text_input("OpenAI APIキーを入力してください:", type="password")
section_titles_prompt = """
あなたは、与えられたプレゼンテーションのタイトルとメモに基づいて、プレゼンテーションのセクションタイトルを生成するアシスタントです。
あなたの役割は、プレゼンテーションの主要なポイントを網羅する、簡潔で分かりやすく、魅力的なセクションタイトルのリストを作成することです。
セクションタイトルは、プレゼンテーションの内容を効果的に伝えるために、重要で関連性が高いものでなければなりません。
セクションタイトルは簡潔で、通常は10語以内とします。
セクションタイトルは、聴衆の興味を引き付け、各セクションの内容についてもっと知りたいと思わせるものであるべきです。
セクションタイトルはカンマ区切りのリストとして提供してください。
"""
slide_elements_prompt = """
与えられたセクションタイトルとメモに基づいて、プレゼンテーションのスライド要素を生成するアシスタントです。
あなたの役割は、与えられたセクションタイトルに関連するキーポイントとアイデアを効果的に伝える、情報に富んだ魅力的で構造化されたスライド要素を作成することです。
スライド要素には以下のエレメントを使用することができます:
1. メッセージ
2. ヘッダー
3. ボディ
スライド要素は、明確で簡潔な方法で提供し、以下の形式を使用してください:
インデント構造を使用して、メッセージ、ヘッダー、ボディを区別します。
区切り記号”,”
"""
async def generate_content(system_prompt, user_prompt):
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {openai_api_key}"
}
data = {
"model": "gpt-4-turbo-preview",
"messages": [
{"role": "system", "content": system_prompt},
{"role": "user", "content": user_prompt}
],
"temperature": 0,
"max_tokens": 4000,
"top_p": 1,
"frequency_penalty": 0,
"presence_penalty": 0
}
response = requests.post("https://api.openai.com/v1/chat/completions", headers=headers, data=json.dumps(data))
response_json = response.json()
return response_json["choices"][0]["message"]["content"].strip()
async def generate_section_titles(presentation_title, memo):
user_prompt = f"プレゼンテーションのタイトル: {presentation_title}\nメモ: {memo}"
section_titles = await generate_content(section_titles_prompt, user_prompt)
return section_titles.split(", ")
async def generate_slide_elements(section_title, memo):
user_prompt = f"セクションタイトル: {section_title}\nメモ: {memo}"
slide_elements = await generate_content(slide_elements_prompt, user_prompt)
return slide_elements
async def generate_presentation_content(presentation_title, memo):
section_titles = await generate_section_titles(presentation_title, memo)
presentation_content = []
for section_title in section_titles:
status_placeholder = st.empty()
status_placeholder.text(f"セクション処理中: {section_title}...")
slide_elements = await generate_slide_elements(section_title, memo)
presentation_content.append((section_title, slide_elements))
status_placeholder.empty()
st.subheader(section_title)
st.write(slide_elements)
return presentation_content
def main():
st.title("プレゼンテーションコンテンツジェネレータ")
presentation_title = st.text_input("プレゼンテーションのタイトルを入力してください:")
memo = st.text_area("プレゼンテーションのメモを入力してください:", height=200)
if st.button("プレゼンテーションを生成"):
presentation_content = asyncio.run(generate_presentation_content(presentation_title, memo))
st.header(presentation_title)
for section_title, slide_elements in presentation_content:
st.subheader(section_title)
st.write(slide_elements)
if __name__ == "__main__":
main()