masterjedi commited on
Commit ·
be4c8b2
1
Parent(s): 13fba23
Create ADI distillation studio Space
Browse files- .gitattributes +1 -4
- README.md +5 -7
- app.py +153 -0
- requirements.txt +1 -0
.gitattributes
CHANGED
|
@@ -3,20 +3,16 @@
|
|
| 3 |
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
-
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
-
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
-
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
-
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
*.pt filter=lfs diff=lfs merge=lfs -text
|
|
@@ -33,3 +29,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 3 |
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
|
|
|
| 6 |
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 8 |
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 9 |
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
| 10 |
*.model filter=lfs diff=lfs merge=lfs -text
|
| 11 |
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 12 |
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 13 |
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 14 |
*.onnx filter=lfs diff=lfs merge=lfs -text
|
|
|
|
| 15 |
*.parquet filter=lfs diff=lfs merge=lfs -text
|
|
|
|
| 16 |
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 17 |
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 18 |
*.pt filter=lfs diff=lfs merge=lfs -text
|
|
|
|
| 29 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 30 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 31 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.jsonl filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
|
@@ -1,13 +1,11 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 6.19.0
|
| 8 |
-
python_version: '3.
|
| 9 |
app_file: app.py
|
| 10 |
pinned: false
|
| 11 |
---
|
| 12 |
-
|
| 13 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: ADI Distillation Studio
|
| 3 |
+
emoji: 🧪
|
| 4 |
+
colorFrom: gray
|
| 5 |
+
colorTo: green
|
| 6 |
sdk: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|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
gradio==6.19.0
|