Fix Gradio Space startup compatibility
Browse files
app.py
CHANGED
|
@@ -25,17 +25,24 @@ def _status() -> str:
|
|
| 25 |
return " | ".join(parts)
|
| 26 |
|
| 27 |
|
| 28 |
-
def _history_for_og(history: list
|
| 29 |
turns: list[dict[str, str]] = []
|
| 30 |
for item in history[-12:]:
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
return turns
|
| 36 |
|
| 37 |
|
| 38 |
-
def chat(message: str, history: list
|
| 39 |
client = _build_client()
|
| 40 |
if not client.chat_enabled:
|
| 41 |
return (
|
|
@@ -86,7 +93,6 @@ with gr.Blocks(title="Mr Reachy") as demo:
|
|
| 86 |
|
| 87 |
gr.ChatInterface(
|
| 88 |
fn=chat,
|
| 89 |
-
type="messages",
|
| 90 |
title="Talk to Mr Reachy",
|
| 91 |
description="Chat calls 0G from the Space backend, so API keys stay private.",
|
| 92 |
examples=[
|
|
|
|
| 25 |
return " | ".join(parts)
|
| 26 |
|
| 27 |
|
| 28 |
+
def _history_for_og(history: list) -> list[dict[str, str]]:
|
| 29 |
turns: list[dict[str, str]] = []
|
| 30 |
for item in history[-12:]:
|
| 31 |
+
if isinstance(item, dict):
|
| 32 |
+
role = item.get("role")
|
| 33 |
+
content = item.get("content", "")
|
| 34 |
+
if role in {"user", "assistant"} and content:
|
| 35 |
+
turns.append({"role": role, "content": content})
|
| 36 |
+
elif isinstance(item, (list, tuple)) and len(item) >= 2:
|
| 37 |
+
user_msg, assistant_msg = item[0], item[1]
|
| 38 |
+
if user_msg:
|
| 39 |
+
turns.append({"role": "user", "content": str(user_msg)})
|
| 40 |
+
if assistant_msg:
|
| 41 |
+
turns.append({"role": "assistant", "content": str(assistant_msg)})
|
| 42 |
return turns
|
| 43 |
|
| 44 |
|
| 45 |
+
def chat(message: str, history: list) -> str:
|
| 46 |
client = _build_client()
|
| 47 |
if not client.chat_enabled:
|
| 48 |
return (
|
|
|
|
| 93 |
|
| 94 |
gr.ChatInterface(
|
| 95 |
fn=chat,
|
|
|
|
| 96 |
title="Talk to Mr Reachy",
|
| 97 |
description="Chat calls 0G from the Space backend, so API keys stay private.",
|
| 98 |
examples=[
|