Spaces:
Runtime error
Runtime error
aa
Browse files
app.py
CHANGED
@@ -11,6 +11,9 @@ def init_state(state):
|
|
11 |
|
12 |
if (len(state["summarize_history"]) == 0):
|
13 |
state["summarize_history"] = []
|
|
|
|
|
|
|
14 |
|
15 |
def make_return_message(state):
|
16 |
init_state(state)
|
@@ -18,11 +21,14 @@ def make_return_message(state):
|
|
18 |
if len(state["summarize_history"]) > 0:
|
19 |
message_string = '\n'.join(state["message_history"])
|
20 |
summarize_string = '\n'.join(state["summarize_history"])
|
|
|
21 |
return f"""
|
22 |
-
#
|
|
|
|
|
23 |
{summarize_string}
|
24 |
|
25 |
-
|
26 |
{message_string}
|
27 |
"""
|
28 |
else:
|
@@ -32,12 +38,13 @@ def make_return_message(state):
|
|
32 |
"""
|
33 |
|
34 |
def summarize_text(state):
|
35 |
-
|
|
|
36 |
message_string = '\n'.join(state["message_history"])
|
37 |
|
38 |
prompt = f"""
|
39 |
# 命令
|
40 |
-
|
41 |
出力は修正後の文章だけにしてください。
|
42 |
|
43 |
# 修正対象の文章
|
@@ -48,7 +55,7 @@ def summarize_text(state):
|
|
48 |
response = openai.ChatCompletion.create(
|
49 |
# model="gpt-3.5-turbo-0613",
|
50 |
model="gpt-3.5-turbo-16k",
|
51 |
-
max_tokens=1000,
|
52 |
messages=[
|
53 |
{"role": "user", "content": prompt}
|
54 |
]
|
@@ -56,9 +63,37 @@ def summarize_text(state):
|
|
56 |
assistant_msg = response["choices"][0]["message"]["content"]
|
57 |
print(assistant_msg)
|
58 |
state["message_history"] = assistant_msg.split('\n')
|
59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
init_state(state)
|
61 |
-
modify_text()
|
|
|
62 |
|
63 |
message_string = '\n'.join(state["message_history"])
|
64 |
|
@@ -75,7 +110,7 @@ def summarize_text(state):
|
|
75 |
response = openai.ChatCompletion.create(
|
76 |
# model="gpt-3.5-turbo-0613",
|
77 |
model="gpt-3.5-turbo-16k",
|
78 |
-
max_tokens=1000,
|
79 |
messages=[
|
80 |
{"role": "user", "content": prompt}
|
81 |
]
|
@@ -116,6 +151,9 @@ def transcribe(audio,state):
|
|
116 |
|
117 |
return make_return_message(state)
|
118 |
|
|
|
|
|
|
|
119 |
user_db = {"a": "aa", "yourmystar": "amazing"}
|
120 |
def auth(user_name, password):
|
121 |
return user_db.get(user_name) == password
|
@@ -123,6 +161,7 @@ def auth(user_name, password):
|
|
123 |
with gr.Blocks() as app:
|
124 |
state = gr.State({
|
125 |
"message_history" : [],
|
|
|
126 |
"summarize_history" : []
|
127 |
})
|
128 |
with gr.Row():
|
@@ -141,7 +180,8 @@ with gr.Blocks() as app:
|
|
141 |
5. 「**要約をつける**」を押すと、ChatGPTが誤字脱字を修正し、要約をつけてくれます
|
142 |
|
143 |
※ブラウザ更新すると文章が消えるので、忘れずにコピペしてください<br>
|
144 |
-
|
|
|
145 |
""")
|
146 |
|
147 |
inputs = gr.Audio(source="microphone", type="filepath", show_label="true",label="話しかけてください")
|
|
|
11 |
|
12 |
if (len(state["summarize_history"]) == 0):
|
13 |
state["summarize_history"] = []
|
14 |
+
|
15 |
+
if (len(state["title_history"]) == 0):
|
16 |
+
state["title_history"] = ""
|
17 |
|
18 |
def make_return_message(state):
|
19 |
init_state(state)
|
|
|
21 |
if len(state["summarize_history"]) > 0:
|
22 |
message_string = '\n'.join(state["message_history"])
|
23 |
summarize_string = '\n'.join(state["summarize_history"])
|
24 |
+
title = state["title_history"]
|
25 |
return f"""
|
26 |
+
# {title}
|
27 |
+
|
28 |
+
## 要約
|
29 |
{summarize_string}
|
30 |
|
31 |
+
## 本文
|
32 |
{message_string}
|
33 |
"""
|
34 |
else:
|
|
|
38 |
"""
|
39 |
|
40 |
def summarize_text(state):
|
41 |
+
|
42 |
+
def modify_text(state):
|
43 |
message_string = '\n'.join(state["message_history"])
|
44 |
|
45 |
prompt = f"""
|
46 |
# 命令
|
47 |
+
以下の文章の誤字脱字を修正して、適切に段落をつけてください。
|
48 |
出力は修正後の文章だけにしてください。
|
49 |
|
50 |
# 修正対象の文章
|
|
|
55 |
response = openai.ChatCompletion.create(
|
56 |
# model="gpt-3.5-turbo-0613",
|
57 |
model="gpt-3.5-turbo-16k",
|
58 |
+
# max_tokens=1000,
|
59 |
messages=[
|
60 |
{"role": "user", "content": prompt}
|
61 |
]
|
|
|
63 |
assistant_msg = response["choices"][0]["message"]["content"]
|
64 |
print(assistant_msg)
|
65 |
state["message_history"] = assistant_msg.split('\n')
|
66 |
+
|
67 |
+
def make_title(state):
|
68 |
+
message_string = '\n'.join(state["message_history"])
|
69 |
+
|
70 |
+
prompt = f"""
|
71 |
+
# 命令
|
72 |
+
以下の文章に、全体の内容を分かりやすく表現する適切なタイトル文をつけてください。
|
73 |
+
タイトル文は20文字以内にしてください。
|
74 |
+
出力はタイトル文だけにしてください。
|
75 |
+
|
76 |
+
# 文章
|
77 |
+
{message_string}
|
78 |
+
|
79 |
+
# Output
|
80 |
+
"""
|
81 |
+
response = openai.ChatCompletion.create(
|
82 |
+
# model="gpt-3.5-turbo-0613",
|
83 |
+
model="gpt-3.5-turbo-16k",
|
84 |
+
# max_tokens=1000,
|
85 |
+
messages=[
|
86 |
+
{"role": "user", "content": prompt}
|
87 |
+
]
|
88 |
+
)
|
89 |
+
assistant_msg = response["choices"][0]["message"]["content"]
|
90 |
+
print(assistant_msg)
|
91 |
+
state["title_history"] = assistant_msg
|
92 |
+
print(state["title_history"])
|
93 |
+
|
94 |
init_state(state)
|
95 |
+
modify_text(state)
|
96 |
+
make_title(state)
|
97 |
|
98 |
message_string = '\n'.join(state["message_history"])
|
99 |
|
|
|
110 |
response = openai.ChatCompletion.create(
|
111 |
# model="gpt-3.5-turbo-0613",
|
112 |
model="gpt-3.5-turbo-16k",
|
113 |
+
# max_tokens=1000,
|
114 |
messages=[
|
115 |
{"role": "user", "content": prompt}
|
116 |
]
|
|
|
151 |
|
152 |
return make_return_message(state)
|
153 |
|
154 |
+
|
155 |
+
|
156 |
+
|
157 |
user_db = {"a": "aa", "yourmystar": "amazing"}
|
158 |
def auth(user_name, password):
|
159 |
return user_db.get(user_name) == password
|
|
|
161 |
with gr.Blocks() as app:
|
162 |
state = gr.State({
|
163 |
"message_history" : [],
|
164 |
+
"title_history" : [],
|
165 |
"summarize_history" : []
|
166 |
})
|
167 |
with gr.Row():
|
|
|
180 |
5. 「**要約をつける**」を押すと、ChatGPTが誤字脱字を修正し、要約をつけてくれます
|
181 |
|
182 |
※ブラウザ更新すると文章が消えるので、忘れずにコピペしてください<br>
|
183 |
+
※クリップボードがうまく動作していません<br>
|
184 |
+
※要約できるのは1万文字くらいまでです
|
185 |
""")
|
186 |
|
187 |
inputs = gr.Audio(source="microphone", type="filepath", show_label="true",label="話しかけてください")
|