MathObsession commited on
Commit
48353a0
·
verified ·
1 Parent(s): d704d5b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -11
app.py CHANGED
@@ -2,15 +2,15 @@ import os
2
  import torch
3
  import gradio as gr
4
  import spaces
5
- # Corrected imports for vision-language generation models
6
- from transformers import AutoModelForConditionalGeneration, AutoProcessor
7
 
8
  MODEL_ID = "OmniSVG/OmniSVG1.1_8B"
9
- print("Loading processor and vision-language model configuration...")
10
 
11
- # Initialize using the proper Auto classes
12
  processor = AutoProcessor.from_pretrained(MODEL_ID, trust_remote_code=True)
13
- model = AutoModelForConditionalGeneration.from_pretrained(
14
  MODEL_ID,
15
  dtype=torch.bfloat16,
16
  trust_remote_code=True
@@ -31,7 +31,7 @@ def generate_vector_icon(prompt_text):
31
 
32
  full_prompt = f"{system_rules}\n\nIcon Request: {prompt_text}\nSVG Output:"
33
 
34
- # Standard messaging array format structure for Qwen VL backbones
35
  messages = [
36
  {
37
  "role": "user",
@@ -39,13 +39,13 @@ def generate_vector_icon(prompt_text):
39
  }
40
  ]
41
 
42
- # Render the input structure with chat templates
43
  text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
44
 
45
  device = "cuda" if torch.cuda.is_available() else "cpu"
46
  model.to(device)
47
 
48
- # Package input dictionaries onto the runtime device
49
  inputs = processor(text=[text], images=None, padding=True, return_tensors="pt").to(device)
50
 
51
  with torch.no_grad():
@@ -56,7 +56,7 @@ def generate_vector_icon(prompt_text):
56
  temperature=0.0
57
  )
58
 
59
- # Strip prompt prefix IDs to extract just the generated SVG text payload
60
  generated_ids_trimmed = [
61
  out_ids[len(in_ids):] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
62
  ]
@@ -65,14 +65,14 @@ def generate_vector_icon(prompt_text):
65
  generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
66
  ).strip()
67
 
68
- # Write the response block to an asset file so Gradio client can fetch it
69
  output_filename = "generated_icon.svg"
70
  with open(output_filename, "w", encoding="utf-8") as f:
71
  f.write(response)
72
 
73
  return output_filename
74
 
75
- # Expose the API matrix interface
76
  demo = gr.Interface(
77
  fn=generate_vector_icon,
78
  inputs=gr.Textbox(label="Icon Prompt Description", placeholder="e.g., download arrow tray"),
 
2
  import torch
3
  import gradio as gr
4
  import spaces
5
+ # Use the explicit model class for Qwen2.5-VL architectures
6
+ from transformers import Qwen2_5_VLForConditionalGeneration, AutoProcessor
7
 
8
  MODEL_ID = "OmniSVG/OmniSVG1.1_8B"
9
+ print("Loading processor and Qwen2.5-VL vision-language model architecture...")
10
 
11
+ # Initialize the processor and the model cleanly
12
  processor = AutoProcessor.from_pretrained(MODEL_ID, trust_remote_code=True)
13
+ model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
14
  MODEL_ID,
15
  dtype=torch.bfloat16,
16
  trust_remote_code=True
 
31
 
32
  full_prompt = f"{system_rules}\n\nIcon Request: {prompt_text}\nSVG Output:"
33
 
34
+ # Structure text formatting using Qwen-VL chat message guidelines
35
  messages = [
36
  {
37
  "role": "user",
 
39
  }
40
  ]
41
 
42
+ # Process text layout templates
43
  text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
44
 
45
  device = "cuda" if torch.cuda.is_available() else "cpu"
46
  model.to(device)
47
 
48
+ # Parse through the multi-modal text pipeline
49
  inputs = processor(text=[text], images=None, padding=True, return_tensors="pt").to(device)
50
 
51
  with torch.no_grad():
 
56
  temperature=0.0
57
  )
58
 
59
+ # Strip layout prefix arrays
60
  generated_ids_trimmed = [
61
  out_ids[len(in_ids):] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
62
  ]
 
65
  generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
66
  ).strip()
67
 
68
+ # Write structural stream data to file assets
69
  output_filename = "generated_icon.svg"
70
  with open(output_filename, "w", encoding="utf-8") as f:
71
  f.write(response)
72
 
73
  return output_filename
74
 
75
+ # Expose API endpoint layers
76
  demo = gr.Interface(
77
  fn=generate_vector_icon,
78
  inputs=gr.Textbox(label="Icon Prompt Description", placeholder="e.g., download arrow tray"),