shuhayas commited on
Commit
2cbe1ec
·
1 Parent(s): 4786b25
Files changed (1) hide show
  1. app.py +33 -7
app.py CHANGED
@@ -1,19 +1,36 @@
 
 
 
 
 
1
  import os
2
  import asyncio
3
  import streamlit as st
4
  import aiohttp
5
 
 
6
  API_KEY = os.environ["OPENAI_API_KEY"]
7
  API_URL = "https://api.openai.com/v1/chat/completions"
8
 
 
 
 
9
  async def generate_context(summaries, system_prompt_prefix, system_prompt_suffix):
10
  prompt = f"{system_prompt_prefix}\n\nYou are an AI assistant. Based on the document summary below, please provide a concise context that captures the essential information:\n\n{summaries}\n\n{system_prompt_suffix}"
11
 
12
  async with aiohttp.ClientSession() as session:
13
  payload = {
14
  "model": "gpt-4-turbo-preview",
15
- "messages": [{"role": "user", "content": prompt}],
16
- "temperature": 0,
 
 
 
 
 
 
 
 
17
  "max_tokens": 2048,
18
  }
19
  headers = {"Authorization": f"Bearer {API_KEY}"}
@@ -21,15 +38,24 @@ async def generate_context(summaries, system_prompt_prefix, system_prompt_suffix
21
  result = await response.json()
22
  return result["choices"][0]["message"]["content"].strip()
23
 
 
24
  async def generate_script(context, heading, system_prompt_prefix, system_prompt_suffix):
25
  prompt = f"{system_prompt_prefix}\n\n{context}\n\nYou are an AI scriptwriter. Based on the context above and the heading provided below, please generate a detailed script of more than 600 characters.\n\nHeading: {heading}\n\n{system_prompt_suffix}"
26
 
27
  async with aiohttp.ClientSession() as session:
28
  payload = {
29
  "model": "gpt-4-turbo-preview",
30
- "messages": [{"role": "user", "content": prompt}],
31
- "temperature": 0,
32
- "max_tokens": 2048,
 
 
 
 
 
 
 
 
33
  }
34
  headers = {"Authorization": f"Bearer {API_KEY}"}
35
  async with session.post(API_URL, json=payload, headers=headers) as response:
@@ -39,9 +65,9 @@ async def generate_script(context, heading, system_prompt_prefix, system_prompt_
39
  async def main():
40
  st.title("Script Generator")
41
 
 
42
  summaries = st.text_area("Enter the document summary:", height=200)
43
- context_system_prompt_prefix = st.text_input("Enter the system prompt prefix for context generation:", value="")
44
- context_system_prompt_suffix = st.text_input("Enter the system prompt suffix for context generation:", value="")
45
 
46
  outline = st.text_area("Enter the content outline (one heading per line):", height=200)
47
  script_system_prompt_prefix = st.text_input("Enter the system prompt prefix for script generation:", value="")
 
1
+ # This is a simple script generator that uses OpenAI to generate scripts based on a document summary and content outline.
2
+ # It's a Streamlit app that allows the user to input the document summary, content outline, and system prompts for context and script generation.
3
+ # The app generates a context that captures the essential information from the summary, and then generates a detailed script for each heading in the content outline.
4
+ # The scripts are then displayed in the app.
5
+
6
  import os
7
  import asyncio
8
  import streamlit as st
9
  import aiohttp
10
 
11
+ # This is the OpenAI API key and URL.
12
  API_KEY = os.environ["OPENAI_API_KEY"]
13
  API_URL = "https://api.openai.com/v1/chat/completions"
14
 
15
+
16
+ # 1st Step: Generate Context
17
+ # まず初めに、コンテンツの前提条件を作るためにcontextを生成します。
18
  async def generate_context(summaries, system_prompt_prefix, system_prompt_suffix):
19
  prompt = f"{system_prompt_prefix}\n\nYou are an AI assistant. Based on the document summary below, please provide a concise context that captures the essential information:\n\n{summaries}\n\n{system_prompt_suffix}"
20
 
21
  async with aiohttp.ClientSession() as session:
22
  payload = {
23
  "model": "gpt-4-turbo-preview",
24
+ "messages": [
25
+ {"role": "system", "content": """
26
+ System prompt:システムプロンプトは、コンテンツの前提条件を作るために使用されます。
27
+ You are an AI assistant. Based on the document summary below, please provide a concise context that captures the essential information:
28
+ ご自由にお代えください。
29
+ """
30
+ },
31
+ {"role": "user", "content": prompt}
32
+ ],
33
+ "temperature": 0.7,
34
  "max_tokens": 2048,
35
  }
36
  headers = {"Authorization": f"Bearer {API_KEY}"}
 
38
  result = await response.json()
39
  return result["choices"][0]["message"]["content"].strip()
40
 
41
+ # 2nd Step: Generate Scripts
42
  async def generate_script(context, heading, system_prompt_prefix, system_prompt_suffix):
43
  prompt = f"{system_prompt_prefix}\n\n{context}\n\nYou are an AI scriptwriter. Based on the context above and the heading provided below, please generate a detailed script of more than 600 characters.\n\nHeading: {heading}\n\n{system_prompt_suffix}"
44
 
45
  async with aiohttp.ClientSession() as session:
46
  payload = {
47
  "model": "gpt-4-turbo-preview",
48
+ "messages": [
49
+ {"role": "system", "content": """
50
+
51
+
52
+
53
+ System prompt:システムプロンプトは、コンテンツの前提条件を作るために使用されます。"""
54
+ },
55
+ {"role": "user", "content": prompt}
56
+ ],
57
+ "temperature": 0.7,
58
+ "max_tokens": 4000,
59
  }
60
  headers = {"Authorization": f"Bearer {API_KEY}"}
61
  async with session.post(API_URL, json=payload, headers=headers) as response:
 
65
  async def main():
66
  st.title("Script Generator")
67
 
68
+ context_system_prompt_prefix = st.text_input("Enter the prompt prefix for context generation:", value="")
69
  summaries = st.text_area("Enter the document summary:", height=200)
70
+ context_system_prompt_suffix = st.text_input("Enter the prompt suffix for context generation:", value="")
 
71
 
72
  outline = st.text_area("Enter the content outline (one heading per line):", height=200)
73
  script_system_prompt_prefix = st.text_input("Enter the system prompt prefix for script generation:", value="")