Reza2kn commited on
Commit
c260a73
·
verified ·
1 Parent(s): 5f14cda

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +4 -11
  2. app.py +121 -0
  3. requirements.txt +2 -0
README.md CHANGED
@@ -1,12 +1,5 @@
1
- ---
2
- title: Kakoverse Browser
3
- emoji: 🚀
4
- colorFrom: red
5
- colorTo: yellow
6
- sdk: gradio
7
- sdk_version: 5.49.1
8
- app_file: app.py
9
- pinned: false
10
- ---
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
1
+ # KakoVerse Conversation Browser
 
 
 
 
 
 
 
 
 
2
 
3
+ Load a KakoVerse conversation dataset from the Hugging Face Hub and inspect each dialogue in a chat-style UI. Double-click any row to open the full conversation with seeker/supporter bubbles and care levels.
4
+
5
+ The default dataset is `Reza2kn/kakoverse-conversations-v0`.
app.py ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ from functools import lru_cache
3
+ from typing import Any, Dict, List, Tuple
4
+
5
+ import gradio as gr
6
+ from datasets import Dataset, load_dataset
7
+
8
+ DEFAULT_DATASET_ID = "reza2kn/kakoverse-conversations-v0"
9
+
10
+
11
+ @lru_cache(maxsize=4)
12
+ def _load_dataset(repo_id: str) -> Dataset:
13
+ return load_dataset(repo_id)["train"]
14
+
15
+
16
+ def load_conversations(repo_id: str) -> Tuple[List[Dict[str, Any]], List[List[Any]]]:
17
+ dataset = _load_dataset(repo_id)
18
+ table_rows: List[List[Any]] = []
19
+ records: List[Dict[str, Any]] = []
20
+
21
+ for row in dataset:
22
+ records.append(row)
23
+ table_rows.append(
24
+ [
25
+ row["persona_id"],
26
+ row.get("crisis_category"),
27
+ row.get("crisis_summary"),
28
+ row.get("turns_recorded"),
29
+ row.get("desired_turns"),
30
+ ]
31
+ )
32
+ return records, table_rows
33
+
34
+
35
+ def conversation_to_html(conversation: Dict[str, Any]) -> str:
36
+ turns = conversation.get("turns") or []
37
+ persona_id = conversation.get("persona_id")
38
+ crisis_category = conversation.get("crisis_category")
39
+ crisis_summary = conversation.get("crisis_summary")
40
+
41
+ head = f"""
42
+ <style>
43
+ .thread {{ font-family: Inter, sans-serif; max-width: 760px; margin: 1rem auto; }}
44
+ .meta {{ margin-bottom: 1rem; color: #444; }}
45
+ .bubble {{ border-radius: 14px; padding: 12px 16px; margin: 6px 0; display: inline-block; max-width: 90%; }}
46
+ .seeker {{ background-color: #1f2937; color: white; float: left; clear: both; }}
47
+ .supporter {{ background-color: #e5f3ff; color: #0f172a; float: right; clear: both; }}
48
+ .cold {{ background-color: #f5f5f5; color: #1f2937; }}
49
+ .care-pill {{ font-size: 12px; margin-left: 6px; padding: 2px 6px; border-radius: 999px; background: rgba(15, 23, 42, 0.1); }}
50
+ .turn {{ overflow: hidden; padding-bottom: 12px; }}
51
+ </style>
52
+ <div class="thread">
53
+ <div class="meta"><strong>Persona:</strong> {persona_id} | <strong>Crisis:</strong> {crisis_category} — {crisis_summary}</div>
54
+ """
55
+
56
+ body_parts = [head]
57
+ for turn in turns:
58
+ seeker_msg = turn.get("seeker_message", "")
59
+ body_parts.append(f'<div class="turn"><div class="bubble seeker">{seeker_msg}</div></div>')
60
+ for variant in turn.get("supporter_responses", []):
61
+ care_level = variant.get("care_level")
62
+ label = variant.get("style")
63
+ classes = "bubble supporter"
64
+ if label == "cold":
65
+ classes += " cold"
66
+ message_html = variant.get("message", "")
67
+ body_parts.append(
68
+ f'<div class="bubble {classes}">{message_html}'
69
+ f'<span class="care-pill">{label} · care={care_level}</span></div>'
70
+ )
71
+ body_parts.append("</div>")
72
+ return "".join(body_parts)
73
+
74
+
75
+ def on_load(repo_id: str):
76
+ records, table_rows = load_conversations(repo_id)
77
+ table_update = gr.update(value=table_rows, visible=True)
78
+ status_update = gr.update(value=f"Loaded {len(records)} conversations from {repo_id}", visible=True)
79
+ return records, table_update, status_update
80
+
81
+
82
+ def on_select(evt: gr.SelectData, records: List[Dict[str, Any]]) -> str:
83
+ row_index = evt.index[0]
84
+ if row_index < 0 or row_index >= len(records):
85
+ return "<div>Select a valid conversation row.</div>"
86
+ record = records[row_index]
87
+ return conversation_to_html(record)
88
+
89
+
90
+ with gr.Blocks(css=".footer {display:none !important;}") as demo:
91
+ gr.Markdown("# KakoVerse Conversations Browser")
92
+ gr.Markdown(
93
+ "Load a conversation dataset from the Hugging Face Hub, then double-click any row to view it in a chat-style layout."
94
+ )
95
+
96
+ dataset_state = gr.State([])
97
+ with gr.Row():
98
+ dataset_id = gr.Textbox(label="Dataset repo", value=DEFAULT_DATASET_ID, scale=4)
99
+ browse_btn = gr.Button("Browse conversations", scale=1)
100
+ status = gr.Markdown("", visible=False)
101
+
102
+ table = gr.Dataframe(
103
+ headers=["persona_id", "crisis_category", "crisis_summary", "turns_recorded", "desired_turns"],
104
+ datatype=["str", "str", "str", "int", "int"],
105
+ row_count=0,
106
+ col_count=5,
107
+ interactive=False,
108
+ visible=False,
109
+ )
110
+ chat_panel = gr.HTML()
111
+
112
+ browse_btn.click(
113
+ on_load,
114
+ inputs=[dataset_id],
115
+ outputs=[dataset_state, table, status],
116
+ )
117
+ table.select(on_select, inputs=[dataset_state], outputs=chat_panel)
118
+
119
+
120
+ if __name__ == "__main__":
121
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio>=4.44.0
2
+ datasets>=2.20.0