Spaces:
Runtime error
Runtime error
File size: 1,572 Bytes
7d73ce2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | import gradio as gr
import json
def detect_chat_format(model_name: str) -> str:
"""Detect the correct chat format for a dispatchAI model.
Args:
model_name: Model name or repo ID
Returns:
JSON with the correct chat_format and usage code
"""
lower = model_name.lower()
if "smollm" in lower or "llama-3" in lower:
fmt = "llama-3"
elif "gemma" in lower:
fmt = "gemma"
elif "qwen" in lower or "phi" in lower or "tinyllama" in lower or "minicpm" in lower:
fmt = "chatml"
else:
fmt = "chatml"
code = f'''from llama_cpp import Llama
llm = Llama(
model_path="model.gguf",
chat_format="{fmt}",
n_ctx=512,
n_threads=4,
verbose=False
)
response = llm.create_chat_completion(
messages=[{{"role": "user", "content": "Hello!"}}],
max_tokens=50
)
print(response["choices"][0]["message"]["content"])'''
return json.dumps({
"model_name": model_name,
"chat_format": fmt,
"code": code,
}, indent=2)
with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue"), title="Chat Format Detector") as demo:
gr.Markdown("# 🎯 Chat Format Detector (MCP)")
inp = gr.Textbox(label="Model Name", placeholder="SmolLM2-135M-Instruct-mobile")
btn = gr.Button("Detect Format", variant="primary")
out = gr.Textbox(label="Result (JSON)", lines=15)
btn.click(fn=detect_chat_format, inputs=inp, outputs=out)
gr.Markdown("---\n🚀 [dispatchAI](https://huggingface.co/dispatchAI)")
demo.launch(mcp_server=True)
|