Spaces:
Sleeping
Sleeping
Fix turns: disable experimental SSR, surface errors + 'didn't catch that' in UI
Browse files
app.py
CHANGED
|
@@ -213,8 +213,14 @@ def on_ask(engine, mic, typed):
|
|
| 213 |
return (engine, gr.skip(), gr.skip(), gr.skip(), gr.skip(), gr.skip(),
|
| 214 |
_banner("info", "Press “Call the witness” to begin."), gr.skip())
|
| 215 |
|
| 216 |
-
|
| 217 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 218 |
|
| 219 |
# Rebuild the chat from the transcript (engine keeps it consistent with what
|
| 220 |
# is actually spoken, including the break line on the winning turn).
|
|
@@ -223,6 +229,13 @@ def on_ask(engine, mic, typed):
|
|
| 223 |
tag = f"_[{rec.stance_tier.lower()}]_ " if rec.stance_tier != "NEUTRAL" else ""
|
| 224 |
chat.append({"role": "user", "content": f"{tag}{rec.examiner_text}"})
|
| 225 |
chat.append({"role": "assistant", "content": f"**{WITNESS_NAME}:** {rec.witness_text}"})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 226 |
|
| 227 |
# witness audio (+ epilogue concatenated on win/lose for a single dramatic play)
|
| 228 |
audio_val = None
|
|
@@ -332,6 +345,11 @@ def build() -> gr.Blocks:
|
|
| 332 |
demo = build()
|
| 333 |
|
| 334 |
if __name__ == "__main__":
|
| 335 |
-
# server_name=0.0.0.0 so the HF Space's startup self-check can reach the app
|
| 336 |
-
#
|
| 337 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 213 |
return (engine, gr.skip(), gr.skip(), gr.skip(), gr.skip(), gr.skip(),
|
| 214 |
_banner("info", "Press “Call the witness” to begin."), gr.skip())
|
| 215 |
|
| 216 |
+
try:
|
| 217 |
+
y, sr = _parse_mic(mic)
|
| 218 |
+
result = engine.take_turn(audio=y, sr=sr, typed_text=typed)
|
| 219 |
+
except Exception as exc: # surface the real cause in the UI, don't silently toast
|
| 220 |
+
import traceback
|
| 221 |
+
traceback.print_exc()
|
| 222 |
+
return (engine, gr.skip(), gr.skip(), gr.skip(), gr.skip(), gr.skip(),
|
| 223 |
+
_banner("lose", f"Turn failed — {type(exc).__name__}: {exc}"), gr.skip())
|
| 224 |
|
| 225 |
# Rebuild the chat from the transcript (engine keeps it consistent with what
|
| 226 |
# is actually spoken, including the break line on the winning turn).
|
|
|
|
| 229 |
tag = f"_[{rec.stance_tier.lower()}]_ " if rec.stance_tier != "NEUTRAL" else ""
|
| 230 |
chat.append({"role": "user", "content": f"{tag}{rec.examiner_text}"})
|
| 231 |
chat.append({"role": "assistant", "content": f"**{WITNESS_NAME}:** {rec.witness_text}"})
|
| 232 |
+
# Terminal turns (e.g. no clear audio) don't enter the transcript — show them
|
| 233 |
+
# anyway so the player always gets visible feedback.
|
| 234 |
+
last_bot = chat[-1]["content"] if chat else ""
|
| 235 |
+
if result.witness_text and result.witness_text not in last_bot:
|
| 236 |
+
if result.examiner_text:
|
| 237 |
+
chat.append({"role": "user", "content": result.examiner_text})
|
| 238 |
+
chat.append({"role": "assistant", "content": f"**{WITNESS_NAME}:** {result.witness_text}"})
|
| 239 |
|
| 240 |
# witness audio (+ epilogue concatenated on win/lose for a single dramatic play)
|
| 241 |
audio_val = None
|
|
|
|
| 345 |
demo = build()
|
| 346 |
|
| 347 |
if __name__ == "__main__":
|
| 348 |
+
# server_name=0.0.0.0 so the HF Space's startup self-check can reach the app.
|
| 349 |
+
# ssr_mode=False: Gradio 5's experimental SSR layer caused flaky request errors
|
| 350 |
+
# on the Space; the classic client-rendered path is reliable for this app.
|
| 351 |
+
demo.launch(
|
| 352 |
+
server_name="0.0.0.0",
|
| 353 |
+
server_port=int(os.environ.get("GRADIO_SERVER_PORT", 7860)),
|
| 354 |
+
ssr_mode=False,
|
| 355 |
+
)
|