shuhayas commited on
Commit
f0a7d18
·
1 Parent(s): 2cbe1ec
Files changed (1) hide show
  1. app.py +27 -27
app.py CHANGED
@@ -22,23 +22,23 @@ async def generate_context(summaries, system_prompt_prefix, system_prompt_suffix
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}"}
37
- async with session.post(API_URL, json=payload, headers=headers) as response:
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
 
@@ -46,32 +46,35 @@ async def generate_script(context, heading, system_prompt_prefix, system_prompt_
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:
62
- result = await response.json()
63
- return result["choices"][0]["message"]["content"].strip()
 
 
 
 
 
 
 
 
64
 
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="")
74
- script_system_prompt_suffix = st.text_input("Enter the system prompt suffix for script generation:", value="")
75
 
76
  if st.button("Generate Context and Scripts"):
77
  with st.spinner("Generating context..."):
@@ -87,7 +90,4 @@ async def main():
87
  st.header("Generated Scripts")
88
  for heading, script in zip(headings, scripts):
89
  st.subheader(heading)
90
- st.write(script)
91
-
92
- if __name__ == "__main__":
93
- asyncio.run(main())
 
22
  payload = {
23
  "model": "gpt-4-turbo-preview",
24
  "messages": [
25
+ {"role": "system", "content": "You are an AI assistant. Based on the document summary below, please provide a concise context that captures the essential information:"},
 
 
 
 
 
26
  {"role": "user", "content": prompt}
27
  ],
28
  "temperature": 0.7,
29
  "max_tokens": 2048,
30
  }
31
  headers = {"Authorization": f"Bearer {API_KEY}"}
32
+ try:
33
+ async with session.post(API_URL, json=payload, headers=headers) as response:
34
+ if response.status != 200:
35
+ raise Exception(f"Error generating context: {response.status} - {await response.text()}")
36
+ result = await response.json()
37
+ return result["choices"][0]["message"]["content"].strip()
38
+ except Exception as e:
39
+ st.error(f"Error generating context: {str(e)}")
40
+ return None
41
 
 
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
 
 
46
  payload = {
47
  "model": "gpt-4-turbo-preview",
48
  "messages": [
49
+ {"role": "system", "content": f"You are an AI scriptwriter. Your task is to generate a detailed script based on the given context and the provided heading."},
 
 
 
 
 
50
  {"role": "user", "content": prompt}
51
  ],
52
  "temperature": 0.7,
53
  "max_tokens": 4000,
54
  }
55
  headers = {"Authorization": f"Bearer {API_KEY}"}
56
+ try:
57
+ async with session.post(API_URL, json=payload, headers=headers) as response:
58
+ if response.status != 200:
59
+ raise Exception(f"Error generating script: {response.status} - {await response.text()}")
60
+ result = await response.json()
61
+ return result["choices"][0]["message"]["content"].strip()
62
+ except Exception as e:
63
+ st.error(f"Error generating script: {str(e)}")
64
+ return None
65
+
66
+
67
 
68
  async def main():
69
  st.title("Script Generator")
70
 
71
+ context_system_prompt_prefix = st.text_input("Enter the prompt prefix for context generation:", value="You are an AI assistant. Your task is to provide a concise context that captures the essential information from the given document summary.")
72
  summaries = st.text_area("Enter the document summary:", height=200)
73
+ context_system_prompt_suffix = st.text_input("Enter the prompt suffix for context generation:", value="Focus on the key points and main ideas, and present the context in a clear and organized manner.")
74
 
75
  outline = st.text_area("Enter the content outline (one heading per line):", height=200)
76
+ script_system_prompt_prefix = st.text_input("Enter the system prompt prefix for script generation:", value="You are an AI scriptwriter. Your task is to generate a detailed script based on the given context and the provided heading.")
77
+ script_system_prompt_suffix = st.text_input("Enter the system prompt suffix for script generation:", value="The script should be relevant, informative, engaging, and contain more than 600 characters.")
78
 
79
  if st.button("Generate Context and Scripts"):
80
  with st.spinner("Generating context..."):
 
90
  st.header("Generated Scripts")
91
  for heading, script in zip(headings, scripts):
92
  st.subheader(heading)
93
+ st.write(script)