Spaces:
Running
Running
Refactor chat message format for Gradio compatibility and update UI theme
Browse files
app.py
CHANGED
|
@@ -37,9 +37,7 @@ def start_new_game_ui(difficulty):
|
|
| 37 |
|
| 38 |
# Initial Chat
|
| 39 |
initial_chat = [
|
| 40 |
-
|
| 41 |
-
("System", f"Victim: {game.scenario['victim']['name']}"),
|
| 42 |
-
("System", f"Time of Death: {game.scenario['victim']['time_of_death']}")
|
| 43 |
]
|
| 44 |
|
| 45 |
return (
|
|
@@ -68,17 +66,10 @@ def submit_question(session_id, suspect_id, question, history):
|
|
| 68 |
response = game.question_suspect(suspect_id, question)
|
| 69 |
|
| 70 |
# Update chat
|
| 71 |
-
# Gradio
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
# The plan said "Color-coded by speaker", implies standard Chatbot might be limiting
|
| 76 |
-
# if we want "Detective: ...", "Suspect: ...".
|
| 77 |
-
# We'll use (Speaker, Message) format and let Gradio handle it,
|
| 78 |
-
# or format it as "Speaker: Message" in the bubble.
|
| 79 |
-
|
| 80 |
-
history.append(("Detective", f"To {suspect_id}: {question}"))
|
| 81 |
-
history.append((suspect_id, response))
|
| 82 |
|
| 83 |
return history, "" # Clear input
|
| 84 |
|
|
@@ -101,7 +92,7 @@ def use_tool_ui(session_id, tool_name, arg1, arg2, history):
|
|
| 101 |
result = game.use_tool(tool_name, **kwargs)
|
| 102 |
|
| 103 |
# Update History
|
| 104 |
-
history.append(
|
| 105 |
|
| 106 |
# Update Evidence Board
|
| 107 |
ev_html = f"<h3>Case: {game.scenario['title']}</h3><p>Victim: {game.scenario['victim']['name']}</p><hr><h4>Evidence Revealed:</h4><ul>"
|
|
@@ -151,7 +142,6 @@ with gr.Blocks(title="Murder.Ai") as demo:
|
|
| 151 |
chatbot = gr.Chatbot(
|
| 152 |
label="Investigation Log",
|
| 153 |
height=500,
|
| 154 |
-
type="messages" # Gradio 5/6 new format
|
| 155 |
)
|
| 156 |
|
| 157 |
with gr.Row():
|
|
@@ -222,7 +212,7 @@ with gr.Blocks(title="Murder.Ai") as demo:
|
|
| 222 |
)
|
| 223 |
|
| 224 |
demo.launch(
|
| 225 |
-
theme=gr.themes.
|
| 226 |
css=custom_css,
|
| 227 |
allowed_paths=["."]
|
| 228 |
)
|
|
|
|
| 37 |
|
| 38 |
# Initial Chat
|
| 39 |
initial_chat = [
|
| 40 |
+
{"role": "assistant", "content": f"CASE FILE LOADED: {game.scenario['title']}\nVictim: {game.scenario['victim']['name']}\nTime of Death: {game.scenario['victim']['time_of_death']}"}
|
|
|
|
|
|
|
| 41 |
]
|
| 42 |
|
| 43 |
return (
|
|
|
|
| 66 |
response = game.question_suspect(suspect_id, question)
|
| 67 |
|
| 68 |
# Update chat
|
| 69 |
+
# Gradio 6 requires [{"role": "user", "content": "..."}, ...] format
|
| 70 |
+
|
| 71 |
+
history.append({"role": "user", "content": f"**Detective to {suspect_id}:** {question}"})
|
| 72 |
+
history.append({"role": "assistant", "content": f"**{suspect_id}:** {response}"})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
return history, "" # Clear input
|
| 75 |
|
|
|
|
| 92 |
result = game.use_tool(tool_name, **kwargs)
|
| 93 |
|
| 94 |
# Update History
|
| 95 |
+
history.append({"role": "assistant", "content": f"π§ **System:** Used {tool_name}\nResult: {result}"})
|
| 96 |
|
| 97 |
# Update Evidence Board
|
| 98 |
ev_html = f"<h3>Case: {game.scenario['title']}</h3><p>Victim: {game.scenario['victim']['name']}</p><hr><h4>Evidence Revealed:</h4><ul>"
|
|
|
|
| 142 |
chatbot = gr.Chatbot(
|
| 143 |
label="Investigation Log",
|
| 144 |
height=500,
|
|
|
|
| 145 |
)
|
| 146 |
|
| 147 |
with gr.Row():
|
|
|
|
| 212 |
)
|
| 213 |
|
| 214 |
demo.launch(
|
| 215 |
+
theme=gr.themes.Monochrome(),
|
| 216 |
css=custom_css,
|
| 217 |
allowed_paths=["."]
|
| 218 |
)
|