Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -222,14 +222,75 @@ def reflect_and_save(user_text, assistant_text, blocks_editor_value):
|
|
| 222 |
data, msg = add_block(data, proposal, block_type="conversation", add_review=False)
|
| 223 |
pretty = json.dumps(data["language_blocks"], ensure_ascii=False, indent=2)
|
| 224 |
return pretty, msg
|
| 225 |
-
|
| 226 |
# ----------------------------
|
| 227 |
# Gradio UI
|
| 228 |
# ----------------------------
|
| 229 |
def launch():
|
| 230 |
data = load_blocks()
|
| 231 |
-
default_blocks_text = json.dumps(
|
|
|
|
|
|
|
| 232 |
|
| 233 |
with gr.Blocks(title="Conversation Learning Lab (CPU)") as demo:
|
| 234 |
gr.Markdown("# 🗣️ Conversation Learning Lab (CPU-friendly)")
|
| 235 |
-
gr.Markdown(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 222 |
data, msg = add_block(data, proposal, block_type="conversation", add_review=False)
|
| 223 |
pretty = json.dumps(data["language_blocks"], ensure_ascii=False, indent=2)
|
| 224 |
return pretty, msg
|
|
|
|
| 225 |
# ----------------------------
|
| 226 |
# Gradio UI
|
| 227 |
# ----------------------------
|
| 228 |
def launch():
|
| 229 |
data = load_blocks()
|
| 230 |
+
default_blocks_text = json.dumps(
|
| 231 |
+
data["language_blocks"], ensure_ascii=False, indent=2
|
| 232 |
+
)
|
| 233 |
|
| 234 |
with gr.Blocks(title="Conversation Learning Lab (CPU)") as demo:
|
| 235 |
gr.Markdown("# 🗣️ Conversation Learning Lab (CPU-friendly)")
|
| 236 |
+
gr.Markdown(
|
| 237 |
+
"Focus on daily dialogue. Reinforce validated language blocks. "
|
| 238 |
+
"Transparent tokens and latency."
|
| 239 |
+
)
|
| 240 |
+
|
| 241 |
+
with gr.Row():
|
| 242 |
+
model_dd = gr.Dropdown(
|
| 243 |
+
label="Choose a model",
|
| 244 |
+
choices=list(MODEL_OPTIONS.keys()),
|
| 245 |
+
value="Phi-3.5 Mini Instruct (4B)"
|
| 246 |
+
)
|
| 247 |
+
|
| 248 |
+
with gr.Row():
|
| 249 |
+
user_in = gr.Textbox(
|
| 250 |
+
label="Your message",
|
| 251 |
+
placeholder="Start a conversation or choose an example below...",
|
| 252 |
+
lines=3
|
| 253 |
+
)
|
| 254 |
+
|
| 255 |
+
with gr.Row():
|
| 256 |
+
blocks_editor = gr.Textbox(
|
| 257 |
+
label="Today's blocks (JSON array or 'type: rule' lines)",
|
| 258 |
+
value=default_blocks_text,
|
| 259 |
+
lines=10
|
| 260 |
+
)
|
| 261 |
+
|
| 262 |
+
with gr.Row():
|
| 263 |
+
generate_btn = gr.Button("Generate (CPU)")
|
| 264 |
+
reflect_btn = gr.Button("Reflect & Save Rule")
|
| 265 |
+
|
| 266 |
+
with gr.Row():
|
| 267 |
+
output = gr.Textbox(label="Assistant", lines=8)
|
| 268 |
+
|
| 269 |
+
with gr.Row():
|
| 270 |
+
metrics = gr.Markdown("")
|
| 271 |
+
|
| 272 |
+
# 🧪 Example prompts section
|
| 273 |
+
gr.Markdown("### 🧪 Try an example prompt:")
|
| 274 |
+
gr.Examples(
|
| 275 |
+
examples=EXAMPLES, # <-- your improved babyChatter examples
|
| 276 |
+
inputs=user_in
|
| 277 |
+
)
|
| 278 |
+
|
| 279 |
+
# Wire up events
|
| 280 |
+
generate_btn.click(
|
| 281 |
+
fn=chat,
|
| 282 |
+
inputs=[user_in, model_dd, blocks_editor],
|
| 283 |
+
outputs=[output, metrics]
|
| 284 |
+
)
|
| 285 |
+
|
| 286 |
+
reflect_btn.click(
|
| 287 |
+
fn=reflect_and_save,
|
| 288 |
+
inputs=[user_in, output, blocks_editor],
|
| 289 |
+
outputs=[blocks_editor, metrics]
|
| 290 |
+
)
|
| 291 |
+
|
| 292 |
+
demo.launch()
|
| 293 |
+
|
| 294 |
+
|
| 295 |
+
if __name__ == "__main__":
|
| 296 |
+
launch()
|