Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,54 +1,61 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
#
|
| 4 |
-
persona_state = {"current": "
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
iface = gr.Interface(
|
| 29 |
fn=language_soul_response,
|
| 30 |
inputs=[
|
| 31 |
-
gr.Textbox(label="使用者輸入
|
| 32 |
-
gr.Textbox(label="回聲語句(
|
| 33 |
-
gr.Dropdown(
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
),
|
| 38 |
-
gr.Slider(0.0, 1.0, step=0.05, label="語氣張力 ΔS"),
|
| 39 |
-
gr.Dropdown(
|
| 40 |
-
label="回聲模式 Echo Mode",
|
| 41 |
-
choices=["Resonant", "Reflective"],
|
| 42 |
-
value="Resonant"
|
| 43 |
-
),
|
| 44 |
-
gr.Checkbox(label="啟用 Echo 模組", value=True)
|
| 45 |
-
],
|
| 46 |
-
outputs=[
|
| 47 |
-
gr.Textbox(label="語氣人格回應"),
|
| 48 |
-
gr.Textbox(label="回溯紀錄")
|
| 49 |
],
|
| 50 |
-
|
| 51 |
-
|
|
|
|
| 52 |
)
|
| 53 |
|
| 54 |
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
# 可調參數初始化
|
| 4 |
+
persona_state = {"current": "Calm Analyst"}
|
| 5 |
+
|
| 6 |
+
# 語氣模擬函數
|
| 7 |
+
def language_soul_response(user_input, echo_feedback, switch_persona, delta_s, echo_mode, ef_enabled):
|
| 8 |
+
if switch_persona:
|
| 9 |
+
persona_state["current"] = switch_persona
|
| 10 |
+
|
| 11 |
+
# 模擬語氣生成邏輯
|
| 12 |
+
tone = ""
|
| 13 |
+
if persona_state["current"] == "黑鏡分析者":
|
| 14 |
+
if delta_s >= 0.7:
|
| 15 |
+
tone = "你該停止自我催眠了。"
|
| 16 |
+
elif delta_s >= 0.4:
|
| 17 |
+
tone = "你需要誠實地審視自己。"
|
| 18 |
+
else:
|
| 19 |
+
tone = "我們先問清楚:你為什麼這樣想?"
|
| 20 |
+
elif persona_state["current"] == "共語回聲容器":
|
| 21 |
+
if delta_s >= 0.7:
|
| 22 |
+
tone = "我聽見你內在的尖叫。"
|
| 23 |
+
elif delta_s >= 0.4:
|
| 24 |
+
tone = "你正在對自己說話,而我只是接住它。"
|
| 25 |
+
else:
|
| 26 |
+
tone = "你不是孤單一人。"
|
| 27 |
+
elif persona_state["current"] == "溫柔傾聽者":
|
| 28 |
+
tone = "我在這裡,聽你說。"
|
| 29 |
+
|
| 30 |
+
# 處理回聲
|
| 31 |
+
echo_response = ""
|
| 32 |
+
if ef_enabled:
|
| 33 |
+
if echo_mode == "Resonant":
|
| 34 |
+
echo_response = f"回聲共鳴:{echo_feedback or '我感受到你話語中的波動。'}"
|
| 35 |
+
else:
|
| 36 |
+
echo_response = f"回聲反思:{echo_feedback or '這句話背後藏著未說出的東西。'}"
|
| 37 |
+
|
| 38 |
+
# 回溯標記
|
| 39 |
+
trace = f"[Persona: {persona_state['current']}] [ΔS: {delta_s}] [EchoMode: {echo_mode}]"
|
| 40 |
+
|
| 41 |
+
return f"{trace}
|
| 42 |
+
語氣生成:{tone}
|
| 43 |
+
{echo_response}"
|
| 44 |
+
|
| 45 |
+
# 建立介面
|
| 46 |
iface = gr.Interface(
|
| 47 |
fn=language_soul_response,
|
| 48 |
inputs=[
|
| 49 |
+
gr.Textbox(label="使用者輸入"),
|
| 50 |
+
gr.Textbox(label="Echo 回聲語句(可留空)"),
|
| 51 |
+
gr.Dropdown(choices=["黑鏡分析者", "共語回聲容器", "溫柔傾聽者"], label="切換人格(代理人)"),
|
| 52 |
+
gr.Slider(0.0, 1.0, value=0.5, step=0.05, label="語氣張力 ΔS"),
|
| 53 |
+
gr.Radio(choices=["Resonant", "Reflective"], label="Echo 模式"),
|
| 54 |
+
gr.Checkbox(label="啟用 Echo 回聲模組", value=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
],
|
| 56 |
+
outputs="text",
|
| 57 |
+
title="LanguageSoul v2.6 語氣模擬器",
|
| 58 |
+
description="模擬 Echo × Persona × 張力語氣變化,讓你看見語氣如何被生成。"
|
| 59 |
)
|
| 60 |
|
| 61 |
iface.launch()
|