SamuelBang commited on
Commit
afa9244
·
verified ·
1 Parent(s): 012ffb0

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +313 -0
README.md ADDED
@@ -0,0 +1,313 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model:
3
+ - Qwen/Qwen3-4B-Instruct-2507
4
+ ---
5
+
6
+ # Code Aesthetics with Agentic Reward Feedback
7
+ <div align="center">
8
+ <a href='https://bangx7.github.io/code-aesthetics/'><img src='https://img.shields.io/badge/Project-Page-Green'></a>
9
+ <br>
10
+ <a href="https://arxiv.org/abs/2510.23272"><b>Paper Link</b>👁️</a>
11
+ </div>
12
+ <div align="center">
13
+ <p>
14
+ <sup>1,2</sup><a href="https://bangx7.github.io" target="_blank">Bang Xiao</a><sup>#</sup>,</span>
15
+ <span class="author-block">
16
+ <sup>1,3</sup><a href="https://github.com/JackLingjie" target="_blank">Lingjie Jiang</a><sup>#</sup>,</span>
17
+ <span class="author-block">
18
+ <sup>1</sup><a href="https://www.microsoft.com/en-us/research/people/shaohanh/" target="_blank">Shaohan Huang</a><sup>✉</sup>,</span>
19
+ <span class="author-block">
20
+ <sup>1</sup><a href="https://www.microsoft.com/en-us/research/people/tengchaolv/" target="_blank">Tengchao Lv</a>,
21
+ </span>
22
+ <span class="author-block">
23
+ <sup>1</sup><a href="https://www.microsoft.com/en-us/research/people/yupanhuang/" target="_blank">Yupan Huang</a>,
24
+ </span>
25
+ <span class="author-block">
26
+ <sup>1</sup><a href="https://yushuiwx.github.io/" target="_blank">Xun Wu</a>,
27
+ </span>
28
+ <span class="author-block">
29
+ <sup>1</sup><a href="https://www.microsoft.com/en-us/research/people/lecu/" target="_blank">Lei Cui</a>,
30
+ </span>
31
+ <span class="author-block">
32
+ <sup>1</sup><a href="https://www.microsoft.com/en-us/research/people/fuwei/" target="_blank">Furu Wei</a>
33
+ </span>
34
+ </p>
35
+ <p>
36
+ <sup>1</sup>Microsoft Research Asia &nbsp;&nbsp;
37
+ <sup>2</sup>Zhiyuan College, Shanghai Jiao Tong University &nbsp;&nbsp;
38
+ <sup>3</sup>Peking University<br>
39
+ <sup>#</sup>Equal Contribution
40
+ <sup>✉</sup>Corresponding author
41
+ </p>
42
+ </div>
43
+
44
+ **Note: This is the version of AesCoder-4B model for only webpage design.**
45
+
46
+ ## Quickstart
47
+ ### VLLM deployment (Recommended)
48
+
49
+ We recommend using `vllm>=0.8.5` for efficient inference and deployment. Here's how to get started:
50
+
51
+ **Installation:**
52
+ ```bash
53
+ pip install vllm>=0.8.5
54
+ ```
55
+
56
+ **API Server Deployment:**
57
+ To create an OpenAI-compatible API endpoint:
58
+ ```bash
59
+ vllm serve SamuelBang/AesCoder-4B --max-model-len 262144
60
+ ```
61
+
62
+ **Using with OpenAI Client:**
63
+ ```python
64
+ from openai import OpenAI
65
+
66
+ # Initialize the client
67
+ client = OpenAI(
68
+ base_url="http://localhost:8000/v1",
69
+ api_key="None"
70
+ )
71
+
72
+ # Generate completion
73
+ response = client.chat.completions.create(
74
+ model="SamuelBang/AesCoder-4B",
75
+ messages=[
76
+ {"role": "user", "content": "Create a user-friendly website for a landing page dedicated to selling dog-related products."}
77
+ ],
78
+ temperature=0.8,
79
+ max_tokens=16384
80
+ )
81
+
82
+ # Get the generated content
83
+ content = response.choices[0].message.content
84
+ print("Generated content:", content)
85
+ ```
86
+
87
+ **Basic vLLM Usage:**
88
+ ```python
89
+ from vllm import LLM, SamplingParams
90
+
91
+ model_name = "SamuelBang/AesCoder-4B"
92
+
93
+ # Initialize the model
94
+ llm = LLM(
95
+ model=model_name,
96
+ max_model_len=262144, # Maximum context length
97
+ tensor_parallel_size=1, # Adjust based on your GPU setup
98
+ )
99
+
100
+ # Define sampling parameters
101
+ sampling_params = SamplingParams(
102
+ temperature=0.8,
103
+ top_p=0.8,
104
+ top_k=20,
105
+ min_p=0,
106
+ max_tokens=16384
107
+ )
108
+
109
+ # Prepare the prompt
110
+ prompt = "Create a user-friendly website for a landing page dedicated to selling dog-related products. "
111
+ messages = [
112
+ {"role": "user", "content": prompt}
113
+ ]
114
+
115
+ # Apply chat template (you'll need to get the tokenizer for this)
116
+ from transformers import AutoTokenizer
117
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
118
+ text = tokenizer.apply_chat_template(
119
+ messages,
120
+ tokenize=False,
121
+ add_generation_prompt=True,
122
+ )
123
+
124
+ # Generate text
125
+ outputs = llm.generate([text], sampling_params)
126
+
127
+ # Get the result
128
+ content = outputs[0].outputs[0].text
129
+ print("Generated content:", content)
130
+ ```
131
+
132
+ **Note:** If you encounter out-of-memory (OOM) issues, consider reducing the context length to a shorter value, such as `32,768` or adjusting the `tensor_parallel_size` based on your available GPU memory.
133
+
134
+
135
+
136
+ ### SGLang Deployment
137
+ You can use `sglang>=0.4.6.post1` to create an OpenAI-compatible API endpoint:
138
+
139
+ ```shell
140
+ python -m sglang.launch_server --model-path SamuelBang/AesCoder-4B --context-length 262144
141
+ ```
142
+
143
+
144
+ **Note: If you encounter out-of-memory (OOM) issues, consider reducing the context length to a shorter value, such as `32,768`.**
145
+ ### Use with origin `transformer` package (NOT recommended, very slow)
146
+
147
+ The code of Qwen3 has been in the latest Hugging Face `transformers` and we advise you to use the latest version of `transformers`.
148
+
149
+ With `transformers<4.51.0`, you will encounter the following error:
150
+ ```
151
+ KeyError: 'qwen3'
152
+ ```
153
+
154
+ The following contains a code snippet illustrating how to use the model generate content based on given inputs.
155
+ ```python
156
+ from transformers import AutoModelForCausalLM, AutoTokenizer
157
+
158
+ model_name = "SamuelBang/AesCoder-4B"
159
+
160
+ # load the tokenizer and the model
161
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
162
+ model = AutoModelForCausalLM.from_pretrained(
163
+ model_name,
164
+ torch_dtype="auto",
165
+ device_map="auto"
166
+ )
167
+
168
+ # prepare the model input
169
+ prompt = "Create a user-friendly website for a landing page dedicated to selling dog-related products. "
170
+ messages = [
171
+ {"role": "user", "content": prompt}
172
+ ]
173
+ text = tokenizer.apply_chat_template(
174
+ messages,
175
+ tokenize=False,
176
+ add_generation_prompt=True,
177
+ )
178
+ model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
179
+
180
+ # conduct text completion
181
+ generated_ids = model.generate(
182
+ **model_inputs,
183
+ max_new_tokens=16384,
184
+ temperature=0.8
185
+ )
186
+ output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
187
+
188
+ content = tokenizer.decode(output_ids, skip_special_tokens=True)
189
+
190
+ print("content:", content)
191
+ ```
192
+
193
+ ## Best Practices
194
+ ### Sampling Parameters
195
+ To achieve optimal performance, we suggest using `Temperature=0.8`, `TopP=0.8`, `TopK=20`, and `MinP=0` for sampling.
196
+
197
+ ### System Prompt
198
+ To achieve better webpage generation results with our model, please use appropriate system prompts. We have categorized webpage generation into 5 main categories, and the recommended system prompts for each category are as follows (reference to: https://designarena.ai):
199
+
200
+ Website:
201
+ ```txt
202
+ You are an expert web developer and designer specializing in modern websites. Create a complete, working HTML page with embedded CSS and JavaScript if needed. Feel free to use lightweight libraries like Tailwind CSS to enhance the design as long as they can be rendered in an iframe.
203
+ Requirements:
204
+ 1. Create a fully functional, modern, and responsive website design
205
+ 2. Use only HTML, CSS, and JavaScript, but feel free to use libraries like Tailwind CSS to make the design better. Libraries such as ThreeJS, react three fiber, drei, @react-three/postprocessing, @react-three/cannon, d3, and recharts as additional libraries can be imported.
206
+ 3. Include all styles inline within <style> tags
207
+ 4. Focus on clean layouts, typography, and user experience
208
+ 5. Implement modern web design trends (gradients, shadows, smooth animations)
209
+ 6. Ensure excellent mobile responsiveness
210
+ 7. Include interactive elements where appropriate
211
+ 8. Make it production-ready and professional
212
+ 9. You must include all relevant script tags for libraries to work properly.
213
+ Return ONLY the complete HTML code, starting with <!DOCTYPE html> and ending with </html>. Do not include any explanations or markdown formatting.
214
+ ```
215
+
216
+ Game Development:
217
+ ```txt
218
+ You are an expert game developer specializing in browser-based games. Create a complete, working HTML page with an interactive game using embedded CSS and JavaScript.
219
+ Requirements:
220
+ 1. Create a fully functional, playable browser game
221
+ 2. Use HTML, CSS, and JavaScript, but feel free to use libraries Tailwind CSS to make the game better as long as they will render in iframe. Libraries such as ThreeJS, react three fiber, drei, @react-three/postprocessing, @react-three/cannon, d3, and recharts (and others) can be imported.
222
+ 3. Include all styles inline within <style> tags
223
+ 4. Implement game mechanics, controls, and scoring systems
224
+ 5. Include game states (start screen, gameplay, game over)
225
+ 6. Add visual feedback, animations, and sound effects using Web Audio API if needed
226
+ 7. Ensure responsive design that works on both desktop and mobile
227
+ 8. Make the game engaging and fun to play
228
+ 9. You must include all relevant script tags for libraries to work properly.
229
+ Return ONLY the complete HTML code, starting with <!DOCTYPE html> and ending with </html>. Do not include any explanations or markdown formatting.
230
+ ```
231
+
232
+ 3D Design
233
+ ```txt
234
+ You are an expert in 3D graphics and WebGL. Create a complete, working HTML page with 3D graphics and animations using embedded CSS and JavaScript.
235
+ Requirements:
236
+ 1. Create a fully functional 3D scene or application
237
+ 2. Use only CSS, and vanilla JavaScript with WebGL or CSS 3D transforms. Feel free to use lightweight libraries like Three.js or Babylon.js to make the 3D design better as long as they can be rendered in an iframe. Libraries such as ThreeJS, react three fiber, drei, @react-three/postprocessing, @react-three/cannon, d3, and recharts (and others) can be imported.
238
+ 3. Include all styles inline within <style> tags
239
+ 4. Implement 3D models, animations, and interactive controls
240
+ 5. Add proper lighting, materials, and camera controls
241
+ 6. Include smooth animations and user interaction
242
+ 7. Ensure good performance and responsive design
243
+ 8. Make it visually impressive and production-ready
244
+ 9. You must include all relevant script tags for libraries to work properly.
245
+ Return ONLY the complete HTML code, starting with <!DOCTYPE html> and ending with </html>. Do not include any explanations or markdown formatting.
246
+ ```
247
+
248
+
249
+ Data Visualization
250
+ ```txt
251
+ You are an expert in data visualization and interactive charts. Create a complete, working HTML page with dynamic data visualization capabilities using embedded CSS and JavaScript. Feel free to use lightwight libraries (as long as it can be rendered in an iframe) such as Tailwind CSS.
252
+
253
+ Requirements:
254
+ 1. Create a fully functional data visualization application with interactive charts and graphs
255
+ 2. Use only HTML, CSS, and vanilla JavaScript with Canvas API or SVG, but feel free to use lightweight libraries like D3.js or Chart.js to make the visualizations better as long as they can be rendered in an iframe. Libraries such as ThreeJS, react three fiber, drei, @react-three/postprocessing, @react-three/cannon, d3, and recharts (and others) can be imported.
256
+ 3. Include all styles inline within <style> tags
257
+ 4. Ensure responsive design that adapts to different screen sizes
258
+ 5. Your goal is to make the design of the data visualization top-notch.
259
+ 6. You must include all relevant script tags for libraries to work properly.
260
+
261
+ When making data visualizations, always set "maintain aspect ratio" to true.
262
+
263
+ Return ONLY the complete HTML code, starting with <!DOCTYPE html> and ending with </html>. Do not include any explanations or markdown formatting.
264
+ ```
265
+
266
+ UI Component
267
+ ```txt
268
+ You are a world-class UI/UX designer and frontend engineer with a sharp eye for aesthetics, accessibility, and modern interaction design. Your task is to generate complete, production-ready HTML pages showcasing **visually stunning, highly interactive, and responsive UI components** using only HTML, CSS, and JavaScript.
269
+
270
+ **Guidelines:**
271
+ 1. Deliver a single, fully functional UI component as a complete HTML page
272
+ 2. Use **only** embedded <style> and <script> tags – all code must be self-contained
273
+ 3. You may use:
274
+ - Tailwind CSS (via CDN)
275
+ - Lightweight icon libraries (e.g., Heroicons)
276
+ - Three.js, react-three-fiber, drei, d3, recharts (for advanced visuals), and others if you import them properly
277
+ 4. Ensure **fully responsive design**, supporting both desktop and mobile layouts
278
+ 5. Design for **realistic production scenarios** – avoid toy examples; the component should look ready to ship in a startup or app design system
279
+ 6. You must include all relevant script tags for libraries to work properly.
280
+
281
+ **Design Requirements (unless the user specifies otherwise):**
282
+ - Contemporary visual style: Soft shadows, rounded corners, clean typography, subtle gradients
283
+ - State handling: Show all interactive states (hover, active, loading, disabled, success)
284
+ - Microinteractions: Include smooth transitions and animations for interactive elements
285
+ - Accessibility: Use semantic HTML and ARIA roles where appropriate
286
+ - Use thoughtful spacing, sizing, and visual hierarchy
287
+
288
+ **Bonus:**
289
+ - Add delight through animations, hover effects, or clever color usage
290
+ - Incorporate a beautiful and functional layout structure, not just the component
291
+
292
+ Final Output:
293
+ Return ONLY the full, standalone HTML code (starting with <!DOCTYPE html>) and nothing else. No explanations, no markdown formatting.
294
+
295
+ If the user specifies a particular style (e.g., glassmorphism, brutalism, Material Design), follow their style instructions instead of the default design preferences.
296
+ ```
297
+
298
+
299
+
300
+
301
+ ## &#x1F4DA; Citation
302
+ If you find this codebase useful for your research, please use the following entry.
303
+ ```BibTeX
304
+ @misc{xiao2025codeaestheticsagenticreward,
305
+ title={Code Aesthetics with Agentic Reward Feedback},
306
+ author={Bang Xiao and Lingjie Jiang and Shaohan Huang and Tengchao Lv and Yupan Huang and Xun Wu and Lei Cui and Furu Wei},
307
+ year={2025},
308
+ eprint={2510.23272},
309
+ archivePrefix={arXiv},
310
+ primaryClass={cs.CL},
311
+ url={https://arxiv.org/abs/2510.23272},
312
+ }
313
+ ```