masterjedi commited on
Commit
3664018
·
1 Parent(s): be4c8b2

Convert distillation studio to static Space

Browse files
Files changed (4) hide show
  1. README.md +2 -4
  2. app.py +0 -153
  3. index.html +124 -0
  4. requirements.txt +0 -1
README.md CHANGED
@@ -3,9 +3,7 @@ title: ADI Distillation Studio
3
  emoji: 🧪
4
  colorFrom: gray
5
  colorTo: green
6
- sdk: gradio
7
- sdk_version: 6.19.0
8
- python_version: '3.12'
9
- app_file: app.py
10
  pinned: false
11
  ---
 
3
  emoji: 🧪
4
  colorFrom: gray
5
  colorTo: green
6
+ sdk: static
7
+ app_file: index.html
 
 
8
  pinned: false
9
  ---
app.py DELETED
@@ -1,153 +0,0 @@
1
- import json
2
- import re
3
- import tempfile
4
- from pathlib import Path
5
-
6
- import gradio as gr
7
-
8
-
9
- STYLE_PRESETS = {
10
- "ADI concise": "Answer clearly, directly, and with practical next steps. Keep the tone calm and capable.",
11
- "Technical mentor": "Explain the reasoning briefly, use precise terms, and make the user feel more capable.",
12
- "Support agent": "Be reassuring, diagnose the issue, and give a short ordered fix path.",
13
- "Creative partner": "Offer useful ideas with a little warmth and imagination while staying grounded.",
14
- "Safety reviewer": "Identify risks, state assumptions, and recommend the safest useful action.",
15
- }
16
-
17
- VARIATION_TEMPLATES = [
18
- "Direct task",
19
- "Beginner phrasing",
20
- "Production constraint",
21
- "Edge case",
22
- "Follow-up turn",
23
- ]
24
-
25
-
26
- def clean_text(value):
27
- return re.sub(r"\s+", " ", (value or "").strip())
28
-
29
-
30
- def split_steps(text):
31
- lines = [line.strip(" -\t") for line in (text or "").splitlines()]
32
- lines = [line for line in lines if line]
33
- if len(lines) >= 2:
34
- return lines[:6]
35
- sentences = re.split(r"(?<=[.!?])\s+", clean_text(text))
36
- return [sentence for sentence in sentences if sentence][:6]
37
-
38
-
39
- def user_variant(instruction, idx):
40
- instruction = clean_text(instruction)
41
- if idx == 0:
42
- return instruction
43
- if idx == 1:
44
- return f"I'm new to this. {instruction}"
45
- if idx == 2:
46
- return f"{instruction} Keep the answer production-ready and avoid unnecessary detail."
47
- if idx == 3:
48
- return f"{instruction} Also mention one common edge case or failure mode."
49
- return f"Follow up on this request and make the answer easier to act on: {instruction}"
50
-
51
-
52
- def assistant_variant(teacher_answer, style_text, idx):
53
- answer = clean_text(teacher_answer)
54
- steps = split_steps(teacher_answer)
55
- if idx == 0:
56
- return answer
57
- if idx == 1:
58
- return f"Here is the short version: {answer}"
59
- if idx == 2:
60
- return "\n".join(f"{i + 1}. {step}" for i, step in enumerate(steps)) or answer
61
- if idx == 3:
62
- return f"{answer}\n\nWatch for: missing context, stale assumptions, or inputs that do not match the expected format."
63
- return f"{answer}\n\nStyle target: {style_text}"
64
-
65
-
66
- def make_record(system_prompt, user, assistant, source, tags):
67
- return {
68
- "messages": [
69
- {"role": "system", "content": system_prompt},
70
- {"role": "user", "content": user},
71
- {"role": "assistant", "content": assistant},
72
- ],
73
- "metadata": {
74
- "source": source,
75
- "tags": [tag.strip() for tag in tags.split(",") if tag.strip()],
76
- },
77
- }
78
-
79
-
80
- def build_dataset(instruction, teacher_answer, style_preset, custom_style, tags, include_variants):
81
- instruction = clean_text(instruction)
82
- teacher_answer = (teacher_answer or "").strip()
83
- if not instruction:
84
- raise gr.Error("Add an instruction or user request first.")
85
- if not teacher_answer:
86
- raise gr.Error("Add a teacher answer first.")
87
-
88
- style_text = clean_text(custom_style) or STYLE_PRESETS[style_preset]
89
- system_prompt = f"You are ADI. {style_text}"
90
- count = 5 if include_variants else 1
91
-
92
- records = []
93
- for idx in range(count):
94
- records.append(
95
- make_record(
96
- system_prompt=system_prompt,
97
- user=user_variant(instruction, idx),
98
- assistant=assistant_variant(teacher_answer, style_text, idx),
99
- source=VARIATION_TEMPLATES[idx],
100
- tags=tags,
101
- )
102
- )
103
-
104
- jsonl = "\n".join(json.dumps(record, ensure_ascii=False) for record in records)
105
- preview = json.dumps(records[0], ensure_ascii=False, indent=2)
106
- out_path = Path(tempfile.NamedTemporaryFile(suffix=".jsonl", delete=False).name)
107
- out_path.write_text(jsonl + "\n", encoding="utf-8")
108
- summary = f"Generated {len(records)} JSONL record(s). First record has {len(records[0]['messages'])} messages."
109
- return summary, preview, jsonl, str(out_path)
110
-
111
-
112
- with gr.Blocks(title="ADI Distillation Studio", fill_width=True) as demo:
113
- gr.Markdown("# ADI Distillation Studio")
114
- with gr.Row():
115
- with gr.Column(scale=1):
116
- instruction = gr.Textbox(
117
- label="Instruction / user request",
118
- lines=5,
119
- value="Explain why a recent llama.cpp build is needed for Qwen3.5 GGUF models.",
120
- )
121
- teacher = gr.Textbox(
122
- label="Teacher answer",
123
- lines=10,
124
- value=(
125
- "Qwen3.5 uses hybrid SSM/Mamba-style gated-delta layers. Older llama.cpp builds may not "
126
- "recognize those tensors or metadata, so the GGUF can download correctly but still fail at "
127
- "model load. Use a recent llama.cpp or a llama-cpp-python wheel that bundles a compatible commit."
128
- ),
129
- )
130
- style = gr.Dropdown(
131
- choices=list(STYLE_PRESETS),
132
- value="ADI concise",
133
- label="Style preset",
134
- )
135
- custom_style = gr.Textbox(label="Custom style override", lines=3)
136
- tags = gr.Textbox(label="Tags", value="adi,distillation,qwen3.5")
137
- include_variants = gr.Checkbox(label="Generate five variants", value=True)
138
- build = gr.Button("Generate JSONL", variant="primary")
139
- with gr.Column(scale=1):
140
- summary = gr.Textbox(label="Summary", interactive=False)
141
- preview = gr.Code(label="First record preview", language="json", lines=18)
142
- download = gr.File(label="Download JSONL")
143
-
144
- jsonl = gr.Code(label="Full JSONL", language="json", lines=14)
145
- build.click(
146
- build_dataset,
147
- inputs=[instruction, teacher, style, custom_style, tags, include_variants],
148
- outputs=[summary, preview, jsonl, download],
149
- )
150
-
151
-
152
- if __name__ == "__main__":
153
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
index.html ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <title>ADI Distillation Studio</title>
7
+ <style>
8
+ :root { color-scheme: dark; --bg:#080b10; --panel:#151922; --line:#303745; --text:#f5f7fb; --muted:#aab2c0; --accent:#12b981; }
9
+ * { box-sizing: border-box; }
10
+ body { margin:0; font:15px/1.45 system-ui, -apple-system, Segoe UI, sans-serif; background:var(--bg); color:var(--text); }
11
+ main { max-width:1180px; margin:0 auto; padding:28px 18px 40px; }
12
+ h1 { margin:0 0 18px; font-size:30px; }
13
+ label { display:block; font-weight:700; margin:0 0 8px; }
14
+ textarea, input, select { width:100%; border:1px solid var(--line); border-radius:8px; background:#0d1118; color:var(--text); padding:12px; font:inherit; }
15
+ textarea { min-height:128px; resize:vertical; }
16
+ .grid { display:grid; grid-template-columns:minmax(300px, 0.9fr) minmax(360px, 1.1fr); gap:18px; align-items:start; }
17
+ .panel { background:var(--panel); border:1px solid var(--line); border-radius:8px; padding:16px; }
18
+ .row { display:grid; grid-template-columns:1fr 1fr; gap:12px; }
19
+ .field { margin-bottom:14px; }
20
+ button, a.button { display:inline-flex; justify-content:center; align-items:center; min-height:42px; border:0; border-radius:8px; padding:0 16px; background:var(--accent); color:#04110c; font-weight:800; cursor:pointer; text-decoration:none; }
21
+ pre { margin:0; white-space:pre-wrap; word-break:break-word; background:#0d1118; border:1px solid var(--line); border-radius:8px; padding:14px; min-height:220px; color:#d8ffe9; }
22
+ .muted { color:var(--muted); }
23
+ .actions { display:flex; gap:10px; flex-wrap:wrap; align-items:center; }
24
+ @media (max-width: 850px) { .grid, .row { grid-template-columns:1fr; } }
25
+ </style>
26
+ </head>
27
+ <body>
28
+ <main>
29
+ <h1>ADI Distillation Studio</h1>
30
+ <div class="grid">
31
+ <section class="panel">
32
+ <div class="field">
33
+ <label for="instruction">Instruction / user request</label>
34
+ <textarea id="instruction">Explain why a recent llama.cpp build is needed for Qwen3.5 GGUF models.</textarea>
35
+ </div>
36
+ <div class="field">
37
+ <label for="teacher">Teacher answer</label>
38
+ <textarea id="teacher">Qwen3.5 uses hybrid SSM/Mamba-style gated-delta layers. Older llama.cpp builds may not recognize those tensors or metadata, so the GGUF can download correctly but still fail at model load. Use a recent llama.cpp or a llama-cpp-python wheel that bundles a compatible commit.</textarea>
39
+ </div>
40
+ <div class="row">
41
+ <div class="field">
42
+ <label for="style">Style preset</label>
43
+ <select id="style">
44
+ <option>ADI concise</option>
45
+ <option>Technical mentor</option>
46
+ <option>Support agent</option>
47
+ <option>Creative partner</option>
48
+ <option>Safety reviewer</option>
49
+ </select>
50
+ </div>
51
+ <div class="field">
52
+ <label for="tags">Tags</label>
53
+ <input id="tags" value="adi,distillation,qwen3.5" />
54
+ </div>
55
+ </div>
56
+ <div class="field">
57
+ <label for="custom">Custom style override</label>
58
+ <textarea id="custom" style="min-height:80px"></textarea>
59
+ </div>
60
+ <div class="actions">
61
+ <button id="generate">Generate JSONL</button>
62
+ <a id="download" class="button" download="adi-distillation.jsonl">Download JSONL</a>
63
+ </div>
64
+ </section>
65
+ <section class="panel">
66
+ <p id="summary" class="muted">Ready.</p>
67
+ <label>First record preview</label>
68
+ <pre id="preview"></pre>
69
+ <label style="margin-top:14px">Full JSONL</label>
70
+ <pre id="jsonl"></pre>
71
+ </section>
72
+ </div>
73
+ </main>
74
+ <script>
75
+ const styles = {
76
+ "ADI concise": "Answer clearly, directly, and with practical next steps. Keep the tone calm and capable.",
77
+ "Technical mentor": "Explain the reasoning briefly, use precise terms, and make the user feel more capable.",
78
+ "Support agent": "Be reassuring, diagnose the issue, and give a short ordered fix path.",
79
+ "Creative partner": "Offer useful ideas with warmth and imagination while staying grounded.",
80
+ "Safety reviewer": "Identify risks, state assumptions, and recommend the safest useful action."
81
+ };
82
+ const variants = ["Direct task", "Beginner phrasing", "Production constraint", "Edge case", "Follow-up turn"];
83
+ const clean = text => (text || "").trim().replace(/\s+/g, " ");
84
+ function userVariant(text, idx) {
85
+ if (idx === 1) return "I'm new to this. " + text;
86
+ if (idx === 2) return text + " Keep the answer production-ready and avoid unnecessary detail.";
87
+ if (idx === 3) return text + " Also mention one common edge case or failure mode.";
88
+ if (idx === 4) return "Follow up on this request and make the answer easier to act on: " + text;
89
+ return text;
90
+ }
91
+ function assistantVariant(answer, style, idx) {
92
+ const sentences = answer.split(/(?<=[.!?])\s+/).filter(Boolean);
93
+ if (idx === 1) return "Here is the short version: " + answer;
94
+ if (idx === 2) return sentences.slice(0, 6).map((s, i) => `${i + 1}. ${s}`).join("\n") || answer;
95
+ if (idx === 3) return answer + "\n\nWatch for: missing context, stale assumptions, or inputs that do not match the expected format.";
96
+ if (idx === 4) return answer + "\n\nStyle target: " + style;
97
+ return answer;
98
+ }
99
+ function generate() {
100
+ const instruction = clean(document.querySelector("#instruction").value);
101
+ const teacher = clean(document.querySelector("#teacher").value);
102
+ const style = clean(document.querySelector("#custom").value) || styles[document.querySelector("#style").value];
103
+ const tags = document.querySelector("#tags").value.split(",").map(t => t.trim()).filter(Boolean);
104
+ if (!instruction || !teacher) return;
105
+ const records = variants.map((source, idx) => ({
106
+ messages: [
107
+ {role: "system", content: "You are ADI. " + style},
108
+ {role: "user", content: userVariant(instruction, idx)},
109
+ {role: "assistant", content: assistantVariant(teacher, style, idx)}
110
+ ],
111
+ metadata: {source, tags}
112
+ }));
113
+ const jsonl = records.map(r => JSON.stringify(r)).join("\n") + "\n";
114
+ document.querySelector("#summary").textContent = `Generated ${records.length} JSONL records.`;
115
+ document.querySelector("#preview").textContent = JSON.stringify(records[0], null, 2);
116
+ document.querySelector("#jsonl").textContent = jsonl;
117
+ const blob = new Blob([jsonl], {type:"application/jsonl"});
118
+ document.querySelector("#download").href = URL.createObjectURL(blob);
119
+ }
120
+ document.querySelector("#generate").addEventListener("click", generate);
121
+ generate();
122
+ </script>
123
+ </body>
124
+ </html>
requirements.txt DELETED
@@ -1 +0,0 @@
1
- gradio==6.19.0