Spaces:
Sleeping

Famwin commited on
Commit
17504ea
·
verified ·
1 Parent(s): 5cf611b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -31
app.py CHANGED
@@ -1,48 +1,63 @@
1
  import gradio as gr
2
- import random
3
-
4
- # 模擬內部狀態
5
- persona_state = {"current": "Calm Analyst"}
6
- echo_mode = {"current": "Echo-On"}
7
-
8
- # ΔS 模擬張力參數(範例:-10 到 +10)
9
- def simulate_delta_s(user_input):
10
- keywords = {
11
- "怒": 6, "痛": 5, "謝謝": -4, "爛": 8, "很好": -6, "為什麼": 3,
12
- "你不懂": 7, "幫我": 2, "我想": -2, "我怕": 4
13
- }
14
- score = sum(val for key, val in keywords.items() if key in user_input)
15
- return max(-10, min(10, score)) if score != 0 else random.randint(-2, 2)
16
-
17
- # 主回應函數
18
- def language_soul_response(user_input, echo_feedback, switch_persona):
19
  if switch_persona:
20
  persona_state["current"] = switch_persona
21
- delta_s = simulate_delta_s(user_input)
22
- trace = f"[Persona: {persona_state['current']}] [ΔS: {delta_s}] [EchoMode: {echo_mode['current']}]\n"
 
 
 
 
 
 
 
 
23
 
24
- # Echo Feedback 解構模擬
25
- echo_analysis = ""
26
- if echo_feedback:
27
- echo_analysis = f"Echo interpretation: 模擬回聲為「{echo_feedback}」" if len(echo_feedback) < 40 else "Echo 超過處理上限"
 
 
 
28
 
29
- # 輸出內容(假輸出模擬語氣回應)
30
- generated_reply = "我了解你說的,但你可以更清楚表達你的情緒嗎?" if delta_s > 5 else "聽起來你還蠻冷靜的,我可以幫你釐清。"
31
 
32
- return trace + echo_analysis + "\n\n→ 模擬輸出:「" + generated_reply + "」"
33
 
34
- # Gradio 介面
35
  iface = gr.Interface(
36
  fn=language_soul_response,
37
  inputs=[
38
  gr.Textbox(label="User Input"),
39
  gr.Textbox(label="Echo Feedback (Optional)"),
40
- gr.Dropdown(choices=["Calm Analyst", "Empathic Listener", "Critical Mirror", "Neutral Proxy"],
41
- label="Switch Persona (Optional)", value="Calm Analyst")
 
 
 
 
 
 
 
 
42
  ],
43
  outputs="text",
44
  title="LanguageSoul v2.5 Demo",
45
- description="支援 EchoLoop、PersonaStack 與 ΔS 語氣張力參數的模擬器"
46
  )
47
 
48
- iface.launch()
 
1
  import gradio as gr
2
+
3
+ # State for persona and echo feedback simulation
4
+ persona_state = {"current": "Empathic Listener"}
5
+ echo_mode = {"current": "Soft Mirror"}
6
+
7
+ def simulate_delta_s(user_input, echo_feedback):
8
+ # Simple heuristic to simulate ΔS (tone strength)
9
+ score = 0
10
+ if any(x in user_input.lower() for x in ["怒", "恨", "討厭", "崩潰", "氣死"]):
11
+ score += 5
12
+ if echo_feedback and "重複" in echo_feedback:
13
+ score += 2
14
+ return min(score, 10)
15
+
16
+ def language_soul_response(user_input, echo_feedback, switch_persona, switch_echo):
 
 
17
  if switch_persona:
18
  persona_state["current"] = switch_persona
19
+ if switch_echo:
20
+ echo_mode["current"] = switch_echo
21
+
22
+ delta_s = simulate_delta_s(user_input, echo_feedback)
23
+
24
+ trace = (
25
+ f"[Persona: {persona_state['current']}] "
26
+ f"[ΔS: {delta_s}] "
27
+ f"[EchoMode: {echo_mode['current']}]"
28
+ )
29
 
30
+ # Simulated output based on tone and state
31
+ if delta_s >= 7:
32
+ output = "你的語氣感受到強烈波動,我會更加溫和地回應你。"
33
+ elif delta_s >= 3:
34
+ output = "我感受到你有些情緒,我會注意語氣。"
35
+ else:
36
+ output = "我們可以平靜地繼續對話。"
37
 
38
+ return f"{output}
 
39
 
40
+ {trace}"
41
 
 
42
  iface = gr.Interface(
43
  fn=language_soul_response,
44
  inputs=[
45
  gr.Textbox(label="User Input"),
46
  gr.Textbox(label="Echo Feedback (Optional)"),
47
+ gr.Dropdown(
48
+ choices=["Empathic Listener", "Critical Mirror", "Calm Analyst"],
49
+ label="Switch Persona (代理人模式)",
50
+ value="Empathic Listener"
51
+ ),
52
+ gr.Dropdown(
53
+ choices=["Soft Mirror", "Sharp Reflector", "Silent Echo"],
54
+ label="Switch Echo Mode (語氣回聲)",
55
+ value="Soft Mirror"
56
+ ),
57
  ],
58
  outputs="text",
59
  title="LanguageSoul v2.5 Demo",
60
+ description="EchoLoop × PersonaStack × ΔS 模擬器"
61
  )
62
 
63
+ iface.launch()