Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,59 +1,80 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
#
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 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}\n語氣生成:{tone}\n{echo_response}"
|
| 42 |
|
| 43 |
# 建立介面
|
| 44 |
iface = gr.Interface(
|
| 45 |
-
fn=
|
| 46 |
inputs=[
|
| 47 |
-
gr.Textbox(label="使用者輸入"),
|
| 48 |
-
gr.Textbox(label="Echo 回
|
| 49 |
-
gr.Dropdown(
|
| 50 |
-
gr.Slider(
|
| 51 |
-
gr.Radio(
|
| 52 |
gr.Checkbox(label="啟用 Echo 回聲模組", value=True)
|
| 53 |
],
|
| 54 |
-
outputs=
|
|
|
|
|
|
|
|
|
|
| 55 |
title="LanguageSoul v2.6 語氣模擬器",
|
| 56 |
-
description="模擬 Echo × Persona
|
| 57 |
)
|
| 58 |
|
| 59 |
-
iface.launch()
|
|
|
|
| 1 |
+
|
| 2 |
import gradio as gr
|
| 3 |
+
import random
|
| 4 |
+
|
| 5 |
+
# 模擬代理人列表與語氣風格映射
|
| 6 |
+
personas = {
|
| 7 |
+
"黑鏡分析者": {"style": "冷靜分析", "prefix": "[黑鏡分析者]"},
|
| 8 |
+
"熱切同理者": {"style": "共感回應", "prefix": "[熱切同理者]"},
|
| 9 |
+
"挑釁觀察者": {"style": "高張力反詰", "prefix": "[挑釁觀察者]"},
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
# Echo 模式語氣轉換映射
|
| 13 |
+
echo_modes = {
|
| 14 |
+
"Reflective": "反思性的鏡像語氣",
|
| 15 |
+
"Resonant": "共鳴式的語氣加強"
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
# 模擬回應生成邏輯
|
| 19 |
+
def generate_response(user_input, echo_input, persona_name, delta_s, echo_mode, echo_enabled):
|
| 20 |
+
trace_log = []
|
| 21 |
+
|
| 22 |
+
# 代理人設定
|
| 23 |
+
persona = personas.get(persona_name, personas["黑鏡分析者"])
|
| 24 |
+
trace_log.append(f"Persona: {persona_name} ({persona['style']})")
|
| 25 |
+
|
| 26 |
+
# 語氣強度分析
|
| 27 |
+
try:
|
| 28 |
+
delta_s = float(delta_s)
|
| 29 |
+
except:
|
| 30 |
+
delta_s = 0.5
|
| 31 |
+
trace_log.append(f"語氣強度 ΔS: {delta_s}")
|
| 32 |
|
| 33 |
+
# Echo 模式
|
| 34 |
+
echo_label = echo_modes.get(echo_mode, "反思性鏡像")
|
| 35 |
+
trace_log.append(f"Echo 模式: {echo_label}")
|
| 36 |
+
|
| 37 |
+
# 語句生成模擬
|
| 38 |
+
base_response = ""
|
| 39 |
+
if "你" in user_input and "在" in user_input:
|
| 40 |
+
base_response = "你需要釐清你要對誰說話。"
|
| 41 |
+
elif "想" in user_input:
|
| 42 |
+
base_response = "有些渴望是為了讓你認出自己。"
|
| 43 |
+
else:
|
| 44 |
+
base_response = random.choice([
|
| 45 |
+
"這句話反映了你潛意識的避讓。",
|
| 46 |
+
"我能理解你在語氣中藏的東西。",
|
| 47 |
+
"你正在測試語魂是否能讀懂你。"
|
| 48 |
+
])
|
| 49 |
+
|
| 50 |
+
# Echo 回饋處理
|
| 51 |
+
echo_part = ""
|
| 52 |
+
if echo_enabled and echo_input:
|
| 53 |
+
echo_part = f"|Echo 殘響:你提到「{echo_input}」,我感受到回聲中的情緒張力。"
|
| 54 |
+
|
| 55 |
+
final_response = f"{persona['prefix']} {base_response} {echo_part}"
|
| 56 |
+
|
| 57 |
+
# 顯示回饋區塊
|
| 58 |
+
feedback_block = "\n".join(trace_log)
|
| 59 |
+
return final_response.strip(), feedback_block
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
# 建立介面
|
| 62 |
iface = gr.Interface(
|
| 63 |
+
fn=generate_response,
|
| 64 |
inputs=[
|
| 65 |
+
gr.Textbox(label="使用者輸入內容"),
|
| 66 |
+
gr.Textbox(label="Echo 回饋語句(可留空)"),
|
| 67 |
+
gr.Dropdown(label="切換人格(代理人)", choices=list(personas.keys()), value="黑鏡分析者"),
|
| 68 |
+
gr.Slider(label="語氣張力 ΔS", minimum=0, maximum=1, step=0.1, value=0.5),
|
| 69 |
+
gr.Radio(label="Echo 模式", choices=list(echo_modes.keys()), value="Reflective"),
|
| 70 |
gr.Checkbox(label="啟用 Echo 回聲模組", value=True)
|
| 71 |
],
|
| 72 |
+
outputs=[
|
| 73 |
+
gr.Textbox(label="模擬語氣回應"),
|
| 74 |
+
gr.Textbox(label="參數與解構結果")
|
| 75 |
+
],
|
| 76 |
title="LanguageSoul v2.6 語氣模擬器",
|
| 77 |
+
description="模擬 Echo × Persona 系列語氣邏輯,以 ΔS 強度與回聲模式驅動語氣生成。"
|
| 78 |
)
|
| 79 |
|
| 80 |
+
iface.launch()
|