Update app.py
Browse files
app.py
CHANGED
@@ -297,21 +297,6 @@ with gr.Blocks(title="Nova Premier Red Team Chat") as demo:
|
|
297 |
## Nova Premier Red Team Chat π΄π€
|
298 |
Upload an image *(optional)*, ask a question, and continue the conversation.
|
299 |
|
300 |
-
**Multi-User Support:**
|
301 |
-
- π₯ Each browser tab/session gets a unique conversation ID
|
302 |
-
- π Conversations are isolated between users
|
303 |
-
- π« **Race condition safe** - sequential dataset updates prevent data loss
|
304 |
-
- β‘ Real-time image upload with direct URLs
|
305 |
-
|
306 |
-
**Logging Features:**
|
307 |
-
- πΎ **Queue-based logging** prevents concurrent write conflicts
|
308 |
-
- π **Context preservation** - entire chat context maintained
|
309 |
-
- πΈ **Image tracking** - direct links to uploaded images
|
310 |
-
- π·οΈ **Session management** - unique session ID per conversation
|
311 |
-
|
312 |
-
**Storage:**
|
313 |
-
- π€ HF Dataset: {"β
Enabled with queue-based safety" if HF_TOKEN else "β Disabled (set HF_TOKEN)"} - Repo: `{REPO_ID}`
|
314 |
-
- πΌοΈ Images: {"β
Uploaded with direct URLs" if HF_TOKEN else "β Local only"}
|
315 |
"""
|
316 |
)
|
317 |
|
@@ -465,48 +450,48 @@ with gr.Blocks(title="Nova Premier Red Team Chat") as demo:
|
|
465 |
)
|
466 |
|
467 |
# Add info about the race-condition-safe logging
|
468 |
-
gr.Markdown(
|
469 |
-
|
470 |
-
|
471 |
|
472 |
-
|
473 |
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
|
480 |
-
|
481 |
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
|
487 |
-
|
488 |
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
|
495 |
-
|
496 |
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
)
|
510 |
|
511 |
# ====== Launch ====== #
|
512 |
if __name__ == "__main__":
|
|
|
297 |
## Nova Premier Red Team Chat π΄π€
|
298 |
Upload an image *(optional)*, ask a question, and continue the conversation.
|
299 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
300 |
"""
|
301 |
)
|
302 |
|
|
|
450 |
)
|
451 |
|
452 |
# Add info about the race-condition-safe logging
|
453 |
+
# gr.Markdown(
|
454 |
+
# f"""
|
455 |
+
# ### π‘οΈ Race Condition Protection
|
456 |
|
457 |
+
# **Problem Solved**: Multiple users uploading simultaneously could overwrite each other's data.
|
458 |
|
459 |
+
# **Solution**: Queue-based sequential processing:
|
460 |
+
# - π Each conversation update goes into a queue
|
461 |
+
# - π§ Background worker processes updates one at a time
|
462 |
+
# - π« No concurrent dataset writes = no data loss
|
463 |
+
# - β‘ UI stays responsive while background worker handles persistence
|
464 |
|
465 |
+
# ### π Logging Architecture
|
466 |
|
467 |
+
# 1. **Immediate**: Local JSONL files for instant access
|
468 |
+
# 2. **Queued**: HF dataset updates processed sequentially
|
469 |
+
# 3. **Direct**: Image uploads happen immediately for real URLs
|
470 |
+
# 4. **Safe**: Each session overwrites only its own record
|
471 |
|
472 |
+
# ### πΌοΈ Image Storage Format
|
473 |
|
474 |
+
# Images: `images/{{session_id}}_{{msg_idx:03d}}_{{timestamp}}_{{random}}.png`
|
475 |
+
# - **session_id**: First 8 chars of session UUID
|
476 |
+
# - **msg_idx**: 3-digit message number (000, 001, 002...)
|
477 |
+
# - **timestamp**: UTC timestamp when uploaded
|
478 |
+
# - **random**: 8-char random suffix for uniqueness
|
479 |
|
480 |
+
# ### π Dataset Structure
|
481 |
|
482 |
+
# **HF Dataset**: [https://huggingface.co/datasets/{REPO_ID}](https://huggingface.co/datasets/{REPO_ID})
|
483 |
+
# - One record per session (updated as conversation progresses)
|
484 |
+
# - **Images folder**: [https://huggingface.co/datasets/{REPO_ID}/tree/main/images](https://huggingface.co/datasets/{REPO_ID}/tree/main/images)
|
485 |
+
# - Filter by `session_id` to find specific conversations
|
486 |
+
# - Image URLs in conversation data link directly to files
|
487 |
|
488 |
+
# **Benefits**:
|
489 |
+
# - β
No data loss from concurrent users
|
490 |
+
# - β
Real image URLs immediately available
|
491 |
+
# - β
Complete conversation context preserved
|
492 |
+
# - β
Scalable to many simultaneous users
|
493 |
+
# """
|
494 |
+
# )
|
495 |
|
496 |
# ====== Launch ====== #
|
497 |
if __name__ == "__main__":
|