Spaces:
Sleeping
Sleeping
Update app.py
Browse files1 unmodified line23455678891011121310141516141718192021222324212225262728292 unmodified lines323334313235363738398 unmodified lines4849504751525354555657545859565760616259636461656667682 unmodified lines71727370747576771 unmodified lineimport torchimport gradio as grimport spacesfrom transformers import AutoModelForCausalLM, AutoTokenizerfrom transformers import AutoConfig, AutoModelForCausalLM, AutoTokenizer
MODEL_ID = "OmniSVG/OmniSVG1.1_8B"print("Loading tokenizer and model layers...")print("Loading customized architecture layers...")
# Force the config to trick transformers into treating this as a causal text modelconfig = AutoConfig.from_pretrained(MODEL_ID, trust_remote_code=True)config.architectures = ["Qwen2ForCausalLM"] # Bypasses the strict Qwen2_5_VL validation logic
# Explicitly load using the standard text stack to avoid missing vision preprocessor issuestokenizer = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=True)model = AutoModelForCausalLM.from_pretrained( MODEL_ID, torch_dtype=torch.bfloat16, config=config, dtype=torch.bfloat16, # Fixed the deprecated parameter warning trust_remote_code=True)
@spaces.GPU(duration=60)def generate_vector_icon(prompt_text): """ Processes text inputs through the OmniSVG tokenization path to generate raw mathematical code blocks. Processes the minimalist text prompt through the OmniSVG tokenization path to output valid SVG path coordinates. """ system_rules = ( "You are an expert UI/UX line icon designer. Generate a clean, 24x24 minimalist icon. "2 unmodified lines "Output raw SVG xml code ONLY." ) # Standard prompt injection format for text-space SVG backends full_prompt = f"<|im_start|>system\n{system_rules}<|im_end|>\n<|im_start|>user\nIcon Request: {prompt_text}<|im_end|>\n<|im_start|>assistant\nSVG Output:" # Correct string template structure for text-driven SVG generators full_prompt = f"<|im_start|><system>\n{system_rules}<|im_end|>\n<|im_start|><user>\nIcon Request: {prompt_text}<|im_end|>\n<|im_start|><assistant>\nSVG Output:" device = "cuda" if torch.cuda.is_available() else "cpu" model.to(device)8 unmodified lines temperature=0.0 ) # Exclude prompt vectors from final token generation stream # Strip prompt prefix array IDs generated_ids_trimmed = [ out_ids[len(in_ids):] for in_ids, out_ids in zip(inputs.input_ids, generated_ids) ] response = tokenizer.batch_decode( generated_ids_trimmed, skip_special_tokens=True )[0].strip() ).strip() # Strip residual markdown ticks if the model returns them if response.startswith("```xml"): # Strip residual codeblock fences if generated by the model if "```xml" in response: response = response.split("```xml")[1].split("```")[0].strip() elif response.startswith("```html"): elif "```html" in response: response = response.split("```html")[1].split("```")[0].strip() elif response.startswith("```"): elif "```" in response: response = response.split("```")[1].split("```")[0].strip()
output_filename = "generated_icon.svg"2 unmodified lines return output_filename
# Mount Gradio framework# Expose Gradio GUIdemo = gr.Interface( fn=generate_vector_icon, inputs=gr.Textbox(label="Icon Prompt Description", placeholder="e.g., download arrow tray"),app.py+19-15