badaoui HF Staff commited on
Commit
c7e31fc
·
verified ·
1 Parent(s): c35efb6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +492 -0
app.py ADDED
@@ -0,0 +1,492 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import csv
2
+ import os
3
+ from datetime import datetime
4
+ from typing import Optional, Union, List
5
+ import gradio as gr
6
+ from huggingface_hub import HfApi, Repository
7
+ from optimum_neuron_export import convert
8
+ from gradio_huggingfacehub_search import HuggingfaceHubSearch
9
+ from apscheduler.schedulers.background import BackgroundScheduler
10
+
11
+ # Define transformer tasks and their categories for coloring
12
+ TRANSFORMER_TASKS = {
13
+ "auto": {"color": "#6b7280", "category": "Auto"},
14
+ "feature-extraction": {"color": "#3b82f6", "category": "Feature Extraction"},
15
+ "fill-mask": {"color": "#8b5cf6", "category": "NLP"},
16
+ "multiple-choice": {"color": "#8b5cf6", "category": "NLP"},
17
+ "question-answering": {"color": "#8b5cf6", "category": "NLP"},
18
+ "text-classification": {"color": "#8b5cf6", "category": "NLP"},
19
+ "token-classification": {"color": "#8b5cf6", "category": "NLP"},
20
+ "text-generation": {"color": "#10b981", "category": "Text Generation"},
21
+ "text2text-generation": {"color": "#10b981", "category": "Text Generation"},
22
+ "audio-classification": {"color": "#f59e0b", "category": "Audio"},
23
+ "automatic-speech-recognition": {"color": "#f59e0b", "category": "Audio"},
24
+ "audio-frame-classification": {"color": "#f59e0b", "category": "Audio"},
25
+ "audio-xvector": {"color": "#f59e0b", "category": "Audio"},
26
+ "image-classification": {"color": "#ef4444", "category": "Vision"},
27
+ "object-detection": {"color": "#ef4444", "category": "Vision"},
28
+ "semantic-segmentation": {"color": "#ef4444", "category": "Vision"},
29
+ "zero-shot-image-classification": {"color": "#ec4899", "category": "Multimodal"},
30
+ "sentence-similarity": {"color": "#06b6d4", "category": "Similarity"},
31
+ }
32
+
33
+ # Define diffusion pipeline types
34
+ DIFFUSION_PIPELINES = {
35
+ "text-to-image": {"color": "#ec4899", "category": "Stable Diffusion"},
36
+ "image-to-image": {"color": "#ec4899", "category": "Stable Diffusion"},
37
+ "inpaint": {"color": "#ec4899", "category": "Stable Diffusion"},
38
+ "instruct-pix2pix": {"color": "#ec4899", "category": "Stable Diffusion"},
39
+ "latent-consistency": {"color": "#8b5cf6", "category": "Latent Consistency"},
40
+ "stable-diffusion": {"color": "#10b981", "category": "Stable Diffusion"},
41
+ "stable-diffusion-xl": {"color": "#10b981", "category": "Stable Diffusion XL"},
42
+ "stable-diffusion-xl-img2img": {"color": "#10b981", "category": "Stable Diffusion XL"},
43
+ "stable-diffusion-xl-inpaint": {"color": "#10b981", "category": "Stable Diffusion XL"},
44
+ "controlnet": {"color": "#f59e0b", "category": "ControlNet"},
45
+ "controlnet-xl": {"color": "#f59e0b", "category": "ControlNet XL"},
46
+ "pixart-alpha": {"color": "#ef4444", "category": "PixArt"},
47
+ "pixart-sigma": {"color": "#ef4444", "category": "PixArt"},
48
+ "flux": {"color": "#06b6d4", "category": "Flux"},
49
+ }
50
+
51
+ TAGS = {
52
+ "Feature Extraction": {"color": "#3b82f6", "category": "Feature Extraction"},
53
+ "NLP": {"color": "#8b5cf6", "category": "NLP"},
54
+ "Text Generation": {"color": "#10b981", "category": "Text Generation"},
55
+ "Audio": {"color": "#f59e0b", "category": "Audio"},
56
+ "Vision": {"color": "#ef4444", "category": "Vision"},
57
+ "Multimodal": {"color": "#ec4899", "category": "Multimodal"},
58
+ "Similarity": {"color": "#06b6d4", "category": "Similarity"},
59
+ "Stable Diffusion": {"color": "#ec4899", "category": "Stable Diffusion"},
60
+ "Stable Diffusion XL": {"color": "#10b981", "category": "Stable Diffusion XL"},
61
+ "ControlNet": {"color": "#f59e0b", "category": "ControlNet"},
62
+ "ControlNet XL": {"color": "#f59e0b", "category": "ControlNet XL"},
63
+ "PixArt": {"color": "#ef4444", "category": "PixArt"},
64
+ "Latent Consistency": {"color": "#8b5cf6", "category": "Latent Consistency"},
65
+ "Flux": {"color": "#06b6d4", "category": "Flux"},
66
+ }
67
+
68
+ # UPDATED: New choices for the Pull Request destination UI component
69
+ DEST_NEW_NEURON_REPO = "Create new Neuron-optimized repository"
70
+ DEST_CACHE_REPO = "Create a PR in the cache repository"
71
+ DEST_CUSTOM_REPO = "Create a PR in a custom repository"
72
+
73
+ PR_DESTINATION_CHOICES = [
74
+ DEST_NEW_NEURON_REPO,
75
+ DEST_CACHE_REPO,
76
+ DEST_CUSTOM_REPO
77
+ ]
78
+
79
+ DEFAULT_CACHE_REPO = "aws-neuron/optimum-neuron-cache"
80
+
81
+ # Get all tasks and pipelines for dropdowns
82
+ ALL_TRANSFORMER_TASKS = list(TRANSFORMER_TASKS.keys())
83
+ ALL_DIFFUSION_PIPELINES = list(DIFFUSION_PIPELINES.keys())
84
+
85
+ def create_task_tag(task: str) -> str:
86
+ """Create a colored HTML tag for a task"""
87
+ if task in TRANSFORMER_TASKS:
88
+ color = TRANSFORMER_TASKS[task]["color"]
89
+ return f'<span style="background-color: {color}; color: white; padding: 2px 6px; border-radius: 12px; font-size: 0.75rem; font-weight: 500; margin: 1px;">{task}</span>'
90
+ elif task in DIFFUSION_PIPELINES:
91
+ color = DIFFUSION_PIPELINES[task]["color"]
92
+ return f'<span style="background-color: {color}; color: white; padding: 2px 6px; border-radius: 12px; font-size: 0.75rem; font-weight: 500; margin: 1px;">{task}</span>'
93
+ elif task in TAGS:
94
+ color = TAGS[task]["color"]
95
+ return f'<span style="background-color: {color}; color: white; padding: 2px 6px; border-radius: 12px; font-size: 0.75rem; font-weight: 500; margin: 1px;">{task}</span>'
96
+ else:
97
+ return f'<span style="background-color: #6b7280; color: white; padding: 2px 6px; border-radius: 12px; font-size: 0.75rem; font-weight: 500; margin: 1px;">{task}</span>'
98
+
99
+ def format_tasks_for_table(tasks_str: str) -> str:
100
+ """Convert comma-separated tasks into colored tags"""
101
+ tasks = [task.strip() for task in tasks_str.split(',')]
102
+ return ' '.join([create_task_tag(task) for task in tasks])
103
+
104
+ def update_task_dropdown(model_type: str):
105
+ """Update the task dropdown based on selected model type"""
106
+ if model_type == "transformers":
107
+ return gr.Dropdown(
108
+ choices=ALL_TRANSFORMER_TASKS,
109
+ value="auto",
110
+ label="Task (auto can infer task from model)",
111
+ visible=True
112
+ )
113
+ else: # diffusers
114
+ return gr.Dropdown(
115
+ choices=ALL_DIFFUSION_PIPELINES,
116
+ value="text-to-image",
117
+ label="Pipeline Type",
118
+ visible=True
119
+ )
120
+
121
+ def toggle_custom_repo_box(pr_destinations: List[str]):
122
+ """Show or hide the custom repo ID textbox based on checkbox selection."""
123
+ if DEST_CUSTOM_REPO in pr_destinations:
124
+ return gr.Textbox(visible=True)
125
+ else:
126
+ return gr.Textbox(visible=False, value="")
127
+
128
+ def neuron_export(model_id: str, model_type: str, task_or_pipeline: str,
129
+ pr_destinations: List[str], custom_repo_id: str, custom_cache_repo: str, oauth_token: gr.OAuthToken):
130
+
131
+ log_buffer = ""
132
+ def log(msg):
133
+ nonlocal log_buffer
134
+ # Handle cases where the message from the backend is not a string
135
+ if not isinstance(msg, str):
136
+ msg = str(msg)
137
+ log_buffer += msg + "\n"
138
+ return log_buffer
139
+
140
+ if oauth_token.token is None:
141
+ yield log("You must be logged in to use this space")
142
+ return
143
+
144
+ if not model_id:
145
+ yield log("🚫 Invalid input. Please specify a model name from the hub.")
146
+ return
147
+
148
+ try:
149
+ api = HfApi(token=oauth_token.token)
150
+ # Set custom cache repo as environment variable
151
+ if custom_cache_repo:
152
+ os.environ['CUSTOM_CACHE_REPO'] = custom_cache_repo.strip()
153
+
154
+ yield log(f"🔑 Logging in ...")
155
+ try:
156
+ api.model_info(model_id, token=oauth_token.token)
157
+ except Exception as e:
158
+ yield log(f"❌ Could not access model `{model_id}`: {e}")
159
+ return
160
+
161
+ yield log(f"✅ Model `{model_id}` is accessible. Starting Neuron export...")
162
+
163
+ # UPDATED: Build pr_options with new structure
164
+ pr_options = {
165
+ "create_neuron_repo": DEST_NEW_NEURON_REPO in pr_destinations,
166
+ "create_cache_pr": DEST_CACHE_REPO in pr_destinations,
167
+ "create_custom_pr": DEST_CUSTOM_REPO in pr_destinations,
168
+ "custom_repo_id": custom_repo_id.strip() if custom_repo_id else ""
169
+ }
170
+
171
+ # The convert function is a generator, so we iterate through its messages
172
+ for status_code, message in convert(api, model_id, task_or_pipeline, model_type,
173
+ token=oauth_token.token, pr_options=pr_options):
174
+ if isinstance(message, str):
175
+ yield log(message)
176
+ else: # It's the final result dictionary
177
+ final_message = "🎉 Process finished.\n"
178
+ if message.get("neuron_repo"):
179
+ final_message += f"🏗️ New Neuron Repository: {message['neuron_repo']}\n"
180
+ if message.get("readme_pr"):
181
+ final_message += f"📝 README PR (Original Model): {message['readme_pr']}\n"
182
+ if message.get("cache_pr"):
183
+ final_message += f"🔗 Cache PR: {message['cache_pr']}\n"
184
+ if message.get("custom_pr"):
185
+ final_message += f"🔗 Custom PR: {message['custom_pr']}\n"
186
+ yield log(final_message)
187
+
188
+ except Exception as e:
189
+ yield log(f"❗ An unexpected error occurred in the Gradio interface: {e}")
190
+
191
+ TITLE_IMAGE = """
192
+ <div style="display: block; margin-left: auto; margin-right: auto; width: 50%;">
193
+ <img src="https://huggingface.co/spaces/optimum/neuron-export/resolve/main/huggingfaceXneuron.png"/>
194
+ </div>
195
+ """
196
+
197
+ TITLE = """
198
+ <div style="text-align: center; max-width: 1400px; margin: 0 auto;">
199
+ <h1 style="font-weight: 900; margin-bottom: 10px; margin-top: 10px; font-size: 2.2rem;">
200
+ 🤗 Optimum Neuron Model Exporter 🏎️
201
+ </h1>
202
+ </div>
203
+ """
204
+
205
+ # UPDATED: Description to reflect new workflow
206
+ DESCRIPTION = """
207
+ This Space allows you to automatically export 🤗 transformers and 🧨 diffusion models to AWS Neuron-optimized format for Inferentia/Trainium acceleration.
208
+
209
+ Simply provide a model ID from the Hugging Face Hub, and choose your desired output.
210
+
211
+ ### ✨ Key Features
212
+
213
+ * **🚀 Create a New Optimized Repo**: Automatically converts your model and uploads it to a new repository under your username (e.g., `your-username/model-name-neuron`).
214
+ * **🔗 Link Back to Original**: Creates a Pull Request on the original model’s repository to add a link to your optimized version, making it easier for the community to discover.
215
+ * **🛠️ PR to a Custom Repo**: For custom workflows, you can create a Pull Request to add the optimized files directly into an existing repository you own.
216
+ * **📦 Contribute to Cache**: Contribute the generated compilation artifacts to a centralized cache repository (or your own private cache), helping avoid recompilation of already exported models.
217
+
218
+ ### ⚙️ How to Use
219
+ 1. **Model ID**: Enter the ID of the model you want to export (e.g., `bert-base-uncased` or `stabilityai/stable-diffusion-xl-base-1.0`) and choose the corresponding task.
220
+ 2. **Export Options**: Select at least one option for where to save the exported model. You can provide your own cache repo ID or use the default (`aws-neuron/optimum-neuron-cache`).
221
+ 3. **Convert & Upload**: Click the button and follow the logs to track progress!
222
+
223
+ """
224
+
225
+ CUSTOM_CSS = """
226
+ /* Primary button styling with warm colors */
227
+ button.gradio-button.lg.primary {
228
+ /* Changed the blue/green gradient to an orange/yellow one */
229
+ background: linear-gradient(135deg, #F97316, #FBBF24) !important;
230
+ color: white !important;
231
+ padding: 16px 32px !important;
232
+ font-size: 1.1rem !important;
233
+ font-weight: 700 !important;
234
+ border: none !important;
235
+ border-radius: 12px !important;
236
+ /* Updated the shadow to match the new orange color */
237
+ box-shadow: 0 0 15px rgba(249, 115, 22, 0.5) !important;
238
+ transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1) !important;
239
+ position: relative;
240
+ overflow: hidden;
241
+ }
242
+ /* Login button styling with glow effect using dark blue and violet colors */
243
+ #login-button {
244
+ background: linear-gradient(135deg, #1a237e, #6a1b9a) !important; /* Dark Blue to Violet */
245
+ color: white !important;
246
+ font-weight: 700 !important;
247
+ border: none !important;
248
+ border-radius: 12px !important;
249
+ box-shadow: 0 0 15px rgba(106, 27, 154, 0.6) !important; /* Cool violet glow */
250
+ transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1) !important;
251
+ position: relative;
252
+ overflow: hidden;
253
+ animation: glow 1.5s ease-in-out infinite alternate;
254
+ max-width: 350px !important;
255
+ margin: 0 auto !important;
256
+ }
257
+ #login-button::before {
258
+ content: "🔑 ";
259
+ display: inline-block !important;
260
+ vertical-align: middle !important;
261
+ margin-right: 5px !important;
262
+ line-height: normal !important;
263
+ }
264
+ #login-button:hover {
265
+ transform: translateY(-3px) scale(1.03) !important;
266
+ box-shadow: 0 10px 25px rgba(26, 35, 126, 0.7) !important; /* Deeper blue glow */
267
+ }
268
+ #login-button::after {
269
+ content: "";
270
+ position: absolute;
271
+ top: 0;
272
+ left: -100%;
273
+ width: 100%;
274
+ height: 100%;
275
+ background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.25), transparent);
276
+ transition: 0.5s;
277
+ }
278
+ #login-button:hover::after {
279
+ left: 100%;
280
+ }
281
+
282
+ """
283
+
284
+ with gr.Blocks(css=CUSTOM_CSS, theme=gr.themes.Soft()) as demo:
285
+ gr.Markdown("**You must be logged in to use this space**")
286
+ gr.LoginButton(elem_id="login-button", elem_classes="center-button", min_width=250)
287
+ gr.HTML(TITLE_IMAGE)
288
+ gr.HTML(TITLE)
289
+ gr.Markdown(DESCRIPTION)
290
+
291
+ with gr.Tabs():
292
+ with gr.Tab("Export Model"):
293
+ with gr.Group():
294
+ with gr.Row():
295
+ pr_destinations_checkbox = gr.CheckboxGroup(
296
+ choices=PR_DESTINATION_CHOICES,
297
+ label="Export Destination",
298
+ value=[DEST_NEW_NEURON_REPO],
299
+ info="Select one or more destinations for the compiled model."
300
+ )
301
+ custom_repo_id_textbox = gr.Textbox(
302
+ label="Custom Repository ID",
303
+ placeholder="e.g., your-username/your-repo-name",
304
+ visible=False,
305
+ interactive=True
306
+ )
307
+ custom_cache_repo_textbox = gr.Textbox(
308
+ label="Custom Cache Repository",
309
+ placeholder="e.g., your-org/your-cache-repo",
310
+ value=DEFAULT_CACHE_REPO,
311
+ info=f"Repository to store and fetch from compilation cache artifacts (default: {DEFAULT_CACHE_REPO}) ",
312
+ interactive=True
313
+ )
314
+ with gr.Row():
315
+ model_type = gr.Radio(
316
+ choices=["transformers", "diffusers"],
317
+ value="transformers",
318
+ label="Model Type",
319
+ info="Choose the type of model you want to export"
320
+ )
321
+ with gr.Row():
322
+ input_model = HuggingfaceHubSearch(
323
+ label="Hub model ID",
324
+ placeholder="Search for a model on the Hub...",
325
+ search_type="model",
326
+ )
327
+ task_dropdown = gr.Dropdown(
328
+ choices=ALL_TRANSFORMER_TASKS,
329
+ value="auto",
330
+ label="Task (auto can infer from model)",
331
+ )
332
+
333
+ btn = gr.Button("Export to Neuron", size="lg", variant="primary")
334
+
335
+ log_box = gr.Textbox(label="Logs", lines=20, interactive=False, show_copy_button=True)
336
+
337
+ # Event Handlers
338
+ model_type.change(
339
+ fn=update_task_dropdown,
340
+ inputs=[model_type],
341
+ outputs=[task_dropdown]
342
+ )
343
+
344
+ pr_destinations_checkbox.change(
345
+ fn=toggle_custom_repo_box,
346
+ inputs=pr_destinations_checkbox,
347
+ outputs=custom_repo_id_textbox
348
+ )
349
+
350
+ btn.click(
351
+ fn=neuron_export,
352
+ inputs=[
353
+ input_model,
354
+ model_type,
355
+ task_dropdown,
356
+ pr_destinations_checkbox,
357
+ custom_repo_id_textbox,
358
+ custom_cache_repo_textbox
359
+ ],
360
+ outputs=log_box,
361
+ )
362
+
363
+ with gr.Tab("Supported Architectures"):
364
+ gr.HTML(f"""
365
+ <div style="margin-bottom: 20px;">
366
+ <h3>🎨 Task Categories Legend</h3>
367
+ <div class="task-tags">
368
+ {create_task_tag("Feature Extraction")}
369
+ {create_task_tag("NLP")}
370
+ {create_task_tag("Text Generation")}
371
+ {create_task_tag("Audio")}
372
+ {create_task_tag("Vision")}
373
+ {create_task_tag("Multimodal")}
374
+ {create_task_tag("Similarity")}
375
+ </div>
376
+ </div>
377
+ """)
378
+
379
+ gr.HTML(f"""
380
+ <h2>🤗 Transformers</h2>
381
+ <table style="width: 100%; border-collapse: collapse; margin: 20px 0;">
382
+ <colgroup>
383
+ <col style="width: 30%;">
384
+ <col style="width: 70%;">
385
+ </colgroup>
386
+ <thead>
387
+ <tr style="background-color: var(--background-fill-secondary);">
388
+ <th style="border: 1px solid var(--border-color-primary); padding: 12px; text-align: left;">Architecture</th>
389
+ <th style="border: 1px solid var(--border-color-primary); padding: 12px; text-align: left;">Supported Tasks</th>
390
+ </tr>
391
+ </thead>
392
+ <tbody>
393
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">ALBERT</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("feature-extraction, fill-mask, multiple-choice, question-answering, text-classification, token-classification")}</td></tr>
394
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">AST</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("feature-extraction, audio-classification")}</td></tr>
395
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">BERT</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("feature-extraction, fill-mask, multiple-choice, question-answering, text-classification, token-classification")}</td></tr>
396
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">BLOOM</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("text-generation")}</td></tr>
397
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">Beit</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("feature-extraction, image-classification")}</td></tr>
398
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">CamemBERT</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("feature-extraction, fill-mask, multiple-choice, question-answering, text-classification, token-classification")}</td></tr>
399
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">CLIP</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("feature-extraction, image-classification")}</td></tr>
400
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">ConvBERT</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("feature-extraction, fill-mask, multiple-choice, question-answering, text-classification, token-classification")}</td></tr>
401
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">ConvNext</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("feature-extraction, image-classification")}</td></tr>
402
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">ConvNextV2</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("feature-extraction, image-classification")}</td></tr>
403
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">CvT</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("feature-extraction, image-classification")}</td></tr>
404
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">DeBERTa (INF2 only)</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("feature-extraction, fill-mask, multiple-choice, question-answering, text-classification, token-classification")}</td></tr>
405
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">DeBERTa-v2 (INF2 only)</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("feature-extraction, fill-mask, multiple-choice, question-answering, text-classification, token-classification")}</td></tr>
406
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">Deit</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("feature-extraction, image-classification")}</td></tr>
407
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">DistilBERT</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("feature-extraction, fill-mask, multiple-choice, question-answering, text-classification, token-classification")}</td></tr>
408
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">DonutSwin</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("feature-extraction")}</td></tr>
409
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">Dpt</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("feature-extraction")}</td></tr>
410
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">ELECTRA</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("feature-extraction, fill-mask, multiple-choice, question-answering, text-classification, token-classification")}</td></tr>
411
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">ESM</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("feature-extraction, fill-mask, text-classification, token-classification")}</td></tr>
412
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">FlauBERT</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("feature-extraction, fill-mask, multiple-choice, question-answering, text-classification, token-classification")}</td></tr>
413
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">GPT2</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("text-generation")}</td></tr>
414
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">Hubert</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("feature-extraction, automatic-speech-recognition, audio-classification")}</td></tr>
415
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">Levit</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("feature-extraction, image-classification")}</td></tr>
416
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">Llama, Llama 2, Llama 3</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("text-generation")}</td></tr>
417
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">Mistral</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("text-generation")}</td></tr>
418
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">Mixtral</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("text-generation")}</td></tr>
419
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">MobileBERT</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("feature-extraction, fill-mask, multiple-choice, question-answering, text-classification, token-classification")}</td></tr>
420
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">MobileNetV2</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("feature-extraction, image-classification, semantic-segmentation")}</td></tr>
421
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">MobileViT</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("feature-extraction, image-classification, semantic-segmentation")}</td></tr>
422
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">ModernBERT</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("feature-extraction, fill-mask, text-classification, token-classification")}</td></tr>
423
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">MPNet</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("feature-extraction, fill-mask, multiple-choice, question-answering, text-classification, token-classification")}</td></tr>
424
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">OPT</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("text-generation")}</td></tr>
425
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">Phi</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("feature-extraction, text-classification, token-classification")}</td></tr>
426
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">RoBERTa</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("feature-extraction, fill-mask, multiple-choice, question-answering, text-classification, token-classification")}</td></tr>
427
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">RoFormer</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("feature-extraction, fill-mask, multiple-choice, question-answering, text-classification, token-classification")}</td></tr>
428
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">Swin</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("feature-extraction, image-classification")}</td></tr>
429
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">T5</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("text2text-generation")}</td></tr>
430
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">UniSpeech</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("feature-extraction, automatic-speech-recognition, audio-classification")}</td></tr>
431
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">UniSpeech-SAT</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("feature-extraction, automatic-speech-recognition, audio-classification, audio-frame-classification, audio-xvector")}</td></tr>
432
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">ViT</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("feature-extraction, image-classification")}</td></tr>
433
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">Wav2Vec2</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("feature-extraction, automatic-speech-recognition, audio-classification, audio-frame-classification, audio-xvector")}</td></tr>
434
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">WavLM</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("feature-extraction, automatic-speech-recognition, audio-classification, audio-frame-classification, audio-xvector")}</td></tr>
435
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">Whisper</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("automatic-speech-recognition")}</td></tr>
436
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">XLM</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("feature-extraction, fill-mask, multiple-choice, question-answering, text-classification, token-classification")}</td></tr>
437
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">XLM-RoBERTa</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("feature-extraction, fill-mask, multiple-choice, question-answering, text-classification, token-classification")}</td></tr>
438
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">Yolos</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("feature-extraction, object-detection")}</td></tr>
439
+ </tbody>
440
+ </table>
441
+ <h2>🧨 Diffusers</h2>
442
+ <table style="width: 100%; border-collapse: collapse; margin: 20px 0;">
443
+ <colgroup>
444
+ <col style="width: 30%;">
445
+ <col style="width: 70%;">
446
+ </colgroup>
447
+ <thead>
448
+ <tr style="background-color: var(--background-fill-secondary);">
449
+ <th style="border: 1px solid var(--border-color-primary); padding: 12px; text-align: left;">Architecture</th>
450
+ <th style="border: 1px solid var(--border-color-primary); padding: 12px; text-align: left;">Supported Tasks</th>
451
+ </tr>
452
+ </thead>
453
+ <tbody>
454
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">Stable Diffusion</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("text-to-image, image-to-image, inpaint")}</td></tr>
455
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">Stable Diffusion XL Base</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("text-to-image, image-to-image, inpaint")}</td></tr>
456
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">Stable Diffusion XL Refiner</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("image-to-image, inpaint")}</td></tr>
457
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">SDXL Turbo</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("text-to-image, image-to-image, inpaint")}</td></tr>
458
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">LCM</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("text-to-image")}</td></tr>
459
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">PixArt-α</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("text-to-image")}</td></tr>
460
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">PixArt-Σ</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("text-to-image")}</td></tr>
461
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">Flux</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("text-to-image")}</td></tr>
462
+
463
+ </tbody>
464
+ </table>
465
+ <h2>🤖 Sentence Transformers</h2>
466
+ <table style="width: 100%; border-collapse: collapse; margin: 20px 0;">
467
+ <colgroup>
468
+ <col style="width: 30%;">
469
+ <col style="width: 70%;">
470
+ </colgroup>
471
+ <thead>
472
+ <tr style="background-color: var(--background-fill-secondary);">
473
+ <th style="border: 1px solid var(--border-color-primary); padding: 12px; text-align: left;">Architecture</th>
474
+ <th style="border: 1px solid var(--border-color-primary); padding: 12px; text-align: left;">Supported Tasks</th>
475
+ </tr>
476
+ </thead>
477
+ <tbody>
478
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">Transformer</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("feature-extraction, sentence-similarity")}</td></tr>
479
+ <tr><td style="border: 1px solid var(--border-color-primary); padding: 8px; font-weight: bold;">CLIP</td><td style="border: 1px solid var(--border-color-primary); padding: 8px;" class="task-tags">{format_tasks_for_table("feature-extraction, zero-shot-image-classification")}</td></tr>
480
+ </tbody>
481
+ </table>
482
+ <div style="margin-top: 20px;">
483
+ <p>💡 <strong>Note</strong>: Some architectures may have specific requirements or limitations. DeBERTa models are only supported on INF2 instances.</p>
484
+ <p>For more details, check the <a href="https://huggingface.co/docs/optimum-neuron" target="_blank">Optimum Neuron documentation</a>.</p>
485
+ </div>
486
+ """)
487
+
488
+ # Add spacing between tabs and content
489
+ gr.Markdown("<br><br><br><br>")
490
+
491
+ if __name__ == "__main__":
492
+ demo.launch(debug=True)