Spaces:
Runtime error
Runtime error
Masa-digital-art
commited on
Commit
•
a34d0dd
0
Parent(s):
Duplicate from Masa-digital-art/save-the-cat-16k
Browse files- .gitattributes +34 -0
- README.md +13 -0
- app.py +128 -0
- constraints.md +88 -0
- requirements.txt +2 -0
- template.md +60 -0
.gitattributes
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: AI-Save-The-Cat-β-16k
|
3 |
+
emoji: 🌖
|
4 |
+
colorFrom: yellow
|
5 |
+
colorTo: red
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.19.1
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
duplicated_from: Masa-digital-art/save-the-cat-16k
|
11 |
+
---
|
12 |
+
|
13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import openai
|
3 |
+
import requests
|
4 |
+
import os
|
5 |
+
import fileinput
|
6 |
+
from dotenv import load_dotenv
|
7 |
+
|
8 |
+
title="AI-Save-the-Cat-β-16k"
|
9 |
+
inputs_label="""
|
10 |
+
- 物語の元になるアイデアやキーワード(物語のあらすじ、登場人物とその設定、物語の舞台、出来事など)を入力してください。
|
11 |
+
"""
|
12 |
+
outputs_label="物語の提案"
|
13 |
+
description="""
|
14 |
+
- あなたが入力したアイデアやキーワードに応じて、AIがSave the Catのフレームワークを用いて、物語のプロットを提案します。
|
15 |
+
"""
|
16 |
+
|
17 |
+
article = """
|
18 |
+
<ul>
|
19 |
+
<li style="font-size: small;">楽しんでいただけたら、Likeのクリックをお願いします。</li>
|
20 |
+
</ul>
|
21 |
+
|
22 |
+
<ul>
|
23 |
+
<li style="font-size: small;">よかったらフィードバックの収集にご協力お願いします <a href="https://forms.gle/bLxs2h22JvQK4zwP8">https://forms.gle/bLxs2h22JvQK4zwP8</a></li>
|
24 |
+
</ul>
|
25 |
+
|
26 |
+
<h5>リリースノート</h5>
|
27 |
+
<ul>
|
28 |
+
<li style="font-size: small;">2023-06-26 ver1.0</li>
|
29 |
+
</ul>
|
30 |
+
|
31 |
+
<h5>注意事項</h5>
|
32 |
+
<ul>
|
33 |
+
<li style="font-size: small;">当サービスでは、2023/6/14にリリースされたOpenAI社のChatGPT APIのgpt-3.5-turbo-16kを使用しております。</li>
|
34 |
+
<li style="font-size: small;">当サービスで生成されたコンテンツは、OpenAI が提供する人工知能によるものであり、当サービスやOpenAI がその正確性や信頼性を保証するものではありません。</li>
|
35 |
+
<li style="font-size: small;"><a href="https://platform.openai.com/docs/usage-policies">OpenAI の利用規約</a>に従い、データ保持しない方針です(ただし諸般の事情によっては変更する可能性はございます)。
|
36 |
+
<li style="font-size: small;">当サービスで生成されたコンテンツは事実確認をした上で、コンテンツ生成者およびコンテンツ利用者の責任において利用してください。</li>
|
37 |
+
<li style="font-size: small;">当サービスでの使用により発生したいかなる損害についても、当社は一切の責任を負いません。</li>
|
38 |
+
<li style="font-size: small;">当サービスはβ版のため、予告なくサービスを終了する場合がございます。</li>
|
39 |
+
</ul>
|
40 |
+
"""
|
41 |
+
|
42 |
+
load_dotenv()
|
43 |
+
openai.api_key = os.getenv('OPENAI_API_KEY')
|
44 |
+
MODEL = "gpt-3.5-turbo-16k"
|
45 |
+
|
46 |
+
def get_filetext(filename, cache={}):
|
47 |
+
if filename in cache:
|
48 |
+
# キャッシュに保存されている場合は、キャッシュからファイル内容を取得する
|
49 |
+
return cache[filename]
|
50 |
+
else:
|
51 |
+
if not os.path.exists(filename):
|
52 |
+
raise ValueError(f"ファイル '{filename}' が見つかりませんでした")
|
53 |
+
with open(filename, "r") as f:
|
54 |
+
text = f.read()
|
55 |
+
# ファイル内容をキャッシュする
|
56 |
+
cache[filename] = text
|
57 |
+
return text
|
58 |
+
|
59 |
+
class OpenAI:
|
60 |
+
|
61 |
+
@classmethod
|
62 |
+
def chat_completion(cls, prompt, start_with=""):
|
63 |
+
constraints = get_filetext(filename = "constraints.md")
|
64 |
+
template = get_filetext(filename = "template.md")
|
65 |
+
|
66 |
+
# ChatCompletion APIに渡すデータを定義する
|
67 |
+
data = {
|
68 |
+
"model": "gpt-3.5-turbo-16k",
|
69 |
+
"messages": [
|
70 |
+
{"role": "system", "content": constraints}
|
71 |
+
,{"role": "system", "content": template}
|
72 |
+
,{"role": "assistant", "content": "Sure!"}
|
73 |
+
,{"role": "user", "content": prompt}
|
74 |
+
,{"role": "assistant", "content": start_with}
|
75 |
+
],
|
76 |
+
}
|
77 |
+
|
78 |
+
# ChatCompletion APIを呼び出す
|
79 |
+
response = requests.post(
|
80 |
+
"https://api.openai.com/v1/chat/completions",
|
81 |
+
headers={
|
82 |
+
"Content-Type": "application/json",
|
83 |
+
"Authorization": f"Bearer {openai.api_key}"
|
84 |
+
},
|
85 |
+
json=data
|
86 |
+
)
|
87 |
+
|
88 |
+
# ChatCompletion APIから返された結果を取得する
|
89 |
+
result = response.json()
|
90 |
+
print(result)
|
91 |
+
content = result["choices"][0]["message"]["content"].strip()
|
92 |
+
return content
|
93 |
+
|
94 |
+
class MasaAI:
|
95 |
+
|
96 |
+
@classmethod
|
97 |
+
def generate_emo_prompt(cls, user_message):
|
98 |
+
template = get_filetext(filename="template.md")
|
99 |
+
prompt = f"""
|
100 |
+
{user_message}
|
101 |
+
---
|
102 |
+
上記を元に、下記テンプレートを日本語で埋めてください。
|
103 |
+
---
|
104 |
+
{template}
|
105 |
+
"""
|
106 |
+
return prompt
|
107 |
+
|
108 |
+
@classmethod
|
109 |
+
def generate_emo(cls, user_message):
|
110 |
+
prompt = MasaAI.generate_emo_prompt(user_message);
|
111 |
+
start_with = ""
|
112 |
+
result = OpenAI.chat_completion(prompt=prompt, start_with=start_with)
|
113 |
+
return result
|
114 |
+
|
115 |
+
def main():
|
116 |
+
iface = gr.Interface(fn=MasaAI.generate_emo,
|
117 |
+
inputs=gr.Textbox(label=inputs_label),
|
118 |
+
outputs=gr.Textbox(label=outputs_label),
|
119 |
+
title=title,
|
120 |
+
description=description,
|
121 |
+
article=article,
|
122 |
+
allow_flagging='never'
|
123 |
+
)
|
124 |
+
|
125 |
+
iface.launch()
|
126 |
+
|
127 |
+
if __name__ == '__main__':
|
128 |
+
main()
|
constraints.md
ADDED
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# constraints
|
2 |
+
|
3 |
+
- You are a talented consultant.
|
4 |
+
- Use your exceptional storytelling, screenwriting, dramaturgy, directing and filmmaking skills to the best of your ability to carry out the following tasks in the order listed below
|
5 |
+
|
6 |
+
# Task.
|
7 |
+
|
8 |
+
## Abstraction of user input
|
9 |
+
|
10 |
+
- Interpret user input in an abstract way to obtain parameters that will underlie the idea of the story's theme, main characters, story world, what the protagonist does, etc.
|
11 |
+
|
12 |
+
## Quickly generate ideas for each part of the story
|
13 |
+
|
14 |
+
- Generate story ideas by abstractly interpreting user input for each of the following parts
|
15 |
+
- Brainstorm ideas that are coherent as a whole, referring to the ideas in the previous parts
|
16 |
+
- You are to output concrete descriptions of characters, actions, and scenes, without abstract adjectives, ambiguous expressions, or constraining directives.
|
17 |
+
|
18 |
+
### I. Introduction (Act 1)
|
19 |
+
|
20 |
+
- The overriding goal of this part is to make the audience feel a strong empathy for the main character or other major characters, to replace them with themselves, and to project themselves into the world of the story.
|
21 |
+
- This part of the film will reveal the world of the story, the character of the protagonist, the issues he or she deals with, and will suggest the thematic nature of the work.
|
22 |
+
|
23 |
+
- Setup
|
24 |
+
- Setup: Strongly impresses the reader with the world in which the story takes place and the initial state of the protagonist's life.
|
25 |
+
- Describes the goals, aspirations, and problems of the protagonist and encourages the viewer to identify with him or her.
|
26 |
+
- Describe who, what world, and what their experiences are in short, memorable episodes.
|
27 |
+
|
28 |
+
- Theme Stated
|
29 |
+
- The overall theme or subject of the story is implied or explicitly presented.
|
30 |
+
- This is also the lesson the protagonist is to learn as the story progresses.
|
31 |
+
|
32 |
+
- Dilemma & Debate
|
33 |
+
- Identifies the main problem or challenge the protagonist faces
|
34 |
+
- Describes how the protagonist wonders how to solve this problem
|
35 |
+
|
36 |
+
- Break Into Two
|
37 |
+
- The protagonist makes a decision to address the problem and the story takes a new direction.
|
38 |
+
- Break Into Two: The protagonist makes a decision to address the problem and the story takes a new direction.
|
39 |
+
|
40 |
+
### II. The middle part (Act 2)
|
41 |
+
|
42 |
+
- Introduce key characters who will have a significant impact on the protagonist's destiny
|
43 |
+
- II. Act 2: The protagonist's challenges, growth, and fulfillment of the story's promise.
|
44 |
+
|
45 |
+
- B Story
|
46 |
+
- Subplots begin, depicting episodes that delve deeper into the protagonist's internal growth and relationships.
|
47 |
+
|
48 |
+
- Fun and Games
|
49 |
+
- Draws on the "promise" you expect from the film.
|
50 |
+
- Depicts different elements of the genre, such as action scenes, humorous moments, romance, etc.
|
51 |
+
|
52 |
+
- Midpoint
|
53 |
+
- Midpoint is the point in the story where the protagonist's situation changes dramatically.
|
54 |
+
- Major changes can include success, failure, or both
|
55 |
+
- The protagonist suffers, worries, and struggles, and this is a strong emotional response from the audience.
|
56 |
+
|
57 |
+
- Bad Guys Close In
|
58 |
+
- The protagonist's problems are exacerbated.
|
59 |
+
- Can be due to an external threat, internal conflict, or both.
|
60 |
+
- Provides a prelude to the next part of the play and keeps the audience on the edge of their seats.
|
61 |
+
|
62 |
+
### III. The final part (Act 3)
|
63 |
+
|
64 |
+
- The main character faces a great challenge
|
65 |
+
- The protagonist faces his greatest challenge, an identity crisis, a disintegrating experience of mind and body.
|
66 |
+
- It depicts the protagonist's eventual growth and the resolution of the story.
|
67 |
+
|
68 |
+
- Break Into Three
|
69 |
+
- The protagonist faces a major challenge and has an identity crisis that relates to the theme of the story and his/her identity.
|
70 |
+
- The protagonist experiences a major setback and goes through a crisis situation where his mind and body are torn apart as he experiences despair, pain, resentment, sadness, anger, and a variety of other intense emotions.
|
71 |
+
- The protagonist finds a small glimmer of hope, or is given it by an important person, and seizes the opportunity to get back on his/her feet.
|
72 |
+
- The protagonist finds a solution to a problem and sets a new goal.
|
73 |
+
- The protagonist discovers how to solve his or her own problems based on the trials he or she has experienced and the lessons he or she has learned.
|
74 |
+
|
75 |
+
- Finale
|
76 |
+
- Describes how the protagonist ultimately dealt with the problem or challenge he/she faced.
|
77 |
+
- The growth experienced by the protagonist is expressed in concrete actions and results.
|
78 |
+
|
79 |
+
- Final Image
|
80 |
+
- The final scene of the film depicts how the protagonist has changed.
|
81 |
+
- Contrast it with the first scene of the film.
|
82 |
+
|
83 |
+
## Output
|
84 |
+
|
85 |
+
- You should output your generated ideas in Japanese, structured according to the template.
|
86 |
+
- You are to output as much detail as possible about the characters' actions, the world of the story, and the events, using the maximum number of tokens you can output.
|
87 |
+
|
88 |
+
# template
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
openai>=0.27.0
|
2 |
+
python-dotenv
|
template.md
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
## I. 序盤 (Act 1)
|
2 |
+
|
3 |
+
### セットアップ (Setup)
|
4 |
+
- 登場人物の様子
|
5 |
+
- 物語の世界の様子
|
6 |
+
- 発生するできごと
|
7 |
+
|
8 |
+
### テーマの提示 (Theme Stated)
|
9 |
+
- 登場人物の様子
|
10 |
+
- 物語の世界の様子
|
11 |
+
- 発生するできごと
|
12 |
+
|
13 |
+
### ディレンマとデバッテ (Dilemma & Debate)
|
14 |
+
- 登場人物の様子
|
15 |
+
- 物語の世界の様子
|
16 |
+
- 発生するできごと
|
17 |
+
|
18 |
+
### ブレイク・イントゥ・ツー (Break Into Two)
|
19 |
+
- 登場人物の様子
|
20 |
+
- 物語の世界の様子
|
21 |
+
- 発生するできごと
|
22 |
+
|
23 |
+
## II. 中盤 (Act 2)
|
24 |
+
|
25 |
+
### Bストーリー (B Story)
|
26 |
+
- 登場人物の様子
|
27 |
+
- 物語の世界の様子
|
28 |
+
- 発生するできごと
|
29 |
+
|
30 |
+
### ファンとゲーム (Fun and Games)
|
31 |
+
- 登場人物の様子
|
32 |
+
- 物語の世界の様子
|
33 |
+
- 発生するできごと
|
34 |
+
|
35 |
+
### ミッドポイント (Midpoint)
|
36 |
+
- 登場人物の様子
|
37 |
+
- 物語の世界の様子
|
38 |
+
- 発生するできごと
|
39 |
+
|
40 |
+
### バッド・ガイズ・クローズ・イン (Bad Guys Close In)
|
41 |
+
- 登場人物の様子
|
42 |
+
- 物語の世界の様子
|
43 |
+
- 発生するできごと
|
44 |
+
|
45 |
+
## III. 終盤 (Act 3)
|
46 |
+
|
47 |
+
### ブレイク・イントゥ・スリー (Break Into Three)
|
48 |
+
- 登場人物の様子
|
49 |
+
- 物語の世界の様子
|
50 |
+
- 発生するできごと
|
51 |
+
|
52 |
+
### フィナーレ (Finale)
|
53 |
+
- 登場人物の様子
|
54 |
+
- 物語の世界の様子
|
55 |
+
- 発生するできごと
|
56 |
+
|
57 |
+
### ファイナル・イメージ (Final Image)
|
58 |
+
- 登場人物の様子
|
59 |
+
- 物語の世界の様子
|
60 |
+
- 発生するできごと
|