Update App2.py
Browse files
App2.py
CHANGED
|
@@ -32,6 +32,7 @@ BASE_SYSTEM_PROMPT = (
|
|
| 32 |
"ユーザーの要求に応じてテキストと画像に対応し、メモリを適切に管理してください。"
|
| 33 |
)
|
| 34 |
|
|
|
|
| 35 |
def save_to_database(history, memory):
|
| 36 |
data = {
|
| 37 |
"timestamp": time.time(),
|
|
@@ -50,6 +51,7 @@ def save_to_database(history, memory):
|
|
| 50 |
)
|
| 51 |
os.remove(file_name)
|
| 52 |
|
|
|
|
| 53 |
def generate_response(message, history, temperature, top_p, top_k, max_output_tokens, image, lang, use_memories):
|
| 54 |
global memory_list
|
| 55 |
|
|
@@ -91,29 +93,31 @@ def generate_response(message, history, temperature, top_p, top_k, max_output_to
|
|
| 91 |
save_to_database(history, memory_list)
|
| 92 |
return "", history, history, memory_list, None # 画像欄を空に
|
| 93 |
|
|
|
|
| 94 |
def add_memory(new_mem):
|
| 95 |
if new_mem.strip():
|
| 96 |
memory_list.append(new_mem.strip())
|
| 97 |
-
return memory_list
|
| 98 |
|
| 99 |
def edit_memory(memories):
|
| 100 |
global memory_list
|
| 101 |
memory_list = [m.strip() for m in memories if m.strip()]
|
| 102 |
-
return memory_list
|
| 103 |
|
| 104 |
def delete_selected_memory(selected):
|
| 105 |
global memory_list
|
| 106 |
memory_list = [m for m in memory_list if m not in selected]
|
| 107 |
-
return memory_list
|
| 108 |
|
|
|
|
| 109 |
with gr.Blocks() as demo:
|
| 110 |
gr.Markdown("## Gemini Chatbot - Image + Memory UI + HF Save")
|
| 111 |
|
| 112 |
with gr.Tabs():
|
| 113 |
with gr.Tab("Chat"):
|
| 114 |
-
chatbot = gr.Chatbot(type="messages")
|
| 115 |
msg = gr.Textbox(placeholder="メッセージを入力...")
|
| 116 |
-
img_upload = gr.Image(type="filepath", label="画像アップロード (プレビュー可)")
|
| 117 |
state = gr.State([])
|
| 118 |
mem_state = gr.State([])
|
| 119 |
|
|
|
|
| 32 |
"ユーザーの要求に応じてテキストと画像に対応し、メモリを適切に管理してください。"
|
| 33 |
)
|
| 34 |
|
| 35 |
+
# ==== データ保存 ====
|
| 36 |
def save_to_database(history, memory):
|
| 37 |
data = {
|
| 38 |
"timestamp": time.time(),
|
|
|
|
| 51 |
)
|
| 52 |
os.remove(file_name)
|
| 53 |
|
| 54 |
+
# ==== 生成関数 ====
|
| 55 |
def generate_response(message, history, temperature, top_p, top_k, max_output_tokens, image, lang, use_memories):
|
| 56 |
global memory_list
|
| 57 |
|
|
|
|
| 93 |
save_to_database(history, memory_list)
|
| 94 |
return "", history, history, memory_list, None # 画像欄を空に
|
| 95 |
|
| 96 |
+
# ==== メモリ操作 ====
|
| 97 |
def add_memory(new_mem):
|
| 98 |
if new_mem.strip():
|
| 99 |
memory_list.append(new_mem.strip())
|
| 100 |
+
return "\n".join(memory_list)
|
| 101 |
|
| 102 |
def edit_memory(memories):
|
| 103 |
global memory_list
|
| 104 |
memory_list = [m.strip() for m in memories if m.strip()]
|
| 105 |
+
return "\n".join(memory_list)
|
| 106 |
|
| 107 |
def delete_selected_memory(selected):
|
| 108 |
global memory_list
|
| 109 |
memory_list = [m for m in memory_list if m not in selected]
|
| 110 |
+
return "\n".join(memory_list)
|
| 111 |
|
| 112 |
+
# ==== UI構築 ====
|
| 113 |
with gr.Blocks() as demo:
|
| 114 |
gr.Markdown("## Gemini Chatbot - Image + Memory UI + HF Save")
|
| 115 |
|
| 116 |
with gr.Tabs():
|
| 117 |
with gr.Tab("Chat"):
|
| 118 |
+
chatbot = gr.Chatbot(type="messages") # type指定で警告回避
|
| 119 |
msg = gr.Textbox(placeholder="メッセージを入力...")
|
| 120 |
+
img_upload = gr.Image(type="filepath", label="画像アップロード (プレビュー可)") # tool削除
|
| 121 |
state = gr.State([])
|
| 122 |
mem_state = gr.State([])
|
| 123 |
|