Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,48 +1,63 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
# ΔS
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
# 主回應函數
|
| 18 |
-
def language_soul_response(user_input, echo_feedback, switch_persona):
|
| 19 |
if switch_persona:
|
| 20 |
persona_state["current"] = switch_persona
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
#
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
|
| 30 |
-
generated_reply = "我了解你說的,但你可以更清楚表達你的情緒嗎?" if delta_s > 5 else "聽起來你還蠻冷靜的,我可以幫你釐清。"
|
| 31 |
|
| 32 |
-
|
| 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(
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
],
|
| 43 |
outputs="text",
|
| 44 |
title="LanguageSoul v2.5 Demo",
|
| 45 |
-
description="
|
| 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()
|