lastwarning commited on
Commit
12bee5e
·
verified ·
1 Parent(s): ea34782

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +213 -479
app.py CHANGED
@@ -4,10 +4,10 @@ import gc
4
  import random
5
  import threading
6
  import traceback
 
7
 
8
  # ==========================================
9
  # ENVIRONMENT
10
- # IMPORTANT: spaces before torch
11
  # ==========================================
12
 
13
  os.environ["HF_HUB_DISABLE_IMPLICIT_TOKEN"] = "1"
@@ -18,7 +18,7 @@ import spaces
18
  import gradio as gr
19
  import torch
20
 
21
- from PIL import Image, ImageOps
22
 
23
  from diffusers import (
24
  DiffusionPipeline,
@@ -37,27 +37,23 @@ from threading import Thread, Event
37
 
38
 
39
  # ==========================================
40
- # APP CONFIGURATION
41
  # ==========================================
42
 
43
  APP_NAME = "Tasting AI Studio"
44
-
45
  APP_VERSION = "2.0 Premium"
46
 
47
- DEVICE = "cuda"
48
-
49
  IMAGE_DTYPE = torch.float16
50
 
51
  MAX_INPUT_LENGTH = 4096
52
-
53
  MAX_HISTORY_MESSAGES = 10
54
 
 
55
  # ==========================================
56
  # TEXT TO IMAGE MODELS
57
  # ==========================================
58
 
59
  IMAGE_MODELS = {
60
-
61
  "SDXL Turbo": {
62
  "id": "stabilityai/sdxl-turbo",
63
  "steps": 4,
@@ -93,10 +89,8 @@ IMAGE_MODELS = {
93
  # ==========================================
94
 
95
  IMAGE_TO_IMAGE_MODELS = {
96
-
97
  "Stable Diffusion 1.5 Img2Img":
98
  "stable-diffusion-v1-5/stable-diffusion-v1-5",
99
-
100
  }
101
 
102
 
@@ -105,8 +99,7 @@ IMAGE_TO_IMAGE_MODELS = {
105
  # ==========================================
106
 
107
  CODE_MODELS = {
108
-
109
- # ORIGINAL MODELS
110
 
111
  "Qwen Coder 0.5B":
112
  "Qwen/Qwen2.5-Coder-0.5B-Instruct",
@@ -117,7 +110,7 @@ CODE_MODELS = {
117
  "DeepSeek Coder 1.3B":
118
  "deepseek-ai/deepseek-coder-1.3b-instruct",
119
 
120
- # ADDITIONAL MODELS
121
 
122
  "Qwen Coder 3B":
123
  "Qwen/Qwen2.5-Coder-3B-Instruct",
@@ -127,12 +120,11 @@ CODE_MODELS = {
127
 
128
  "CodeGen 350M":
129
  "Salesforce/codegen-350M-mono",
130
-
131
  }
132
 
133
 
134
  # ==========================================
135
- # MODEL CACHES
136
  # ==========================================
137
 
138
  image_cache = {
@@ -148,55 +140,49 @@ code_cache = {
148
  }
149
 
150
  image_lock = threading.RLock()
151
-
152
  code_lock = threading.RLock()
153
 
154
  generation_events = {}
155
-
156
  generation_events_lock = threading.Lock()
157
 
158
 
159
  # ==========================================
160
- # MEMORY MANAGEMENT
161
  # ==========================================
162
 
163
  def clear_image_cache():
164
 
165
- with image_lock:
166
-
167
- old_pipe = image_cache.get("pipe")
168
 
169
- image_cache["pipe"] = None
170
- image_cache["name"] = None
171
- image_cache["mode"] = None
172
 
173
- if old_pipe is not None:
174
- del old_pipe
175
 
176
- gc.collect()
177
 
178
- if torch.cuda.is_available():
179
- torch.cuda.empty_cache()
180
 
181
 
182
  def clear_code_cache():
183
 
184
- with code_lock:
185
-
186
- old_model = code_cache.get("model")
187
- old_tokenizer = code_cache.get("tokenizer")
188
 
189
- code_cache["model"] = None
190
- code_cache["tokenizer"] = None
191
- code_cache["name"] = None
192
 
193
- if old_model is not None:
194
- del old_model
195
 
196
- if old_tokenizer is not None:
197
- del old_tokenizer
198
 
199
- gc.collect()
200
 
201
 
202
  # ==========================================
@@ -213,7 +199,6 @@ def load_image_pipeline(model_id, mode):
213
  image_cache["name"] == cache_key
214
  and image_cache["pipe"] is not None
215
  ):
216
-
217
  return image_cache["pipe"]
218
 
219
  clear_image_cache()
@@ -224,8 +209,6 @@ def load_image_pipeline(model_id, mode):
224
  model_id,
225
  torch_dtype=IMAGE_DTYPE,
226
  token=False,
227
- safety_checker=None,
228
- requires_safety_checker=False,
229
  )
230
 
231
  elif mode == "image":
@@ -237,12 +220,10 @@ def load_image_pipeline(model_id, mode):
237
  )
238
 
239
  else:
 
240
 
241
- raise ValueError("Unsupported image generation mode.")
242
 
243
- pipe = pipe.to(DEVICE)
244
-
245
- # Optional memory optimization.
246
  if hasattr(pipe, "enable_attention_slicing"):
247
  pipe.enable_attention_slicing()
248
 
@@ -270,27 +251,20 @@ def generate_image(
270
  ):
271
 
272
  if not prompt or not prompt.strip():
273
-
274
  raise gr.Error("Please enter an image prompt.")
275
 
276
  if model_name not in IMAGE_MODELS:
277
-
278
  raise gr.Error("Invalid image model.")
279
 
280
- config = IMAGE_MODELS[model_name]
281
-
282
  if random_seed:
283
  seed = random.randint(0, 2147483647)
284
 
285
  seed = int(seed)
286
 
287
- width = int(width)
288
- height = int(height)
289
-
290
- # Avoid unsupported dimensions.
291
 
292
- width = max(256, min(width, 768))
293
- height = max(256, min(height, 768))
294
 
295
  width = (width // 8) * 8
296
  height = (height // 8) * 8
@@ -301,44 +275,39 @@ def generate_image(
301
  )
302
 
303
  if model_name in ["SDXL Turbo", "SD Turbo"]:
304
-
305
  actual_steps = min(actual_steps, 4)
306
 
307
- else:
308
-
309
- actual_steps = max(actual_steps, 1)
310
-
311
  try:
312
 
313
- pipe = load_image_pipeline(
314
- config["id"],
315
- "text",
316
- )
317
 
318
- generator = torch.Generator(
319
- device=DEVICE
320
- ).manual_seed(seed)
321
-
322
- result = pipe(
323
- prompt=prompt.strip(),
324
- negative_prompt=negative_prompt or None,
325
- width=width,
326
- height=height,
327
- num_inference_steps=actual_steps,
328
- guidance_scale=config["guidance"],
329
- generator=generator,
330
- )
331
 
332
- output = result.images[0]
 
 
 
 
 
 
 
 
 
 
 
 
333
 
334
- return output, seed
335
 
336
  except Exception as error:
337
 
338
  traceback.print_exc()
339
 
340
  raise gr.Error(
341
- f"Text-to-image failed: {str(error)}"
342
  )
343
 
344
 
@@ -360,15 +329,12 @@ def generate_image_to_image(
360
  ):
361
 
362
  if input_image is None:
363
-
364
  raise gr.Error("Please upload an image.")
365
 
366
  if not prompt or not prompt.strip():
367
-
368
  raise gr.Error("Please enter a transformation prompt.")
369
 
370
  if model_name not in IMAGE_TO_IMAGE_MODELS:
371
-
372
  raise gr.Error("Invalid image-to-image model.")
373
 
374
  if random_seed:
@@ -376,32 +342,18 @@ def generate_image_to_image(
376
 
377
  seed = int(seed)
378
 
379
- strength = float(strength)
380
- strength = max(0.05, min(strength, 0.95))
381
-
382
  steps = max(1, min(int(steps), 30))
383
 
384
  try:
385
 
386
- # Convert uploaded image to RGB.
387
-
388
- if isinstance(input_image, Image.Image):
389
-
390
- image = input_image.convert("RGB")
391
-
392
- else:
393
-
394
- image = Image.open(input_image).convert("RGB")
395
-
396
- # Preserve image proportions.
397
 
398
  image.thumbnail(
399
  (768, 768),
400
  Image.Resampling.LANCZOS,
401
  )
402
 
403
- # Make dimensions compatible with Stable Diffusion.
404
-
405
  new_width = max(256, (image.width // 8) * 8)
406
  new_height = max(256, (image.height // 8) * 8)
407
 
@@ -412,33 +364,35 @@ def generate_image_to_image(
412
 
413
  model_id = IMAGE_TO_IMAGE_MODELS[model_name]
414
 
415
- pipe = load_image_pipeline(
416
- model_id,
417
- "image",
418
- )
419
 
420
- generator = torch.Generator(
421
- device=DEVICE
422
- ).manual_seed(seed)
423
-
424
- result = pipe(
425
- prompt=prompt.strip(),
426
- image=image,
427
- negative_prompt=negative_prompt or None,
428
- strength=strength,
429
- num_inference_steps=steps,
430
- guidance_scale=float(guidance),
431
- generator=generator,
432
- )
 
 
 
 
 
433
 
434
- return result.images[0], seed
435
 
436
  except Exception as error:
437
 
438
  traceback.print_exc()
439
 
440
  raise gr.Error(
441
- f"Image-to-image failed: {str(error)}"
442
  )
443
 
444
 
@@ -450,7 +404,7 @@ SYSTEM_PROMPT = """
450
  You are Tasting AI, a professional software engineering
451
  and advanced coding assistant.
452
 
453
- YOUR SPECIALIZATIONS:
454
 
455
  - Python
456
  - Kotlin
@@ -478,38 +432,23 @@ YOUR SPECIALIZATIONS:
478
  - Code optimization
479
  - Software architecture
480
 
481
- CORE RULES:
482
 
483
  1. Understand the complete user request.
484
-
485
- 2. Generate practical, working code.
486
-
487
  3. Never intentionally omit important code.
488
-
489
  4. Preserve existing features when modifying projects.
490
-
491
  5. Explain important changes.
492
-
493
  6. Return complete files when requested.
494
-
495
  7. Identify required dependencies.
496
-
497
  8. Never claim code was tested unless actually tested.
498
-
499
  9. Use Markdown formatting.
500
-
501
  10. Prioritize correctness.
502
-
503
  11. Analyze error messages before proposing fixes.
504
-
505
  12. Avoid unnecessary code changes.
506
-
507
- 13. Maintain compatibility with the requested environment.
508
-
509
- 14. Clearly explain any limitations.
510
-
511
- 15. When asked for a complete application,
512
- return the complete implementation rather than pseudocode.
513
  """
514
 
515
 
@@ -520,7 +459,6 @@ return the complete implementation rather than pseudocode.
520
  def load_code_model(model_name):
521
 
522
  if model_name not in CODE_MODELS:
523
-
524
  raise ValueError("Invalid coding model.")
525
 
526
  model_id = CODE_MODELS[model_name]
@@ -531,7 +469,6 @@ def load_code_model(model_name):
531
  code_cache["name"] == model_id
532
  and code_cache["model"] is not None
533
  ):
534
-
535
  return (
536
  code_cache["tokenizer"],
537
  code_cache["model"],
@@ -568,21 +505,14 @@ def load_code_model(model_name):
568
  class StopCriteria(StoppingCriteria):
569
 
570
  def __init__(self, event):
571
-
572
  self.event = event
573
 
574
- def __call__(
575
- self,
576
- input_ids,
577
- scores,
578
- **kwargs,
579
- ):
580
-
581
  return self.event.is_set()
582
 
583
 
584
  # ==========================================
585
- # REAL TIME CODING ASSISTANT
586
  # ==========================================
587
 
588
  def coding_assistant(
@@ -594,10 +524,10 @@ def coding_assistant(
594
  request: gr.Request,
595
  ):
596
 
597
- if not prompt or not prompt.strip():
598
-
599
- yield history or [], history or []
600
 
 
 
601
  return
602
 
603
  session_id = (
@@ -617,64 +547,58 @@ def coding_assistant(
617
 
618
  generation_events[session_id] = stop_event
619
 
620
- history = list(history or [])
621
-
622
- conversation = history[-MAX_HISTORY_MESSAGES:]
623
-
624
- messages = [
625
- {
626
- "role": "system",
627
- "content": SYSTEM_PROMPT,
628
- }
629
- ]
630
 
631
- # Preserve previous conversation.
 
 
 
632
 
633
- for item in conversation:
634
 
635
- if not isinstance(item, dict):
636
- continue
 
 
 
 
637
 
638
- role = item.get("role")
639
- content = item.get("content")
640
 
641
- if (
642
- role in ["user", "assistant"]
643
- and isinstance(content, str)
644
- ):
645
 
646
- messages.append({
647
- "role": role,
648
- "content": content,
649
- })
650
 
651
- messages.append({
652
- "role": "user",
653
- "content": prompt.strip(),
654
- })
 
 
 
 
655
 
656
- updated_history = history + [
657
- {
658
  "role": "user",
659
  "content": prompt.strip(),
660
- },
661
- {
662
- "role": "assistant",
663
- "content": "⏳ Loading coding model...",
664
- },
665
- ]
666
 
667
- try:
668
 
669
- yield updated_history, updated_history
 
 
 
 
670
 
671
- tokenizer, model = load_code_model(model_name)
672
 
673
- formatted_prompt = tokenizer.apply_chat_template(
674
- messages,
675
- tokenize=False,
676
- add_generation_prompt=True,
677
- )
678
 
679
  inputs = tokenizer(
680
  formatted_prompt,
@@ -687,29 +611,20 @@ def coding_assistant(
687
  tokenizer,
688
  skip_prompt=True,
689
  skip_special_tokens=True,
 
690
  )
691
 
692
  generation_kwargs = {
693
-
694
  **inputs,
695
-
696
  "streamer": streamer,
697
-
698
  "max_new_tokens": int(max_tokens),
699
-
700
  "do_sample": float(temperature) > 0.05,
701
-
702
- "temperature": max(
703
- float(temperature),
704
- 0.05,
705
- ),
706
-
707
  "pad_token_id": (
708
  tokenizer.pad_token_id
709
  if tokenizer.pad_token_id is not None
710
  else tokenizer.eos_token_id
711
  ),
712
-
713
  "stopping_criteria": StoppingCriteriaList([
714
  StopCriteria(stop_event)
715
  ]),
@@ -722,19 +637,13 @@ def coding_assistant(
722
  try:
723
 
724
  with torch.inference_mode():
725
-
726
- model.generate(
727
- **generation_kwargs
728
- )
729
 
730
  except Exception as error:
731
 
732
  generation_error.append(str(error))
733
-
734
  traceback.print_exc()
735
 
736
- # Ensure the streamer can finish.
737
-
738
  try:
739
  streamer.end()
740
  except Exception:
@@ -771,18 +680,16 @@ def coding_assistant(
771
 
772
  thread.join(timeout=10)
773
 
774
- if generation_error:
 
775
 
776
- raise RuntimeError(
777
- generation_error[0]
778
- )
779
 
780
  if stop_event.is_set():
781
-
782
  response += "\n\n⏹ Generation stopped."
783
 
784
- elif not response.strip():
785
-
786
  response = "No response generated."
787
 
788
  final_history = history + [
@@ -800,9 +707,7 @@ def coding_assistant(
800
 
801
  except Exception as error:
802
 
803
- error_text = (
804
- f"**Coding error:** {str(error)}"
805
- )
806
 
807
  final_history = history + [
808
  {
@@ -822,11 +727,7 @@ def coding_assistant(
822
  with generation_events_lock:
823
 
824
  if generation_events.get(session_id) is stop_event:
825
-
826
- generation_events.pop(
827
- session_id,
828
- None,
829
- )
830
 
831
 
832
  # ==========================================
@@ -852,11 +753,10 @@ def stop_generation(request: gr.Request):
852
 
853
 
854
  # ==========================================
855
- # CLEAR CODING HISTORY
856
  # ==========================================
857
 
858
  def clear_history():
859
-
860
  return [], "Conversation cleared."
861
 
862
 
@@ -865,317 +765,186 @@ def clear_history():
865
  # ==========================================
866
 
867
  CSS = r"""
868
-
869
  @import url(
870
  'https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&display=swap'
871
  );
872
 
873
  :root {
874
-
875
  --bg: #080b14;
876
-
877
  --panel: #101727;
878
-
879
  --accent: #8b5cf6;
880
-
881
  --cyan: #06d6e9;
882
-
883
  --text: #f5f7ff;
884
-
885
  }
886
 
887
  body {
888
-
889
  background:
890
- radial-gradient(
891
- circle at 15% 10%,
892
- rgba(105, 64, 255, .15),
893
- transparent 35%
894
- ),
895
- radial-gradient(
896
- circle at 90% 80%,
897
- rgba(0, 205, 255, .10),
898
- transparent 35%
899
- ),
900
  var(--bg) !important;
901
-
902
- font-family: Inter, sans-serif !important;
903
-
904
  }
905
 
906
  .gradio-container {
907
-
908
  max-width: 1250px !important;
909
-
910
  margin: auto !important;
911
-
912
  background: transparent !important;
913
-
914
  }
915
 
916
  footer {
917
-
918
  display: none !important;
919
-
920
  }
921
 
922
  #main-header {
923
-
924
  position: relative;
925
-
926
  overflow: hidden;
927
-
928
  text-align: center;
929
-
930
  padding: 55px 20px;
931
-
932
- border: 1px solid rgba(139, 92, 246, .35);
933
-
934
  border-radius: 25px;
935
-
936
- background:
937
- linear-gradient(
938
- 120deg,
939
- rgba(45, 26, 90, .95),
940
- rgba(9, 35, 57, .95),
941
- rgba(30, 17, 70, .95)
942
- );
943
-
944
- box-shadow:
945
- 0 0 30px rgba(139, 92, 246, .16),
946
- inset 0 0 35px rgba(6, 214, 233, .07);
947
-
948
  animation: bannerGlow 5s ease-in-out infinite alternate;
949
-
950
  }
951
 
952
  @keyframes bannerGlow {
953
-
954
  from {
955
-
956
- box-shadow:
957
- 0 0 15px rgba(139, 92, 246, .15);
958
-
959
  }
960
-
961
  to {
962
-
963
  box-shadow:
964
- 0 0 38px rgba(6, 214, 233, .24),
965
- 0 0 65px rgba(139, 92, 246, .17);
966
-
967
  }
968
-
969
  }
970
 
971
  .hero-title {
972
-
973
- font-size: clamp(30px, 6vw, 58px);
974
-
975
  font-weight: 900;
976
-
977
  letter-spacing: -2px;
978
-
979
- background:
980
- linear-gradient(
981
- 90deg,
982
- #ffffff,
983
- #b8a5ff,
984
- #56e8ff,
985
- #ffffff
986
- );
987
-
988
  background-size: 300%;
989
-
990
  -webkit-background-clip: text;
991
-
992
  -webkit-text-fill-color: transparent;
993
-
994
  animation: textGradient 5s linear infinite;
995
-
996
  }
997
 
998
  @keyframes textGradient {
999
-
1000
  0% { background-position: 0%; }
1001
-
1002
  100% { background-position: 300%; }
1003
-
1004
  }
1005
 
1006
  .hero-subtitle {
1007
-
1008
  color: #bdc7df;
1009
-
1010
- font-size: 15px;
1011
-
1012
- letter-spacing: 1px;
1013
-
1014
- animation: fadeIn 1.5s ease;
1015
-
 
 
 
 
1016
  }
1017
 
1018
- @keyframes fadeIn {
1019
-
1020
- from {
1021
-
1022
- opacity: 0;
1023
-
1024
- transform: translateY(12px);
1025
-
1026
- }
1027
-
1028
- to {
1029
-
1030
- opacity: 1;
1031
-
1032
- transform: translateY(0);
1033
-
1034
- }
1035
-
1036
  }
1037
 
1038
- .section-title {
1039
-
1040
- font-size: 23px;
1041
-
1042
- font-weight: 800;
1043
-
1044
- color: #ffffff;
1045
-
1046
  }
1047
 
1048
  .gradio-container .tab-nav {
1049
-
1050
- border: 1px solid rgba(139, 92, 246, .25);
1051
-
1052
  border-radius: 15px;
1053
-
1054
- background: rgba(18, 24, 40, .8);
1055
-
1056
  padding: 7px;
1057
-
1058
  }
1059
 
1060
  .gradio-container button {
1061
-
1062
  border-radius: 12px !important;
1063
-
1064
  transition: all .25s ease !important;
1065
-
1066
  }
1067
 
1068
  .gradio-container button:hover {
1069
-
1070
  transform: translateY(-2px);
1071
-
1072
- box-shadow: 0 0 20px rgba(139, 92, 246, .35);
1073
-
1074
  }
1075
 
1076
  .primary {
1077
-
1078
- background:
1079
- linear-gradient(
1080
- 100deg,
1081
- #7045ed,
1082
- #168edb
1083
- ) !important;
1084
-
1085
  border: 1px solid rgba(255,255,255,.15) !important;
1086
-
1087
  color: white !important;
1088
-
1089
  font-weight: 800 !important;
1090
-
1091
  }
1092
 
1093
- textarea, input {
1094
-
1095
  border-radius: 12px !important;
1096
-
1097
  }
1098
 
1099
  .gradio-container .block {
1100
-
1101
- border-color: rgba(139, 92, 246, .16) !important;
1102
-
1103
- }
1104
-
1105
- .output-markdown {
1106
-
1107
- border-radius: 15px;
1108
-
1109
  }
1110
 
1111
  #coding-output {
1112
-
1113
  min-height: 350px;
1114
-
1115
  padding: 18px;
1116
-
1117
- border: 1px solid rgba(6, 214, 233, .22);
1118
-
1119
  border-radius: 15px;
1120
-
1121
- background: rgba(9, 15, 28, .8);
1122
-
1123
  }
1124
 
1125
  #coding-output code {
1126
-
1127
  color: #70e7ff;
 
1128
 
 
 
 
1129
  }
1130
 
1131
  #footer {
1132
-
1133
  text-align: center;
1134
-
1135
  color: #8390ad;
1136
-
1137
  padding: 20px;
1138
-
1139
  }
1140
 
1141
- .status-label {
1142
-
1143
- color: #61e5f3;
1144
-
1145
- font-weight: 600;
1146
-
1147
- }
1148
-
1149
- @media(max-width: 650px) {
1150
-
1151
  .gradio-container {
1152
-
1153
  padding: 8px !important;
1154
-
1155
  }
1156
 
1157
  #main-header {
1158
-
1159
  padding: 35px 12px;
1160
-
1161
  border-radius: 18px;
1162
-
1163
  }
1164
 
1165
  .hero-title {
1166
-
1167
  font-size: 32px;
1168
-
1169
  }
1170
 
1171
  .hero-subtitle {
1172
-
1173
- font-size: 12px;
1174
-
1175
  }
1176
-
1177
  }
1178
-
1179
  """
1180
 
1181
 
@@ -1184,7 +953,6 @@ textarea, input {
1184
  # ==========================================
1185
 
1186
  HEADER = """
1187
-
1188
  <div id="main-header">
1189
 
1190
  <div style="
@@ -1194,21 +962,15 @@ HEADER = """
1194
  font-weight:800;
1195
  margin-bottom:12px;
1196
  ">
1197
-
1198
  NEXT GENERATION ARTIFICIAL INTELLIGENCE
1199
-
1200
  </div>
1201
 
1202
  <div class="hero-title">
1203
-
1204
  ⚡ TASTING AI STUDIO
1205
-
1206
  </div>
1207
 
1208
  <div class="hero-subtitle">
1209
-
1210
  CREATE · TRANSFORM · CODE · INNOVATE
1211
-
1212
  </div>
1213
 
1214
  <div style="
@@ -1244,9 +1006,7 @@ HEADER = """
1244
  ">💻 AI Coding</span>
1245
 
1246
  </div>
1247
-
1248
  </div>
1249
-
1250
  """
1251
 
1252
 
@@ -1268,16 +1028,16 @@ with gr.Blocks(
1268
 
1269
  gr.Markdown(
1270
  """
1271
- <div style="text-align:center;color:#9ba9c5;padding:12px">
1272
- Premium AI workspace · Public open models · Live generation
 
 
 
 
1273
  </div>
1274
  """
1275
  )
1276
 
1277
- # ======================================
1278
- # MAIN TABS
1279
- # ======================================
1280
-
1281
  with gr.Tabs():
1282
 
1283
  # ==================================
@@ -1286,9 +1046,7 @@ with gr.Blocks(
1286
 
1287
  with gr.Tab("🎨 Text to Image"):
1288
 
1289
- gr.Markdown(
1290
- "## Create Images with AI"
1291
- )
1292
 
1293
  image_model = gr.Dropdown(
1294
  choices=list(IMAGE_MODELS.keys()),
@@ -1298,10 +1056,7 @@ with gr.Blocks(
1298
 
1299
  image_prompt = gr.Textbox(
1300
  label="Image Prompt",
1301
- placeholder=(
1302
- "A beautiful fantasy landscape, "
1303
- "cinematic lighting, detailed artwork..."
1304
- ),
1305
  lines=4,
1306
  )
1307
 
@@ -1314,24 +1069,21 @@ with gr.Blocks(
1314
  with gr.Row():
1315
 
1316
  width = gr.Slider(
1317
- 256,
1318
- 768,
1319
  value=512,
1320
  step=64,
1321
  label="Image Width",
1322
  )
1323
 
1324
  height = gr.Slider(
1325
- 256,
1326
- 768,
1327
  value=512,
1328
  step=64,
1329
  label="Image Height",
1330
  )
1331
 
1332
  steps = gr.Slider(
1333
- 1,
1334
- 30,
1335
  value=4,
1336
  step=1,
1337
  label="Inference Steps",
@@ -1353,7 +1105,6 @@ with gr.Blocks(
1353
  generate_button = gr.Button(
1354
  "✨ Generate Image",
1355
  variant="primary",
1356
- elem_classes=["primary-button"],
1357
  )
1358
 
1359
  image_output = gr.Image(
@@ -1395,7 +1146,7 @@ with gr.Blocks(
1395
  """
1396
  ## Transform Your Images
1397
 
1398
- Upload a picture and describe the transformation.
1399
  """
1400
  )
1401
 
@@ -1407,9 +1158,9 @@ with gr.Blocks(
1407
 
1408
  gr.Markdown(
1409
  """
1410
- **Example transformation prompts**
1411
 
1412
- - Whimsical hand-painted anime illustration
1413
  - Soft watercolor fantasy artwork
1414
  - Colorful cartoon illustration
1415
  - Cinematic digital painting
@@ -1425,10 +1176,7 @@ with gr.Blocks(
1425
 
1426
  img2img_prompt = gr.Textbox(
1427
  label="Transformation Prompt",
1428
- placeholder=(
1429
- "Transform this photograph into "
1430
- "a beautiful hand-painted anime illustration..."
1431
- ),
1432
  lines=4,
1433
  )
1434
 
@@ -1439,30 +1187,23 @@ with gr.Blocks(
1439
  )
1440
 
1441
  strength = gr.Slider(
1442
- 0.05,
1443
- 0.95,
1444
  value=0.70,
1445
  step=0.05,
1446
  label="Transformation Strength",
1447
- info=(
1448
- "Lower values preserve more of the original image. "
1449
- "Higher values create bigger changes."
1450
- ),
1451
  )
1452
 
1453
  with gr.Row():
1454
 
1455
  img2img_steps = gr.Slider(
1456
- 1,
1457
- 30,
1458
  value=25,
1459
  step=1,
1460
  label="Inference Steps",
1461
  )
1462
 
1463
  img2img_guidance = gr.Slider(
1464
- 1,
1465
- 15,
1466
  value=7.5,
1467
  step=0.5,
1468
  label="Guidance Scale",
@@ -1527,7 +1268,7 @@ with gr.Blocks(
1527
  ## Advanced AI Coding Assistant
1528
 
1529
  <div style="color:#7ddfff">
1530
- Real-time token streaming · Multiple coding models
1531
  </div>
1532
  """
1533
  )
@@ -1540,25 +1281,21 @@ with gr.Blocks(
1540
 
1541
  code_prompt = gr.Textbox(
1542
  label="Your Coding Request",
1543
- placeholder=(
1544
- "Build a complete Android application..."
1545
- ),
1546
  lines=6,
1547
  )
1548
 
1549
  with gr.Row():
1550
 
1551
  max_tokens = gr.Slider(
1552
- 128,
1553
- 1024,
1554
  value=512,
1555
  step=128,
1556
  label="Maximum Output Tokens",
1557
  )
1558
 
1559
  temperature = gr.Slider(
1560
- 0.1,
1561
- 1.0,
1562
  value=0.3,
1563
  step=0.1,
1564
  label="Temperature",
@@ -1608,9 +1345,6 @@ with gr.Blocks(
1608
  coding_chat,
1609
  coding_history,
1610
  ],
1611
- ).then(
1612
- fn=lambda: "Generation completed.",
1613
- outputs=coding_status,
1614
  )
1615
 
1616
  stop_button.click(
@@ -1651,7 +1385,7 @@ with gr.Blocks(
1651
  </div>
1652
 
1653
  <div style="margin-top:8px;font-size:11px">
1654
- Powered by open-source models and Hugging Face
1655
  </div>
1656
 
1657
  </div>
 
4
  import random
5
  import threading
6
  import traceback
7
+ import uuid
8
 
9
  # ==========================================
10
  # ENVIRONMENT
 
11
  # ==========================================
12
 
13
  os.environ["HF_HUB_DISABLE_IMPLICIT_TOKEN"] = "1"
 
18
  import gradio as gr
19
  import torch
20
 
21
+ from PIL import Image
22
 
23
  from diffusers import (
24
  DiffusionPipeline,
 
37
 
38
 
39
  # ==========================================
40
+ # CONFIGURATION
41
  # ==========================================
42
 
43
  APP_NAME = "Tasting AI Studio"
 
44
  APP_VERSION = "2.0 Premium"
45
 
 
 
46
  IMAGE_DTYPE = torch.float16
47
 
48
  MAX_INPUT_LENGTH = 4096
 
49
  MAX_HISTORY_MESSAGES = 10
50
 
51
+
52
  # ==========================================
53
  # TEXT TO IMAGE MODELS
54
  # ==========================================
55
 
56
  IMAGE_MODELS = {
 
57
  "SDXL Turbo": {
58
  "id": "stabilityai/sdxl-turbo",
59
  "steps": 4,
 
89
  # ==========================================
90
 
91
  IMAGE_TO_IMAGE_MODELS = {
 
92
  "Stable Diffusion 1.5 Img2Img":
93
  "stable-diffusion-v1-5/stable-diffusion-v1-5",
 
94
  }
95
 
96
 
 
99
  # ==========================================
100
 
101
  CODE_MODELS = {
102
+ # Original models
 
103
 
104
  "Qwen Coder 0.5B":
105
  "Qwen/Qwen2.5-Coder-0.5B-Instruct",
 
110
  "DeepSeek Coder 1.3B":
111
  "deepseek-ai/deepseek-coder-1.3b-instruct",
112
 
113
+ # Additional models
114
 
115
  "Qwen Coder 3B":
116
  "Qwen/Qwen2.5-Coder-3B-Instruct",
 
120
 
121
  "CodeGen 350M":
122
  "Salesforce/codegen-350M-mono",
 
123
  }
124
 
125
 
126
  # ==========================================
127
+ # GLOBAL CACHES
128
  # ==========================================
129
 
130
  image_cache = {
 
140
  }
141
 
142
  image_lock = threading.RLock()
 
143
  code_lock = threading.RLock()
144
 
145
  generation_events = {}
 
146
  generation_events_lock = threading.Lock()
147
 
148
 
149
  # ==========================================
150
+ # MEMORY CLEANUP
151
  # ==========================================
152
 
153
  def clear_image_cache():
154
 
155
+ old_pipe = image_cache["pipe"]
 
 
156
 
157
+ image_cache["pipe"] = None
158
+ image_cache["name"] = None
159
+ image_cache["mode"] = None
160
 
161
+ if old_pipe is not None:
162
+ del old_pipe
163
 
164
+ gc.collect()
165
 
166
+ if torch.cuda.is_available():
167
+ torch.cuda.empty_cache()
168
 
169
 
170
  def clear_code_cache():
171
 
172
+ old_model = code_cache["model"]
173
+ old_tokenizer = code_cache["tokenizer"]
 
 
174
 
175
+ code_cache["model"] = None
176
+ code_cache["tokenizer"] = None
177
+ code_cache["name"] = None
178
 
179
+ if old_model is not None:
180
+ del old_model
181
 
182
+ if old_tokenizer is not None:
183
+ del old_tokenizer
184
 
185
+ gc.collect()
186
 
187
 
188
  # ==========================================
 
199
  image_cache["name"] == cache_key
200
  and image_cache["pipe"] is not None
201
  ):
 
202
  return image_cache["pipe"]
203
 
204
  clear_image_cache()
 
209
  model_id,
210
  torch_dtype=IMAGE_DTYPE,
211
  token=False,
 
 
212
  )
213
 
214
  elif mode == "image":
 
220
  )
221
 
222
  else:
223
+ raise ValueError("Unsupported image mode.")
224
 
225
+ pipe = pipe.to("cuda")
226
 
 
 
 
227
  if hasattr(pipe, "enable_attention_slicing"):
228
  pipe.enable_attention_slicing()
229
 
 
251
  ):
252
 
253
  if not prompt or not prompt.strip():
 
254
  raise gr.Error("Please enter an image prompt.")
255
 
256
  if model_name not in IMAGE_MODELS:
 
257
  raise gr.Error("Invalid image model.")
258
 
 
 
259
  if random_seed:
260
  seed = random.randint(0, 2147483647)
261
 
262
  seed = int(seed)
263
 
264
+ config = IMAGE_MODELS[model_name]
 
 
 
265
 
266
+ width = max(256, min(int(width), 768))
267
+ height = max(256, min(int(height), 768))
268
 
269
  width = (width // 8) * 8
270
  height = (height // 8) * 8
 
275
  )
276
 
277
  if model_name in ["SDXL Turbo", "SD Turbo"]:
 
278
  actual_steps = min(actual_steps, 4)
279
 
 
 
 
 
280
  try:
281
 
282
+ with image_lock:
 
 
 
283
 
284
+ pipe = load_image_pipeline(
285
+ config["id"],
286
+ "text",
287
+ )
 
 
 
 
 
 
 
 
 
288
 
289
+ generator = torch.Generator(
290
+ device="cuda"
291
+ ).manual_seed(seed)
292
+
293
+ result = pipe(
294
+ prompt=prompt.strip(),
295
+ negative_prompt=negative_prompt or None,
296
+ width=width,
297
+ height=height,
298
+ num_inference_steps=actual_steps,
299
+ guidance_scale=config["guidance"],
300
+ generator=generator,
301
+ )
302
 
303
+ return result.images[0], seed
304
 
305
  except Exception as error:
306
 
307
  traceback.print_exc()
308
 
309
  raise gr.Error(
310
+ f"Image generation failed: {error}"
311
  )
312
 
313
 
 
329
  ):
330
 
331
  if input_image is None:
 
332
  raise gr.Error("Please upload an image.")
333
 
334
  if not prompt or not prompt.strip():
 
335
  raise gr.Error("Please enter a transformation prompt.")
336
 
337
  if model_name not in IMAGE_TO_IMAGE_MODELS:
 
338
  raise gr.Error("Invalid image-to-image model.")
339
 
340
  if random_seed:
 
342
 
343
  seed = int(seed)
344
 
345
+ strength = max(0.05, min(float(strength), 0.95))
 
 
346
  steps = max(1, min(int(steps), 30))
347
 
348
  try:
349
 
350
+ image = input_image.convert("RGB")
 
 
 
 
 
 
 
 
 
 
351
 
352
  image.thumbnail(
353
  (768, 768),
354
  Image.Resampling.LANCZOS,
355
  )
356
 
 
 
357
  new_width = max(256, (image.width // 8) * 8)
358
  new_height = max(256, (image.height // 8) * 8)
359
 
 
364
 
365
  model_id = IMAGE_TO_IMAGE_MODELS[model_name]
366
 
367
+ with image_lock:
 
 
 
368
 
369
+ pipe = load_image_pipeline(
370
+ model_id,
371
+ "image",
372
+ )
373
+
374
+ generator = torch.Generator(
375
+ device="cuda"
376
+ ).manual_seed(seed)
377
+
378
+ result = pipe(
379
+ prompt=prompt.strip(),
380
+ image=image,
381
+ negative_prompt=negative_prompt or None,
382
+ strength=strength,
383
+ num_inference_steps=steps,
384
+ guidance_scale=float(guidance),
385
+ generator=generator,
386
+ )
387
 
388
+ return result.images[0], seed
389
 
390
  except Exception as error:
391
 
392
  traceback.print_exc()
393
 
394
  raise gr.Error(
395
+ f"Image-to-image failed: {error}"
396
  )
397
 
398
 
 
404
  You are Tasting AI, a professional software engineering
405
  and advanced coding assistant.
406
 
407
+ SPECIALIZATIONS:
408
 
409
  - Python
410
  - Kotlin
 
432
  - Code optimization
433
  - Software architecture
434
 
435
+ RULES:
436
 
437
  1. Understand the complete user request.
438
+ 2. Generate practical working code.
 
 
439
  3. Never intentionally omit important code.
 
440
  4. Preserve existing features when modifying projects.
 
441
  5. Explain important changes.
 
442
  6. Return complete files when requested.
 
443
  7. Identify required dependencies.
 
444
  8. Never claim code was tested unless actually tested.
 
445
  9. Use Markdown formatting.
 
446
  10. Prioritize correctness.
 
447
  11. Analyze error messages before proposing fixes.
 
448
  12. Avoid unnecessary code changes.
449
+ 13. Maintain environment compatibility.
450
+ 14. Clearly explain limitations.
451
+ 15. Return complete implementations when requested.
 
 
 
 
452
  """
453
 
454
 
 
459
  def load_code_model(model_name):
460
 
461
  if model_name not in CODE_MODELS:
 
462
  raise ValueError("Invalid coding model.")
463
 
464
  model_id = CODE_MODELS[model_name]
 
469
  code_cache["name"] == model_id
470
  and code_cache["model"] is not None
471
  ):
 
472
  return (
473
  code_cache["tokenizer"],
474
  code_cache["model"],
 
505
  class StopCriteria(StoppingCriteria):
506
 
507
  def __init__(self, event):
 
508
  self.event = event
509
 
510
+ def __call__(self, input_ids, scores, **kwargs):
 
 
 
 
 
 
511
  return self.event.is_set()
512
 
513
 
514
  # ==========================================
515
+ # CODING ASSISTANT
516
  # ==========================================
517
 
518
  def coding_assistant(
 
524
  request: gr.Request,
525
  ):
526
 
527
+ history = list(history or [])
 
 
528
 
529
+ if not prompt or not prompt.strip():
530
+ yield history, history
531
  return
532
 
533
  session_id = (
 
547
 
548
  generation_events[session_id] = stop_event
549
 
550
+ try:
 
 
 
 
 
 
 
 
 
551
 
552
+ yield history + [
553
+ {"role": "user", "content": prompt},
554
+ {"role": "assistant", "content": "⏳ Loading coding model..."},
555
+ ], history
556
 
557
+ tokenizer, model = load_code_model(model_name)
558
 
559
+ messages = [
560
+ {
561
+ "role": "system",
562
+ "content": SYSTEM_PROMPT,
563
+ }
564
+ ]
565
 
566
+ for item in history[-MAX_HISTORY_MESSAGES:]:
 
567
 
568
+ if not isinstance(item, dict):
569
+ continue
 
 
570
 
571
+ role = item.get("role")
572
+ content = item.get("content")
 
 
573
 
574
+ if (
575
+ role in ["user", "assistant"]
576
+ and isinstance(content, str)
577
+ ):
578
+ messages.append({
579
+ "role": role,
580
+ "content": content,
581
+ })
582
 
583
+ messages.append({
 
584
  "role": "user",
585
  "content": prompt.strip(),
586
+ })
 
 
 
 
 
587
 
588
+ if getattr(tokenizer, "chat_template", None):
589
 
590
+ formatted_prompt = tokenizer.apply_chat_template(
591
+ messages,
592
+ tokenize=False,
593
+ add_generation_prompt=True,
594
+ )
595
 
596
+ else:
597
 
598
+ formatted_prompt = "\n\n".join(
599
+ f"{item['role'].upper()}:\n{item['content']}"
600
+ for item in messages
601
+ ) + "\n\nASSISTANT:\n"
 
602
 
603
  inputs = tokenizer(
604
  formatted_prompt,
 
611
  tokenizer,
612
  skip_prompt=True,
613
  skip_special_tokens=True,
614
+ timeout=120,
615
  )
616
 
617
  generation_kwargs = {
 
618
  **inputs,
 
619
  "streamer": streamer,
 
620
  "max_new_tokens": int(max_tokens),
 
621
  "do_sample": float(temperature) > 0.05,
622
+ "temperature": max(float(temperature), 0.05),
 
 
 
 
 
623
  "pad_token_id": (
624
  tokenizer.pad_token_id
625
  if tokenizer.pad_token_id is not None
626
  else tokenizer.eos_token_id
627
  ),
 
628
  "stopping_criteria": StoppingCriteriaList([
629
  StopCriteria(stop_event)
630
  ]),
 
637
  try:
638
 
639
  with torch.inference_mode():
640
+ model.generate(**generation_kwargs)
 
 
 
641
 
642
  except Exception as error:
643
 
644
  generation_error.append(str(error))
 
645
  traceback.print_exc()
646
 
 
 
647
  try:
648
  streamer.end()
649
  except Exception:
 
680
 
681
  thread.join(timeout=10)
682
 
683
+ if thread.is_alive():
684
+ stop_event.set()
685
 
686
+ if generation_error:
687
+ raise RuntimeError(generation_error[0])
 
688
 
689
  if stop_event.is_set():
 
690
  response += "\n\n⏹ Generation stopped."
691
 
692
+ if not response.strip():
 
693
  response = "No response generated."
694
 
695
  final_history = history + [
 
707
 
708
  except Exception as error:
709
 
710
+ error_text = f"**Coding error:** {error}"
 
 
711
 
712
  final_history = history + [
713
  {
 
727
  with generation_events_lock:
728
 
729
  if generation_events.get(session_id) is stop_event:
730
+ generation_events.pop(session_id, None)
 
 
 
 
731
 
732
 
733
  # ==========================================
 
753
 
754
 
755
  # ==========================================
756
+ # CLEAR HISTORY
757
  # ==========================================
758
 
759
  def clear_history():
 
760
  return [], "Conversation cleared."
761
 
762
 
 
765
  # ==========================================
766
 
767
  CSS = r"""
 
768
  @import url(
769
  'https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&display=swap'
770
  );
771
 
772
  :root {
 
773
  --bg: #080b14;
 
774
  --panel: #101727;
 
775
  --accent: #8b5cf6;
 
776
  --cyan: #06d6e9;
 
777
  --text: #f5f7ff;
 
778
  }
779
 
780
  body {
 
781
  background:
782
+ radial-gradient(circle at 15% 10%,
783
+ rgba(105,64,255,.15),transparent 35%),
784
+ radial-gradient(circle at 90% 80%,
785
+ rgba(0,205,255,.10),transparent 35%),
 
 
 
 
 
 
786
  var(--bg) !important;
787
+ font-family: Inter,sans-serif !important;
 
 
788
  }
789
 
790
  .gradio-container {
 
791
  max-width: 1250px !important;
 
792
  margin: auto !important;
 
793
  background: transparent !important;
 
794
  }
795
 
796
  footer {
 
797
  display: none !important;
 
798
  }
799
 
800
  #main-header {
 
801
  position: relative;
 
802
  overflow: hidden;
 
803
  text-align: center;
 
804
  padding: 55px 20px;
805
+ border: 1px solid rgba(139,92,246,.35);
 
 
806
  border-radius: 25px;
807
+ background: linear-gradient(
808
+ 120deg,
809
+ rgba(45,26,90,.95),
810
+ rgba(9,35,57,.95),
811
+ rgba(30,17,70,.95)
812
+ );
 
 
 
 
 
 
 
813
  animation: bannerGlow 5s ease-in-out infinite alternate;
 
814
  }
815
 
816
  @keyframes bannerGlow {
 
817
  from {
818
+ box-shadow: 0 0 15px rgba(139,92,246,.15);
 
 
 
819
  }
 
820
  to {
 
821
  box-shadow:
822
+ 0 0 38px rgba(6,214,233,.24),
823
+ 0 0 65px rgba(139,92,246,.17);
 
824
  }
 
825
  }
826
 
827
  .hero-title {
828
+ font-size: clamp(30px,6vw,58px);
 
 
829
  font-weight: 900;
 
830
  letter-spacing: -2px;
831
+ background: linear-gradient(
832
+ 90deg,
833
+ #ffffff,
834
+ #b8a5ff,
835
+ #56e8ff,
836
+ #ffffff
837
+ );
 
 
 
838
  background-size: 300%;
 
839
  -webkit-background-clip: text;
 
840
  -webkit-text-fill-color: transparent;
 
841
  animation: textGradient 5s linear infinite;
 
842
  }
843
 
844
  @keyframes textGradient {
 
845
  0% { background-position: 0%; }
 
846
  100% { background-position: 300%; }
 
847
  }
848
 
849
  .hero-subtitle {
 
850
  color: #bdc7df;
851
+ font-size: 14px;
852
+ letter-spacing: 2px;
853
+ width: fit-content;
854
+ max-width: 100%;
855
+ margin: 12px auto 0;
856
+ overflow: hidden;
857
+ white-space: nowrap;
858
+ border-right: 2px solid #56e8ff;
859
+ animation:
860
+ typing 3.5s steps(42,end),
861
+ cursorBlink .8s step-end infinite;
862
  }
863
 
864
+ @keyframes typing {
865
+ from { max-width: 0; }
866
+ to { max-width: 100%; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
867
  }
868
 
869
+ @keyframes cursorBlink {
870
+ 50% { border-color: transparent; }
 
 
 
 
 
 
871
  }
872
 
873
  .gradio-container .tab-nav {
874
+ border: 1px solid rgba(139,92,246,.25);
 
 
875
  border-radius: 15px;
876
+ background: rgba(18,24,40,.8);
 
 
877
  padding: 7px;
 
878
  }
879
 
880
  .gradio-container button {
 
881
  border-radius: 12px !important;
 
882
  transition: all .25s ease !important;
 
883
  }
884
 
885
  .gradio-container button:hover {
 
886
  transform: translateY(-2px);
887
+ box-shadow: 0 0 20px rgba(139,92,246,.35);
 
 
888
  }
889
 
890
  .primary {
891
+ background: linear-gradient(
892
+ 100deg,#7045ed,#168edb
893
+ ) !important;
 
 
 
 
 
894
  border: 1px solid rgba(255,255,255,.15) !important;
 
895
  color: white !important;
 
896
  font-weight: 800 !important;
 
897
  }
898
 
899
+ textarea,input {
 
900
  border-radius: 12px !important;
 
901
  }
902
 
903
  .gradio-container .block {
904
+ border-color: rgba(139,92,246,.16) !important;
 
 
 
 
 
 
 
 
905
  }
906
 
907
  #coding-output {
 
908
  min-height: 350px;
 
909
  padding: 18px;
910
+ border: 1px solid rgba(6,214,233,.22);
 
 
911
  border-radius: 15px;
912
+ background: rgba(9,15,28,.8);
 
 
913
  }
914
 
915
  #coding-output code {
 
916
  color: #70e7ff;
917
+ }
918
 
919
+ .status-label {
920
+ color: #61e5f3;
921
+ font-weight: 600;
922
  }
923
 
924
  #footer {
 
925
  text-align: center;
 
926
  color: #8390ad;
 
927
  padding: 20px;
 
928
  }
929
 
930
+ @media(max-width:650px) {
 
 
 
 
 
 
 
 
 
931
  .gradio-container {
 
932
  padding: 8px !important;
 
933
  }
934
 
935
  #main-header {
 
936
  padding: 35px 12px;
 
937
  border-radius: 18px;
 
938
  }
939
 
940
  .hero-title {
 
941
  font-size: 32px;
 
942
  }
943
 
944
  .hero-subtitle {
945
+ font-size: 10px;
 
 
946
  }
 
947
  }
 
948
  """
949
 
950
 
 
953
  # ==========================================
954
 
955
  HEADER = """
 
956
  <div id="main-header">
957
 
958
  <div style="
 
962
  font-weight:800;
963
  margin-bottom:12px;
964
  ">
 
965
  NEXT GENERATION ARTIFICIAL INTELLIGENCE
 
966
  </div>
967
 
968
  <div class="hero-title">
 
969
  ⚡ TASTING AI STUDIO
 
970
  </div>
971
 
972
  <div class="hero-subtitle">
 
973
  CREATE · TRANSFORM · CODE · INNOVATE
 
974
  </div>
975
 
976
  <div style="
 
1006
  ">💻 AI Coding</span>
1007
 
1008
  </div>
 
1009
  </div>
 
1010
  """
1011
 
1012
 
 
1028
 
1029
  gr.Markdown(
1030
  """
1031
+ <div style="
1032
+ text-align:center;
1033
+ color:#9ba9c5;
1034
+ padding:12px;
1035
+ ">
1036
+ Premium AI Workspace · Public Open Models · Live Generation
1037
  </div>
1038
  """
1039
  )
1040
 
 
 
 
 
1041
  with gr.Tabs():
1042
 
1043
  # ==================================
 
1046
 
1047
  with gr.Tab("🎨 Text to Image"):
1048
 
1049
+ gr.Markdown("## Create Images with AI")
 
 
1050
 
1051
  image_model = gr.Dropdown(
1052
  choices=list(IMAGE_MODELS.keys()),
 
1056
 
1057
  image_prompt = gr.Textbox(
1058
  label="Image Prompt",
1059
+ placeholder="Describe your image...",
 
 
 
1060
  lines=4,
1061
  )
1062
 
 
1069
  with gr.Row():
1070
 
1071
  width = gr.Slider(
1072
+ 256, 768,
 
1073
  value=512,
1074
  step=64,
1075
  label="Image Width",
1076
  )
1077
 
1078
  height = gr.Slider(
1079
+ 256, 768,
 
1080
  value=512,
1081
  step=64,
1082
  label="Image Height",
1083
  )
1084
 
1085
  steps = gr.Slider(
1086
+ 1, 30,
 
1087
  value=4,
1088
  step=1,
1089
  label="Inference Steps",
 
1105
  generate_button = gr.Button(
1106
  "✨ Generate Image",
1107
  variant="primary",
 
1108
  )
1109
 
1110
  image_output = gr.Image(
 
1146
  """
1147
  ## Transform Your Images
1148
 
1149
+ Upload an image and describe its new artistic style.
1150
  """
1151
  )
1152
 
 
1158
 
1159
  gr.Markdown(
1160
  """
1161
+ **Example prompts**
1162
 
1163
+ - Hand-painted anime-inspired illustration
1164
  - Soft watercolor fantasy artwork
1165
  - Colorful cartoon illustration
1166
  - Cinematic digital painting
 
1176
 
1177
  img2img_prompt = gr.Textbox(
1178
  label="Transformation Prompt",
1179
+ placeholder="Transform this image into a beautiful anime-inspired illustration...",
 
 
 
1180
  lines=4,
1181
  )
1182
 
 
1187
  )
1188
 
1189
  strength = gr.Slider(
1190
+ 0.05, 0.95,
 
1191
  value=0.70,
1192
  step=0.05,
1193
  label="Transformation Strength",
 
 
 
 
1194
  )
1195
 
1196
  with gr.Row():
1197
 
1198
  img2img_steps = gr.Slider(
1199
+ 1, 30,
 
1200
  value=25,
1201
  step=1,
1202
  label="Inference Steps",
1203
  )
1204
 
1205
  img2img_guidance = gr.Slider(
1206
+ 1, 15,
 
1207
  value=7.5,
1208
  step=0.5,
1209
  label="Guidance Scale",
 
1268
  ## Advanced AI Coding Assistant
1269
 
1270
  <div style="color:#7ddfff">
1271
+ Real-time token streaming · Multiple coding models
1272
  </div>
1273
  """
1274
  )
 
1281
 
1282
  code_prompt = gr.Textbox(
1283
  label="Your Coding Request",
1284
+ placeholder="Create a complete Python application...",
 
 
1285
  lines=6,
1286
  )
1287
 
1288
  with gr.Row():
1289
 
1290
  max_tokens = gr.Slider(
1291
+ 128, 1024,
 
1292
  value=512,
1293
  step=128,
1294
  label="Maximum Output Tokens",
1295
  )
1296
 
1297
  temperature = gr.Slider(
1298
+ 0.1, 1.0,
 
1299
  value=0.3,
1300
  step=0.1,
1301
  label="Temperature",
 
1345
  coding_chat,
1346
  coding_history,
1347
  ],
 
 
 
1348
  )
1349
 
1350
  stop_button.click(
 
1385
  </div>
1386
 
1387
  <div style="margin-top:8px;font-size:11px">
1388
+ Powered by Open Source Models and Hugging Face
1389
  </div>
1390
 
1391
  </div>