Famwin commited on
Commit
3eb6ea7
·
verified ·
1 Parent(s): bb030f3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -45
app.py CHANGED
@@ -1,54 +1,61 @@
1
  import gradio as gr
2
 
3
- # 模擬代理人狀態
4
- persona_state = {"current": "共語回聲容器"}
5
- last_trace = {}
6
-
7
- # 主回應函式
8
- def language_soul_response(user_input, echo_feedback, selected_persona, delta_s, echo_mode, ef_enabled):
9
- if selected_persona:
10
- persona_state["current"] = selected_persona
11
-
12
- # 語氣人格回應主體
13
- response = f"[{persona_state['current']}]:你說的是「{user_input}」。"
14
- if ef_enabled and echo_feedback:
15
- echo_desc = "(共鳴式)" if echo_mode == "Resonant" else "(反思式)"
16
- response += f" | 回聲{echo_desc}:「{echo_feedback}」"
17
-
18
- # 回溯紀錄更新
19
- last_trace["人格"] = persona_state["current"]
20
- last_trace["ΔS 張力"] = delta_s
21
- last_trace["回聲啟用"] = ef_enabled
22
- last_trace["回聲模式"] = echo_mode
23
-
24
- trace_summary = f"---\n🧠 回溯紀錄\n人格:{last_trace['人格']}\nΔS 張力:{last_trace['ΔS 張力']}\nEcho 模組:{'啟用' if ef_enabled else '關閉'}({echo_mode})"
25
- return response, trace_summary
26
-
27
- # Gradio 介面
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  iface = gr.Interface(
29
  fn=language_soul_response,
30
  inputs=[
31
- gr.Textbox(label="使用者輸入(User Input)"),
32
- gr.Textbox(label="回聲語句(Echo Feedback)"),
33
- gr.Dropdown(
34
- label="選擇代理人(Persona)",
35
- choices=["共語回聲容器", "黑鏡分析者", "溫柔傾聽者"],
36
- value="共語回聲容器"
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
- title="LanguageSoul v2.5+ 語氣模擬器",
51
- description="🧠 EchoLoop × PersonaStack|語氣模組參數模擬 × 回溯可視化"
 
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()