Zeel commited on
Commit
8b720fd
·
1 Parent(s): fcbbb53

support unsloth templates in URL

Browse files
Files changed (1) hide show
  1. app.py +9 -2
app.py CHANGED
@@ -56,7 +56,14 @@ col.image("https://raw.githubusercontent.com/unslothai/unsloth/main/images/made%
56
  model = st.text_input("Enter HuggingFace model name", st.query_params.get("model", "Qwen/Qwen2-VL-7B-Instruct"))
57
  processor = AutoProcessor.from_pretrained(model, trust_remote_code=True)
58
  text_tokenizer = processor if not hasattr(processor, "tokenizer") else processor.tokenizer
59
- chat_template_key = st.selectbox("Select chat template", ["model_default"] + list(CHAT_TEMPLATES.keys()), index=0)
 
 
 
 
 
 
 
60
 
61
  if chat_template_key == "model_default":
62
  chat_template = None
@@ -105,5 +112,5 @@ st.markdown("#### Masked Prompt ('x' is the mask token)")
105
  st.code(masked_text, language="html")
106
 
107
  st.markdown("#### You may share the following URL with others to show them the results")
108
- url = f"https://zeel-twro.hf.space?model={model}&message={message}&instruction_part={instruction_part}&response_part={response_part}"
109
  st.markdown(f"`{url}`")
 
56
  model = st.text_input("Enter HuggingFace model name", st.query_params.get("model", "Qwen/Qwen2-VL-7B-Instruct"))
57
  processor = AutoProcessor.from_pretrained(model, trust_remote_code=True)
58
  text_tokenizer = processor if not hasattr(processor, "tokenizer") else processor.tokenizer
59
+ chat_template_predefined = st.query_params.get("chat_template_idx", None)
60
+ possible_templates = ["model_default"] + sorted(CHAT_TEMPLATES.keys())
61
+ if chat_template_predefined is not None:
62
+ chat_template_idx = possible_templates.index(chat_template_predefined)
63
+ else:
64
+ chat_template_idx = 0
65
+
66
+ chat_template_key = st.selectbox("Select chat template", possible_templates, index=chat_template_idx)
67
 
68
  if chat_template_key == "model_default":
69
  chat_template = None
 
112
  st.code(masked_text, language="html")
113
 
114
  st.markdown("#### You may share the following URL with others to show them the results")
115
+ url = f"https://zeel-twro.hf.space?model={model}&message={message}&instruction_part={instruction_part}&response_part={response_part}&chat_template_idx={chat_template_key}"
116
  st.markdown(f"`{url}`")