mgbam commited on
Commit
757c773
Β·
verified Β·
1 Parent(s): d31fee7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +129 -170
app.py CHANGED
@@ -117,78 +117,27 @@ class AnyCoder:
117
  """Create the professional sidebar"""
118
 
119
  # Model Selection
120
- with gr.Group(elem_classes=["control-group"]):
121
- gr.HTML('<div class="group-title">πŸ€– AI Model</div>')
122
-
123
- model_dropdown = gr.Dropdown(
124
- choices=[f"{model['name']} ({model['category']})" for model in AVAILABLE_MODELS],
125
- value=f"{DEFAULT_MODEL['name']} ({DEFAULT_MODEL['category']})",
126
- label="Select Model",
127
- container=False
128
- )
 
 
 
 
 
 
 
 
129
 
 
130
  model_info = gr.HTML(self.get_model_info_html(DEFAULT_MODEL))
131
 
132
- # Web Search Toggle
133
- with gr.Group(elem_classes=["control-group"]):
134
- search_toggle = gr.Checkbox(
135
- label="πŸ” Web search",
136
- value=False,
137
- info="Enable real-time web search for enhanced results",
138
- container=False
139
- )
140
-
141
- # Media Generation Links
142
- with gr.Group(elem_classes=["control-group"]):
143
- gr.HTML('<div class="group-title">🎨 Media Generation</div>')
144
-
145
- with gr.Row():
146
- gr.HTML('<div class="media-option-text">πŸ–ΌοΈ Generate Images (text β†’ image)</div>')
147
- text_to_image_btn = gr.Button("Open", size="sm", variant="secondary", elem_classes=["media-link-btn"])
148
- gr.HTML('<div class="media-info">Include generated images in your outputs using Qwen image model</div>')
149
-
150
- with gr.Row():
151
- gr.HTML('<div class="media-option-text">πŸ–ΌοΈ Image to Image (uses input image)</div>')
152
- image_to_image_btn = gr.Button("Open", size="sm", variant="secondary", elem_classes=["media-link-btn"])
153
- gr.HTML('<div class="media-info">Transform your uploaded image using Qwen image/edit</div>')
154
-
155
- with gr.Row():
156
- gr.HTML('<div class="media-option-text">🎬 Image to Video (uses input image)</div>')
157
- image_to_video_btn = gr.Button("Open", size="sm", variant="secondary", elem_classes=["media-link-btn"])
158
- gr.HTML('<div class="media-info">Generate a short video from your uploaded image using Lightricks LTX-Video</div>')
159
-
160
- with gr.Row():
161
- gr.HTML('<div class="media-option-text">🎬 Generate Video (text β†’ video)</div>')
162
- text_to_video_btn = gr.Button("Open", size="sm", variant="secondary", elem_classes=["media-link-btn"])
163
- gr.HTML('<div class="media-info">Generate a short video directly from your prompt using WanAi/Wan2.2-TIZV-S8</div>')
164
-
165
- with gr.Row():
166
- gr.HTML('<div class="media-option-text">🎡 Generate Music (text β†’ music)</div>')
167
- text_to_music_btn = gr.Button("Open", size="sm", variant="secondary", elem_classes=["media-link-btn"])
168
- gr.HTML('<div class="media-info">Compose short music from your prompt using ElevenLabs Music</div>')
169
-
170
- # Model Information
171
- with gr.Group(elem_classes=["control-group"]):
172
- gr.HTML('<div class="group-title">Model</div>')
173
- model_display = gr.HTML(
174
- '<div class="model-name">Qwen3-Coder-4800-A535-Instruc</div>',
175
- elem_classes=["model-display"]
176
- )
177
-
178
- # Quick Start Examples
179
- with gr.Group(elem_classes=["control-group"]):
180
- gr.HTML('<div class="group-title">Quick Start</div>')
181
-
182
- quick_start_buttons = []
183
- for demo in DEMO_LIST[:6]:
184
- btn = gr.Button(
185
- demo["title"],
186
- variant="secondary",
187
- size="sm",
188
- elem_classes=["quick-start-btn"]
189
- )
190
- quick_start_buttons.append(btn)
191
-
192
  # Project Configuration
193
  with gr.Group(elem_classes=["control-group"]):
194
  gr.HTML('<div class="group-title">βš™οΈ Project Settings</div>')
@@ -210,12 +159,17 @@ class AnyCoder:
210
  container=False
211
  )
212
 
213
- advanced_mode = gr.Checkbox(
214
- label="Advanced Mode",
215
- value=False,
216
- info="Show advanced options",
217
- container=False
218
- )
 
 
 
 
 
219
 
220
  # Input Sources
221
  with gr.Group(elem_classes=["control-group"]):
@@ -235,17 +189,39 @@ class AnyCoder:
235
 
236
  image_input = gr.Image(
237
  label="Design Reference Image",
 
238
  container=False
239
  )
240
 
241
- # Advanced Controls (initially hidden)
242
  with gr.Group(elem_classes=["control-group"], visible=False) as advanced_controls:
243
- gr.HTML('<div class="group-title">πŸ”§ Advanced Options</div>')
 
 
 
 
 
244
 
245
  media_prompts = gr.Textbox(
246
  label="Media Generation Prompts",
247
  placeholder="Describe media to generate...",
248
  lines=2,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
249
  container=False
250
  )
251
 
@@ -260,14 +236,13 @@ class AnyCoder:
260
  )
261
 
262
  with gr.Row():
263
- import_btn = gr.Button("Import", variant="secondary", size="sm")
264
- import_status = gr.HTML("", visible=False)
265
 
266
  # Store sidebar components for event handling
267
  self.sidebar_components = {
268
  'model_dropdown': model_dropdown,
269
  'model_info': model_info,
270
- 'model_display': model_display,
271
  'language_dropdown': language_dropdown,
272
  'search_toggle': search_toggle,
273
  'advanced_mode': advanced_mode,
@@ -275,56 +250,33 @@ class AnyCoder:
275
  'website_url_input': website_url_input,
276
  'image_input': image_input,
277
  'advanced_controls': advanced_controls,
278
- 'text_to_image_btn': text_to_image_btn,
279
- 'image_to_image_btn': image_to_image_btn,
280
- 'image_to_video_btn': image_to_video_btn,
281
- 'text_to_video_btn': text_to_video_btn,
282
- 'text_to_music_btn': text_to_music_btn,
283
  'media_prompts': media_prompts,
284
- 'quick_start_buttons': quick_start_buttons,
285
  'import_url': import_url,
286
  'import_btn': import_btn,
287
  'import_status': import_status
288
  }
289
 
290
- # Setup sidebar event handlers
291
- self.setup_sidebar_events(session_state)
292
-
293
- def setup_sidebar_events(self, session_state):
294
- """Setup sidebar-specific event handlers"""
295
-
296
  # Show advanced controls when enabled
297
- self.sidebar_components['advanced_mode'].change(
298
  lambda checked: gr.update(visible=checked),
299
- inputs=[self.sidebar_components['advanced_mode']],
300
- outputs=[self.sidebar_components['advanced_controls']]
301
- )
302
-
303
- # Media generation buttons - redirect to Hugging Face Spaces
304
- self.sidebar_components['text_to_image_btn'].click(
305
- lambda: None,
306
- js="() => window.open('https://huggingface.co/spaces/evalstate/flux1_schnell', '_blank')"
307
  )
308
 
309
- self.sidebar_components['image_to_image_btn'].click(
310
- lambda: None,
311
- js="() => window.open('https://huggingface.co/spaces/abidlabs/EasyGhibli', '_blank')"
312
- )
313
-
314
- self.sidebar_components['image_to_video_btn'].click(
315
- lambda: None,
316
- js="() => window.open('https://huggingface.co/spaces/multimodalart/wan2-1-fast', '_blank')"
317
- )
318
-
319
- self.sidebar_components['text_to_video_btn'].click(
320
- lambda: None,
321
- js="() => window.open('https://huggingface.co/spaces/WanAi/Wan2.2-TIZV-S8', '_blank')"
322
- )
323
-
324
- self.sidebar_components['text_to_music_btn'].click(
325
- lambda: None,
326
- js="() => window.open('https://huggingface.co/spaces/ElevenLabs/ElevenLabs-Music', '_blank')"
327
- )
328
 
329
  def create_main_content(self, history, current_model):
330
  """Create the main content area"""
@@ -341,14 +293,14 @@ class AnyCoder:
341
 
342
  with gr.Row():
343
  generate_btn = gr.Button(
344
- "Generate",
345
  variant="primary",
346
  scale=3,
347
  size="lg",
348
  elem_classes=["generate-btn"]
349
  )
350
  clear_btn = gr.Button(
351
- "Clear",
352
  variant="secondary",
353
  scale=1,
354
  size="lg"
@@ -358,7 +310,7 @@ class AnyCoder:
358
  with gr.Tabs(elem_classes=["output-tabs"]):
359
 
360
  # Preview Tab
361
- with gr.Tab("Preview", elem_classes=["preview-tab"]):
362
  with gr.Group():
363
  preview_controls = gr.HTML("""
364
  <div class="preview-controls">
@@ -376,7 +328,7 @@ class AnyCoder:
376
  )
377
 
378
  # Code Tab
379
- with gr.Tab("Code", elem_classes=["code-tab"]):
380
  with gr.Row():
381
  with gr.Column(scale=4):
382
  code_output = gr.Code(
@@ -405,7 +357,7 @@ class AnyCoder:
405
  )
406
 
407
  # Deployment Tab
408
- with gr.Tab("Deploy", elem_classes=["deploy-tab"]):
409
  with gr.Row():
410
  with gr.Column(scale=2):
411
  with gr.Group():
@@ -509,13 +461,12 @@ class AnyCoder:
509
  ]
510
  )
511
 
512
- # Quick start button handlers
513
- for i, btn in enumerate(self.sidebar_components['quick_start_buttons']):
514
- if i < len(DEMO_LIST):
515
- btn.click(
516
- lambda demo_idx=i: DEMO_LIST[demo_idx]['description'],
517
- outputs=[self.main_components['input_textbox']]
518
- )
519
 
520
  def handle_generation(self, prompt, file, website_url, image, language,
521
  enable_search, current_model_state, history_state, session_state):
@@ -559,6 +510,21 @@ class AnyCoder:
559
  # Process the generated code
560
  processed_code = remove_code_block(generated_code)
561
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
562
  # Generate preview
563
  preview_html = self.generate_preview(processed_code, language)
564
 
@@ -822,6 +788,15 @@ class AnyCoder:
822
  [] # history
823
  )
824
 
 
 
 
 
 
 
 
 
 
825
  def get_model_info_html(self, model):
826
  """Generate HTML for model information"""
827
  vision_badge = '<span class="feature-badge vision">πŸ‘οΈ Vision</span>' if model.get('supports_vision') else ''
@@ -938,7 +913,7 @@ class AnyCoder:
938
  }
939
 
940
  .control-group {
941
- margin-bottom: 16px;
942
  background: white;
943
  padding: 16px;
944
  border-radius: 8px;
@@ -955,43 +930,6 @@ class AnyCoder:
955
  gap: 8px;
956
  }
957
 
958
- .model-display {
959
- background: #f3f4f6;
960
- padding: 8px 12px;
961
- border-radius: 6px;
962
- border: 1px solid #d1d5db;
963
- }
964
-
965
- .model-display .model-name {
966
- font-family: 'Monaco', 'Consolas', monospace;
967
- font-size: 0.85rem;
968
- color: #374151;
969
- }
970
-
971
- .quick-start-btn {
972
- width: 100%;
973
- margin-bottom: 4px;
974
- text-align: left;
975
- justify-content: flex-start;
976
- }
977
-
978
- .media-option-text {
979
- font-weight: 500;
980
- color: #374151;
981
- flex: 1;
982
- }
983
-
984
- .media-link-btn {
985
- min-width: 60px;
986
- }
987
-
988
- .media-info {
989
- font-size: 0.8rem;
990
- color: #6b7280;
991
- margin-bottom: 12px;
992
- padding-left: 4px;
993
- }
994
-
995
  .input-group {
996
  background: white;
997
  padding: 24px;
@@ -1131,6 +1069,11 @@ class AnyCoder:
1131
  color: #92400e;
1132
  }
1133
 
 
 
 
 
 
1134
  .preview-message {
1135
  text-align: center;
1136
  padding: 40px 20px;
@@ -1158,6 +1101,22 @@ class AnyCoder:
1158
  color: #6b7280;
1159
  }
1160
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1161
  /* Responsive design */
1162
  @media (max-width: 768px) {
1163
  .header-content {
 
117
  """Create the professional sidebar"""
118
 
119
  # Model Selection
120
+ # Quick Examples
121
+ with gr.Group(elem_classes=["control-group"]):
122
+ gr.HTML('<div class="group-title">πŸš€ Quick Start</div>')
123
+
124
+ example_gallery = gr.Gallery(
125
+ value=[
126
+ (demo.get("image", None), demo["title"]) for demo in DEMO_LIST[:6]
127
+ ],
128
+ label="Example Projects",
129
+ show_label=False,
130
+ elem_classes=["example-gallery"],
131
+ columns=2,
132
+ rows=3,
133
+ height="auto",
134
+ container=False
135
+ )
136
+
137
 
138
+ # Model info display
139
  model_info = gr.HTML(self.get_model_info_html(DEFAULT_MODEL))
140
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  # Project Configuration
142
  with gr.Group(elem_classes=["control-group"]):
143
  gr.HTML('<div class="group-title">βš™οΈ Project Settings</div>')
 
159
  container=False
160
  )
161
 
162
+ with gr.Row():
163
+ search_toggle = gr.Checkbox(
164
+ label="Web Search",
165
+ value=False,
166
+ info="Enable real-time web search"
167
+ )
168
+ advanced_mode = gr.Checkbox(
169
+ label="Advanced Mode",
170
+ value=False,
171
+ info="Show advanced options"
172
+ )
173
 
174
  # Input Sources
175
  with gr.Group(elem_classes=["control-group"]):
 
189
 
190
  image_input = gr.Image(
191
  label="Design Reference Image",
192
+ visible=False,
193
  container=False
194
  )
195
 
196
+ # Media Generation Controls
197
  with gr.Group(elem_classes=["control-group"], visible=False) as advanced_controls:
198
+ gr.HTML('<div class="group-title">🎨 Media Generation</div>')
199
+
200
+ with gr.Row():
201
+ enable_images = gr.Checkbox(label="Images", value=False, scale=1)
202
+ enable_videos = gr.Checkbox(label="Videos", value=False, scale=1)
203
+ enable_music = gr.Checkbox(label="Music", value=False, scale=1)
204
 
205
  media_prompts = gr.Textbox(
206
  label="Media Generation Prompts",
207
  placeholder="Describe media to generate...",
208
  lines=2,
209
+ visible=False,
210
+ container=False
211
+ )
212
+
213
+ # Quick Examples
214
+ with gr.Group(elem_classes=["control-group"]):
215
+ gr.HTML('<div class="group-title">πŸš€ Quick Start</div>')
216
+
217
+ example_gallery = gr.Gallery(
218
+ value=[demo["title"] for demo in DEMO_LIST[:6]], # text only, no NoneType
219
+ label="Example Projects",
220
+ show_label=False,
221
+ elem_classes=["example-gallery"],
222
+ columns=2,
223
+ rows=3,
224
+ height="auto",
225
  container=False
226
  )
227
 
 
236
  )
237
 
238
  with gr.Row():
239
+ import_btn = gr.Button("Import", variant="secondary", scale=1)
240
+ import_status = gr.HTML("", visible=False) # fixed, no invalid scale arg
241
 
242
  # Store sidebar components for event handling
243
  self.sidebar_components = {
244
  'model_dropdown': model_dropdown,
245
  'model_info': model_info,
 
246
  'language_dropdown': language_dropdown,
247
  'search_toggle': search_toggle,
248
  'advanced_mode': advanced_mode,
 
250
  'website_url_input': website_url_input,
251
  'image_input': image_input,
252
  'advanced_controls': advanced_controls,
253
+ 'enable_images': enable_images,
254
+ 'enable_videos': enable_videos,
255
+ 'enable_music': enable_music,
 
 
256
  'media_prompts': media_prompts,
257
+ 'example_gallery': example_gallery,
258
  'import_url': import_url,
259
  'import_btn': import_btn,
260
  'import_status': import_status
261
  }
262
 
 
 
 
 
 
 
263
  # Show advanced controls when enabled
264
+ advanced_mode.change(
265
  lambda checked: gr.update(visible=checked),
266
+ inputs=[advanced_mode],
267
+ outputs=[advanced_controls]
 
 
 
 
 
 
268
  )
269
 
270
+ # Show media prompts when any media generation is enabled
271
+ for checkbox in [enable_images, enable_videos, enable_music]:
272
+ checkbox.change(
273
+ lambda *args: gr.update(visible=any(args)),
274
+ inputs=[enable_images, enable_videos, enable_music],
275
+ outputs=[media_prompts]
276
+ )
277
+
278
+ # rest of the class and main() remain unchanged
279
+
 
 
 
 
 
 
 
 
 
280
 
281
  def create_main_content(self, history, current_model):
282
  """Create the main content area"""
 
293
 
294
  with gr.Row():
295
  generate_btn = gr.Button(
296
+ "πŸš€ Generate Application",
297
  variant="primary",
298
  scale=3,
299
  size="lg",
300
  elem_classes=["generate-btn"]
301
  )
302
  clear_btn = gr.Button(
303
+ "πŸ—‘οΈ Clear",
304
  variant="secondary",
305
  scale=1,
306
  size="lg"
 
310
  with gr.Tabs(elem_classes=["output-tabs"]):
311
 
312
  # Preview Tab
313
+ with gr.Tab("πŸ–₯️ Live Preview", elem_classes=["preview-tab"]):
314
  with gr.Group():
315
  preview_controls = gr.HTML("""
316
  <div class="preview-controls">
 
328
  )
329
 
330
  # Code Tab
331
+ with gr.Tab("πŸ’» Source Code", elem_classes=["code-tab"]):
332
  with gr.Row():
333
  with gr.Column(scale=4):
334
  code_output = gr.Code(
 
357
  )
358
 
359
  # Deployment Tab
360
+ with gr.Tab("πŸš€ Deploy", elem_classes=["deploy-tab"]):
361
  with gr.Row():
362
  with gr.Column(scale=2):
363
  with gr.Group():
 
461
  ]
462
  )
463
 
464
+ # Example selection handler
465
+ self.sidebar_components['example_gallery'].select(
466
+ self.handle_example_select,
467
+ inputs=[self.sidebar_components['example_gallery']],
468
+ outputs=[self.main_components['input_textbox']]
469
+ )
 
470
 
471
  def handle_generation(self, prompt, file, website_url, image, language,
472
  enable_search, current_model_state, history_state, session_state):
 
510
  # Process the generated code
511
  processed_code = remove_code_block(generated_code)
512
 
513
+ # Apply media generation if enabled
514
+ if any([
515
+ session_state.get('enable_images', False),
516
+ session_state.get('enable_videos', False),
517
+ session_state.get('enable_music', False)
518
+ ]):
519
+ processed_code = apply_generated_media_to_html(
520
+ processed_code,
521
+ prompt,
522
+ enable_text_to_image=session_state.get('enable_images', False),
523
+ enable_text_to_video=session_state.get('enable_videos', False),
524
+ enable_text_to_music=session_state.get('enable_music', False),
525
+ session_id=session_id
526
+ )
527
+
528
  # Generate preview
529
  preview_html = self.generate_preview(processed_code, language)
530
 
 
788
  [] # history
789
  )
790
 
791
+ def handle_example_select(self, evt: gr.SelectData):
792
+ """Handle example selection from gallery"""
793
+ try:
794
+ if evt.index is not None and evt.index < len(DEMO_LIST):
795
+ return DEMO_LIST[evt.index]['description']
796
+ return ""
797
+ except Exception:
798
+ return ""
799
+
800
  def get_model_info_html(self, model):
801
  """Generate HTML for model information"""
802
  vision_badge = '<span class="feature-badge vision">πŸ‘οΈ Vision</span>' if model.get('supports_vision') else ''
 
913
  }
914
 
915
  .control-group {
916
+ margin-bottom: 24px;
917
  background: white;
918
  padding: 16px;
919
  border-radius: 8px;
 
930
  gap: 8px;
931
  }
932
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
933
  .input-group {
934
  background: white;
935
  padding: 24px;
 
1069
  color: #92400e;
1070
  }
1071
 
1072
+ .example-gallery {
1073
+ border-radius: 8px;
1074
+ border: 1px solid #e5e7eb;
1075
+ }
1076
+
1077
  .preview-message {
1078
  text-align: center;
1079
  padding: 40px 20px;
 
1101
  color: #6b7280;
1102
  }
1103
 
1104
+ /* Dark mode adjustments */
1105
+ .dark .sidebar {
1106
+ background: #1f2937;
1107
+ border-color: #374151;
1108
+ }
1109
+
1110
+ .dark .control-group {
1111
+ background: #111827;
1112
+ border-color: #374151;
1113
+ }
1114
+
1115
+ .dark .input-group {
1116
+ background: #111827;
1117
+ border-color: #374151;
1118
+ }
1119
+
1120
  /* Responsive design */
1121
  @media (max-width: 768px) {
1122
  .header-content {