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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
demo_markdown = """要約の出力イメージ
|
| 2 |
+
## 会議要約
|
| 3 |
+
|
| 4 |
+
**会議の概要**
|
| 5 |
+
|
| 6 |
+
- 会議名: test
|
| 7 |
+
- 日時: 2xxx年x月x日
|
| 8 |
+
- 参加者: Aさん、Bさん、Cさん
|
| 9 |
+
- 議題: 要約の精度確認、今後の開発
|
| 10 |
+
|
| 11 |
+
**議論された内容**
|
| 12 |
+
|
| 13 |
+
1. 要約に用いる技術
|
| 14 |
+
- AIモデルの一覧
|
| 15 |
+
- xxx
|
| 16 |
+
- xxx
|
| 17 |
+
2. ツールとして必要な機能
|
| 18 |
+
- すでに実装されている機能
|
| 19 |
+
- xxx
|
| 20 |
+
- xxx
|
| 21 |
+
- 開発が望まれる機能
|
| 22 |
+
- xxx
|
| 23 |
+
3. 今後の開発プラン
|
| 24 |
+
- 短期計画: xxx
|
| 25 |
+
- 長期計画: xxx
|
| 26 |
+
|
| 27 |
+
**結論**
|
| 28 |
+
|
| 29 |
+
- xxx
|
| 30 |
+
|
| 31 |
+
**懸念点**
|
| 32 |
+
|
| 33 |
+
- xxx
|
| 34 |
+
|
| 35 |
+
**今後のアクションアイテム**
|
| 36 |
+
|
| 37 |
+
- xxx
|
| 38 |
+
|
| 39 |
+
## 会議の流れ
|
| 40 |
+
| タイムスタンプ | 話題 | 備考 |
|
| 41 |
+
| --- | --- | --- |
|
| 42 |
+
| 0:00 | 要約に用いる技術 | xxx |
|
| 43 |
+
| 0:58 | xxx | xxx |
|
| 44 |
+
| 2:30 | xxx | xxx |
|
| 45 |
+
"""
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
import os
|
| 49 |
+
import time
|
| 50 |
+
|
| 51 |
+
import gradio as gr
|
| 52 |
+
import google.generativeai as genai
|
| 53 |
+
import logging
|
| 54 |
+
logging.basicConfig(level=logging.DEBUG)
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
generation_config = {
|
| 58 |
+
"temperature": 0,
|
| 59 |
+
"top_p": 0.95,
|
| 60 |
+
"top_k": 64,
|
| 61 |
+
"max_output_tokens": 8192,
|
| 62 |
+
"response_mime_type": "text/plain",
|
| 63 |
+
}
|
| 64 |
+
safety_settings = [
|
| 65 |
+
{
|
| 66 |
+
"category": "HARM_CATEGORY_HARASSMENT",
|
| 67 |
+
"threshold": "BLOCK_MEDIUM_AND_ABOVE",
|
| 68 |
+
},
|
| 69 |
+
{
|
| 70 |
+
"category": "HARM_CATEGORY_HATE_SPEECH",
|
| 71 |
+
"threshold": "BLOCK_MEDIUM_AND_ABOVE",
|
| 72 |
+
},
|
| 73 |
+
{
|
| 74 |
+
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
|
| 75 |
+
"threshold": "BLOCK_MEDIUM_AND_ABOVE",
|
| 76 |
+
},
|
| 77 |
+
{
|
| 78 |
+
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
|
| 79 |
+
"threshold": "BLOCK_MEDIUM_AND_ABOVE",
|
| 80 |
+
},
|
| 81 |
+
]
|
| 82 |
+
|
| 83 |
+
def model_settings(api_key, system_prompt, model):
|
| 84 |
+
genai.configure(api_key=api_key)
|
| 85 |
+
model = genai.GenerativeModel(
|
| 86 |
+
model_name="models/" + model,
|
| 87 |
+
safety_settings=safety_settings,
|
| 88 |
+
generation_config=generation_config,
|
| 89 |
+
system_instruction=system_prompt,
|
| 90 |
+
)
|
| 91 |
+
chat_session = model.start_chat(
|
| 92 |
+
history=[
|
| 93 |
+
]
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
return chat_session
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
def audio_system_prompt(meeting_name, members, point, keyword):
|
| 100 |
+
system_prompt = f"""
|
| 101 |
+
この音声は、{meeting_name}という会議の録音です。
|
| 102 |
+
会議の参加者は、
|
| 103 |
+
{members}
|
| 104 |
+
です。
|
| 105 |
+
この音声をもとに会議の要約を作成してください。
|
| 106 |
+
音声に含まれていない情報を記載したり、冗長になったりしてはいけません。
|
| 107 |
+
この会議固有の言葉は、{keyword}です。
|
| 108 |
+
|
| 109 |
+
まず、会議の概要、何が議論されたのか、会議の結論、アクションアイテム、{point}を冒頭にまとめて記載してください。
|
| 110 |
+
会議の概要には、会議名、日時、参加者を記載してください。開催日時などが不明の場合は「不明」と記載してください。
|
| 111 |
+
また内容はMECEである必要があります。
|
| 112 |
+
|
| 113 |
+
その後、会議の流れを記載します。
|
| 114 |
+
会議の流れは下記の形式で、それぞれのタイムスタンプごとの話題を記載します。
|
| 115 |
+
具体的な内容は整理して、概要に記載してください。表の中はすべて左詰となるようにします。
|
| 116 |
+
| タイムスタンプ | 話題 | 概要 |
|
| 117 |
+
"""
|
| 118 |
+
return system_prompt
|
| 119 |
+
|
| 120 |
+
def video_system_prompt(meeting_name, members, point, keyword):
|
| 121 |
+
system_prompt = f"""
|
| 122 |
+
この動画は、{meeting_name}という会議の録画です。
|
| 123 |
+
会議の参加者は、
|
| 124 |
+
{members}
|
| 125 |
+
です。
|
| 126 |
+
この動画をもとに会議の要約を作成してください。
|
| 127 |
+
動画に含まれていない情報を記載したり、冗長になったりしてはいけません。
|
| 128 |
+
この会議固有の言葉は、{keyword}です。
|
| 129 |
+
|
| 130 |
+
まず、会議の概要、何が議論されたのか、会議の結論、アクションアイテム、{point}を冒頭にまとめて記載してください。
|
| 131 |
+
会議の概要には、会議名、日時、参加者を記載してください。開催日時などが不明の場合は「不明」と記載してください。
|
| 132 |
+
また内容はMECEである必要があります。
|
| 133 |
+
|
| 134 |
+
その後、会議の流れを記載します。
|
| 135 |
+
会議の流れは下記の形式で、それぞれのタイムスタンプごとの話題を記載します。
|
| 136 |
+
具体的な内容は整理して、概要に記載してください。表の中はすべて左詰となるようにします。
|
| 137 |
+
| タイムスタンプ | 話題 | 概要 |
|
| 138 |
+
"""
|
| 139 |
+
return system_prompt
|
| 140 |
+
|
| 141 |
+
def gemini(api_key, input_file, meeting_name, members, point, keyword, model, task):
|
| 142 |
+
if api_key is None:
|
| 143 |
+
raise gr.Error("No api_key submitted!")
|
| 144 |
+
if input_file is None:
|
| 145 |
+
raise gr.Error("No input_file submitted! Please upload or record an file before submitting your request.")
|
| 146 |
+
# 音声 or 動画
|
| 147 |
+
if task == "audio":
|
| 148 |
+
system_prompt = audio_system_prompt(meeting_name, members, point, keyword)
|
| 149 |
+
else:
|
| 150 |
+
system_prompt = video_system_prompt(meeting_name, members, point, keyword)
|
| 151 |
+
|
| 152 |
+
# 処理の実行
|
| 153 |
+
chat_session = model_settings(api_key, system_prompt, model)
|
| 154 |
+
logging.warning(f"input file: {input_file}")
|
| 155 |
+
upload_file = genai.upload_file(input_file)
|
| 156 |
+
logging.warning(f"upload file: {upload_file}")
|
| 157 |
+
|
| 158 |
+
response = chat_session.send_message([upload_file])
|
| 159 |
+
|
| 160 |
+
upload_file.delete()
|
| 161 |
+
|
| 162 |
+
return [[None, response.text]]
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
audio = gr.Interface(
|
| 166 |
+
fn=gemini,
|
| 167 |
+
inputs=[
|
| 168 |
+
gr.Textbox(label="google ai studioのAPI key", show_label=True, placeholder="不明"),
|
| 169 |
+
gr.Audio(type="filepath",label="Audio file"),
|
| 170 |
+
gr.Textbox(label="会議名", show_label=True, placeholder="不明"),
|
| 171 |
+
gr.TextArea(label="参加者: 1名ずつ改行して入力", show_label=True, placeholder="不明"),
|
| 172 |
+
gr.Textbox(label="抽出事項: 概要、何が議論されたのか、会議の結論、アクションアイテム以外に抽出したいこと", show_label=True),
|
| 173 |
+
gr.Textbox(label="固有名詞: 企業名など", show_label=True),
|
| 174 |
+
gr.Radio(["gemini-1.5-flash-latest", "gemini-1.5-pro-latest"], label="使用モデル", show_label=True, value="gemini-1.5-flash-latest"),
|
| 175 |
+
gr.Textbox(value="audio", visible=False),
|
| 176 |
+
],
|
| 177 |
+
outputs=[gr.Chatbot(show_copy_button=True, render_markdown=True, height=1000, value=[[None, demo_markdown]])],
|
| 178 |
+
title="QuickRecap v1",
|
| 179 |
+
description ="↑select souce. It automatically summarizes meeting audio and video.",
|
| 180 |
+
allow_flagging="never",
|
| 181 |
+
)
|
| 182 |
+
|
| 183 |
+
video = gr.Interface(
|
| 184 |
+
fn=gemini,
|
| 185 |
+
inputs=[
|
| 186 |
+
gr.Textbox(label="google ai studioのAPI key", show_label=True, placeholder="不明"),
|
| 187 |
+
gr.Video(label="Video file", show_download_button=True),
|
| 188 |
+
gr.Textbox(label="会議名", show_label=True, placeholder="不明"),
|
| 189 |
+
gr.TextArea(label="参加者: 1名ずつ改行して入力", show_label=True, placeholder="不明"),
|
| 190 |
+
gr.Textbox(label="抽出事項: 概要、何が議論されたのか、会議の結論、アクションアイテム以外に抽出したいこと", show_label=True),
|
| 191 |
+
gr.Textbox(label="固有名詞: 企業名など", show_label=True),
|
| 192 |
+
gr.Radio(["gemini-1.5-flash-latest", "gemini-1.5-pro-latest"], label="使用モデル", show_label=True, value="gemini-1.5-pro-latest"),
|
| 193 |
+
gr.Textbox(value="video", visible=False),
|
| 194 |
+
],
|
| 195 |
+
outputs=[gr.Chatbot(show_copy_button=True, render_markdown=True, height=1000, value=[[None, demo_markdown]])],
|
| 196 |
+
title="QuickRecap v1",
|
| 197 |
+
description ="↑select souce. It automatically summarizes meeting audio and video.",
|
| 198 |
+
allow_flagging="never",
|
| 199 |
+
)
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
demo = gr.Blocks()
|
| 203 |
+
with demo:
|
| 204 |
+
gr.TabbedInterface([audio, video], ["Audio", "Video"])
|
| 205 |
+
|
| 206 |
+
demo.launch()
|