zenityx commited on
Commit
c54c905
·
verified ·
1 Parent(s): 457c0ef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +137 -106
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import math
2
  import gradio as gr
3
  from transformers import MarianTokenizer, MarianMTModel
 
4
 
5
  ###################################
6
  # 1) โหลดโมเดล MarianMT (Thai->En)
@@ -55,20 +56,41 @@ def approximate_temp_with_star(star_type, distance_au, albedo=0.3):
55
  return round(T_c)
56
 
57
  ###################################
58
- # 3) สูตรแรงโน้มถ่วง (สมมุติตามนิวตัน)
59
  ###################################
60
- def approximate_gravity_nw(diameter_factor):
61
  """
62
- สมมุติว่ามวล ∝ R^3 => g ∝ R
63
  """
64
- return round(diameter_factor, 2)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
 
66
  ###################################
67
  # 4) Dictionary แปลล่วงหน้า (TH->EN)
68
  ###################################
69
- # ลดการเรียก MarianMT สำหรับคำที่เกิดซ้ำ เช่น
70
- # describe_distance, describe_temp, describe_gravity, describe_tilt, describe_moons, describe_oxygen
71
-
72
  pretranslated_map = {
73
  # distance
74
  "โคจรใกล้ดาวฤกษ์มาก": "orbits extremely close to its star",
@@ -94,8 +116,18 @@ pretranslated_map = {
94
  "เอียงปานกลาง ฤดูกาลเปลี่ยนแปลง": "moderately tilted, noticeable seasonal changes",
95
  "เอียงมาก ฤดูกาลสุดขั้ว": "highly tilted, extreme seasonal shifts",
96
 
97
- # moons (prefix check some conditions)
98
- # => We'll dynamically generate string TH -> EN
 
 
 
 
 
 
 
 
 
 
99
  }
100
 
101
  def describe_distance_th_to_en(desc_th):
@@ -110,6 +142,19 @@ def describe_gravity_th_to_en(desc_th):
110
  def describe_tilt_th_to_en(desc_th):
111
  return pretranslated_map.get(desc_th, "unknown axial tilt")
112
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  ###################################
114
  # ฟังก์ชันบรรยาย (ภาษาไทย)
115
  ###################################
@@ -119,7 +164,7 @@ def describe_distance(distance_au):
119
  elif distance_au < 1.2:
120
  return "โคจรคล้ายโลกหรืออุ่นกว่านิดหน่อย"
121
  elif distance_au < 2.5:
122
- return "โคจรห่างพอประมาณ อากาศค่อนขั้วเย็น" # อาจแก้เป็น "ค่อนข้างเย็น"
123
  else:
124
  return "โคจรไกลสุดข���้ว อากาศหนาวมาก"
125
 
@@ -158,11 +203,26 @@ def describe_moons(n):
158
  return "ไม่มีดวงจันทร์"
159
  elif n == 1:
160
  return "มีดวงจันทร์หนึ่งดวง"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161
  else:
162
- if n > 2:
163
- return f"มีดวงจันทร์ {n} ดวง (ทำให้เกิดน้ำขึ้นน้ำลงรุนแรง)"
164
- else:
165
- return f"มีดวงจันทร์ {n} ดวง"
166
 
167
  def describe_oxygen(oxygen_percent):
168
  if oxygen_percent < 1:
@@ -183,7 +243,7 @@ def build_prompts_en(
183
  ):
184
  # Prompt 1
185
  prompt1 = (
186
- f"A vibrant space painting of planet '{planet_name_en}' orbiting a {star_type_en}. "
187
  f"It is {dist_desc_en}, with {temp_desc_en} conditions and {grav_desc_en} gravity. "
188
  f"{tilt_desc_en}, {moon_desc_en}, atmosphere has {oxygen_desc_en}. Cinematic details."
189
  )
@@ -200,12 +260,7 @@ def build_prompts_en(
200
  f"{tilt_desc_en} tilt, and {moon_desc_en}. Epic environment design, atmospheric perspective."
201
  )
202
 
203
- prompt_all = (
204
- "--- Prompt #1 ---\n" + prompt1 + "\n\n"
205
- "--- Prompt #2 ---\n" + prompt2 + "\n\n"
206
- "--- Prompt #3 ---\n" + prompt3 + "\n"
207
- )
208
- return prompt_all
209
 
210
  ###################################
211
  # 6) ฟังก์ชันหลัก generate_planet_info
@@ -242,17 +297,22 @@ def generate_planet_info(
242
  except:
243
  moon_count = 1
244
 
 
 
 
 
 
245
  # คำนวณ
246
  temp_c = approximate_temp_with_star(star_type_en, distance_au)
247
- g_approx = approximate_gravity_nw(diameter_factor)
248
 
249
  # -----------------------------
250
  # (A) สรุปสำหรับเด็ก (ไทย)
251
  # -----------------------------
252
  child_summary = ""
253
  child_summary += f"สวัสดีหนูน้อยนักสำรวจ!\n\n"
254
- child_summary += f"ดาว {planet_name_th} ที่หนูสร้าง เป็น{planet_type_th} "
255
- child_summary += f"โคจรรอบดาวฤกษ์ {star_type_en}\n"
256
 
257
  child_summary += f"ระยะห่าง ~{distance_au} AU => ประเมินอุณหภูมิ ~{temp_c}°C\n"
258
  if temp_c < -20:
@@ -277,7 +337,7 @@ def generate_planet_info(
277
  else:
278
  child_summary += "มีฤดูกาลตามองศาเอียง\n"
279
 
280
- child_summary += f"มีดวงจันทร์ {moon_count} ดวง\n"
281
  if moon_count > 2:
282
  child_summary += "น้ำขึ้นน้ำลงคงอลังการมาก\n"
283
 
@@ -287,7 +347,7 @@ def generate_planet_info(
287
  elif oxygen_percent > 30:
288
  child_summary += "สูงมาก ระวังไฟติดง่ายนะ\n"
289
 
290
- child_summary += f"สิ่งมีชีวิต: {life_th}\n"
291
  child_summary += "ลองคิดดูสิว่าหน้าตาจะเป็นยังไง!\n\n"
292
  child_summary += "พร้อมลุยกันแล้วหรือยัง!?"
293
 
@@ -315,8 +375,7 @@ def generate_planet_info(
315
  planet_name_en = translate_th_to_en(planet_name_th)
316
  life_en = translate_th_to_en(life_th)
317
 
318
- # 2) อธิบาย distance/temp/gravity/tilt/moon/oxygen เป็นภาษาไทย -> Map to EN
319
- # ไม่ต้องเรียก MarianMT เพราะเราใช้ pretranslated map
320
  dist_desc_th = describe_distance(distance_au)
321
  temp_desc_th = describe_temp(temp_c)
322
  grav_desc_th = describe_gravity(g_approx)
@@ -324,58 +383,18 @@ def generate_planet_info(
324
  moon_desc_th = describe_moons(moon_count)
325
  o2_desc_th = describe_oxygen(oxygen_percent)
326
 
327
- # แปลงผ่าน Dictionary (ถ้าไม่เจอ key, fallback "unknown")
328
- # distance
329
- dist_desc_en = pretranslated_map.get(dist_desc_th, "unknown distance")
330
- # temperature
331
- temp_desc_en = pretranslated_map.get(temp_desc_th, "unknown temperature")
332
- # gravity
333
- grav_desc_en = pretranslated_map.get(grav_desc_th, "unknown gravity")
334
- # tilt
335
- tilt_desc_en = pretranslated_map.get(tilt_desc_th, "unknown tilt")
336
-
337
- # moons (กรณีมีจำนวนระบุใน string)
338
- # "มีดวงจันทร์ x ดวง" -> Pre-translate ประโยคแบบ dynamic?
339
- # เราอาจ simplify: if "dวง" in moon_desc_th => split
340
- if "ไม่มีดวงจันทร์" in moon_desc_th:
341
- moon_desc_en = "no moons"
342
- elif "หนึ่งดวง" in moon_desc_th:
343
- moon_desc_en = "one moon"
344
- elif "ทำให้เกิดน้ำขึ้นน้ำลงรุนแรง" in moon_desc_th:
345
- # e.g. "มีดวงจันทร์ 4 ดวง (ทำให้เกิด...)"
346
- # split out the number
347
- import re
348
- match = re.search(r"(\d+) ดวง", moon_desc_th)
349
- if match:
350
- n_str = match.group(1)
351
- moon_desc_en = f"{n_str} moons causing powerful tides"
352
- else:
353
- moon_desc_en = "multiple moons causing stronger tides"
354
- elif "มีดวงจันทร์ " in moon_desc_th:
355
- # e.g. "มีดวงจันทร์ 2 ดวง"
356
- match = re.search(r"(\d+) ดวง", moon_desc_th)
357
- if match:
358
- n_str = match.group(1)
359
- moon_desc_en = f"{n_str} moons"
360
- else:
361
- moon_desc_en = "some moons"
362
- else:
363
- moon_desc_en = "unknown moons"
364
-
365
- # oxygen
366
- if o2_desc_th == "ไม่มีออกซิเจน":
367
- oxygen_desc_en = "no oxygen"
368
- elif o2_desc_th == "ออกซิเจนน้อย":
369
- oxygen_desc_en = "low oxygen"
370
- elif o2_desc_th == "ออกซิเจนพอเหมาะ":
371
- oxygen_desc_en = "moderate oxygen"
372
- else:
373
- oxygen_desc_en = "high oxygen"
374
 
375
- # 3) build prompts
376
- prompts_en = build_prompts_en(
377
  planet_name_en,
378
- star_type_en + " star",
379
  dist_desc_en,
380
  temp_desc_en,
381
  grav_desc_en,
@@ -385,7 +404,7 @@ def generate_planet_info(
385
  life_en
386
  )
387
 
388
- return child_summary, detail_th, prompts_en
389
 
390
  ###################################
391
  # สูตรโชว์
@@ -441,13 +460,22 @@ body {
441
  border-radius: 10px;
442
  margin-right: 10px;
443
  }
444
- #child-summary, #detail-th, #prompt-en, #formula-box {
445
  background-color: #FFFDF5;
446
  border: 2px solid #FFE082;
447
  border-radius: 10px;
448
  padding: 10px;
449
  margin-bottom: 20px;
450
  }
 
 
 
 
 
 
 
 
 
451
  """
452
 
453
  def show_formula(state):
@@ -455,16 +483,17 @@ def show_formula(state):
455
  return new_state, gr.update(visible=new_state)
456
 
457
  def welcome_text():
458
- return "ยินดีต้อนรับสู่ Planetary Adventure++ (Optimized)! ลองกรอกข้อมูลแล้วกด 'สร้างโลกแฟนตาซี' สิ!"
459
 
460
  with gr.Blocks(css=css_code) as demo:
461
  gr.Markdown("<h1 id='title'>ZenityX Planetary Adventure</h1>")
462
  gr.Markdown("""
463
  <div class="game-desc">
464
- <p>(พัฒนาโดยสถาบัน ZenityX AI Studio)</p>
 
465
  <p>ใส่ข้อมูล แล้วกด <strong>"สร้างโลกแฟนตาซี"</strong> เพื่อดู
466
  <em>สรุปสำหรับเด็ก</em>, <em>รายละเอียด (ไทย)</em>, และ <em>3 Prompts อังกฤษ</em></p>
467
- <p>ถ้าอยากดูสูตรคำนวณ กดปุ่ม "โชว์สูตรคำนวณ" ได้เลย!</p>
468
  </div>
469
  """)
470
 
@@ -476,41 +505,44 @@ with gr.Blocks(css=css_code) as demo:
476
 
477
  with gr.Row():
478
  with gr.Column():
479
- planet_name_th = gr.Textbox(label="ชื่อดาวเคราะห์ (ไทย)", placeholder="ดาวซานาดา, ดาวโซลาริส...")
480
  star_type_en = gr.Dropdown(
481
  label="ประเภทดาวฤกษ์",
482
  choices=["Red Dwarf", "White Dwarf", "Sun-like", "Blue Giant", "Supergiant"],
483
  value="Sun-like"
484
  )
485
- distance_au = gr.Textbox(label="ระยะห่าง (AU)", placeholder="1, 0.5, 2...")
486
- diameter_factor = gr.Textbox(label="ขนาด (เท่าโลก)", placeholder="1, 2, 0.5...")
487
-
488
- with gr.Column():
489
- tilt_slider = gr.Slider(0, 90, step=1, value=23.5, label="แกนเอียง (องศา)")
490
- moon_slider = gr.Slider(0, 10, step=1, value=1, label="จำนวนดวงจันทร์")
491
- oxygen_slider = gr.Slider(0, 100, step=1, value=21, label="% ออกซิเจน")
492
  planet_type_th = gr.Dropdown(
493
  label="ชนิดดาวเคราะห์ (ไทย)",
494
  choices=["ดาวหิน", "ดาวก๊าซ", "ดาวน้ำแข็ง"],
495
  value="ดาวหิน"
496
  )
497
- life_th = gr.Textbox(label="สิ่งมีชีวิต (ไทย)", placeholder="แมลงยักษ์เรืองแสง...")
 
 
 
 
 
498
 
499
  create_btn = gr.Button("สร้างโลกแฟนตาซี", elem_classes="btn-main")
500
 
501
  child_summary_out = gr.Textbox(label="สรุปสำหรับเด็ก (ไทย)", interactive=False, elem_id="child-summary")
502
  detail_th_out = gr.Textbox(label="รายละเอียด (ไทย)", interactive=False, elem_id="detail-th")
503
- prompt_en_out = gr.Textbox(label="Prompts (English)", interactive=False, elem_id="prompt-en")
 
 
504
 
 
505
  copy_button_html = """
506
- <button style="background-color: #F06292; border: 2px solid #E91E63; font-weight: bold;
507
- font-size: 1.0rem; padding: 8px 20px; border-radius: 10px;"
508
- onclick="copyPromptText()">
509
- คัดลอก Prompt
510
- </button>
511
  <script>
512
- function copyPromptText() {
513
- const promptBox = document.querySelector('#prompt-en textarea');
514
  if (!promptBox) {
515
  alert('ไม่พบข้อความ Prompt!');
516
  return;
@@ -531,8 +563,8 @@ with gr.Blocks(css=css_code) as demo:
531
  star_type_en=s_type_en,
532
  distance_str=dist_au,
533
  diameter_str=dia_fac,
534
- tilt_value=str(tilt_val),
535
- moon_value=str(moon_val),
536
  oxygen_percent=oxy_val,
537
  planet_type_th=p_type_th,
538
  life_th=l_th
@@ -554,13 +586,12 @@ with gr.Blocks(css=css_code) as demo:
554
  outputs=[
555
  child_summary_out,
556
  detail_th_out,
557
- prompt_en_out
 
 
558
  ]
559
  )
560
 
561
- def welcome_text():
562
- return "ยินดีต้อนรับสู่ ZenityX Planetary Adventure! ลองกรอกข้อมูลแล้วกด 'สร้างโลกแฟนตาซี' สิ!"
563
-
564
  demo.load(fn=welcome_text, inputs=None, outputs=child_summary_out)
565
 
566
  demo.launch()
 
1
  import math
2
  import gradio as gr
3
  from transformers import MarianTokenizer, MarianMTModel
4
+ import re
5
 
6
  ###################################
7
  # 1) โหลดโมเดล MarianMT (Thai->En)
 
56
  return round(T_c)
57
 
58
  ###################################
59
+ # 3) สูตรแรงโน้มถ่วง (ตามนิวตัน โดยคำนึงถึงความหนาแน่นตามชนิดดาว)
60
  ###################################
61
+ def approximate_gravity(diameter_factor, planet_type_th):
62
  """
63
+ คำนวณแรงโน้มถ่วงตามขนาดและชนิดดาว
64
  """
65
+ G = 6.67430e-11 # m³ kg⁻¹ s⁻²
66
+ earth_radius = 6.371e6 # meters
67
+ radius = diameter_factor * earth_radius # m
68
+
69
+ # กำหนดความหนาแน่นตามชนิดดาว
70
+ if planet_type_th == "ดาวหิน":
71
+ density = 5500 # kg/m³
72
+ elif planet_type_th == "ดาวก๊าซ":
73
+ density = 1300 # kg/m³
74
+ elif planet_type_th == "ดาวน้ำแข็ง":
75
+ density = 1600 # kg/m³
76
+ else:
77
+ density = 5500 # ค่าเริ่มต้นเป็นดาวหิน
78
+
79
+ # คำนวณมวล: M = density * volume = density * (4/3) * pi * R^3
80
+ mass = density * (4/3) * math.pi * radius**3
81
+
82
+ # คำนวณแรงโน้มถ่วง: g = G * M / R^2
83
+ g = G * mass / radius**2 # m/s²
84
+
85
+ # แปลงเป็น g ของโลก
86
+ g_earth = 9.81
87
+ g_relative = g / g_earth
88
+
89
+ return round(g_relative, 2)
90
 
91
  ###################################
92
  # 4) Dictionary แปลล่วงหน้า (TH->EN)
93
  ###################################
 
 
 
94
  pretranslated_map = {
95
  # distance
96
  "โคจรใกล้ดาวฤกษ์มาก": "orbits extremely close to its star",
 
116
  "เอียงปานกลาง ฤดูกาลเปลี่ยนแปลง": "moderately tilted, noticeable seasonal changes",
117
  "เอียงมาก ฤดูกาลสุดขั้ว": "highly tilted, extreme seasonal shifts",
118
 
119
+ # moons
120
+ "ไม่มีดวงจันทร์": "no moons",
121
+ "มีดวงจันทร์หนึ่งดวง": "one moon",
122
+ "มีดวงจันทร์สองดวง": "two moons",
123
+ "มีดวงจันทร์สามดวง": "three moons",
124
+ "มีดวงจันทร์สี่ดวง": "four moons",
125
+ "มีดวงจันทร์ห้าวง": "five moons",
126
+ "มีดวงจันทร์หกดวง": "six moons",
127
+ "มีดวงจันทร์เจ็ดดวง": "seven moons",
128
+ "มีดวงจันทร์แปดดวง": "eight moons",
129
+ "มีดวงจันทร์เก้าดวง": "nine moons",
130
+ "มีดวงจันทร์สิบดวง": "ten moons",
131
  }
132
 
133
  def describe_distance_th_to_en(desc_th):
 
142
  def describe_tilt_th_to_en(desc_th):
143
  return pretranslated_map.get(desc_th, "unknown axial tilt")
144
 
145
+ def describe_moons_th_to_en(desc_th):
146
+ return pretranslated_map.get(desc_th, "unknown moons")
147
+
148
+ def describe_oxygen_th_to_en(desc_th):
149
+ if desc_th == "ไม่มีออกซิเจน":
150
+ return "no oxygen"
151
+ elif desc_th == "ออกซิเจนน้อย":
152
+ return "low oxygen"
153
+ elif desc_th == "ออกซิเจนพอเหมาะ":
154
+ return "moderate oxygen"
155
+ else:
156
+ return "high oxygen"
157
+
158
  ###################################
159
  # ฟังก์ชันบรรยาย (ภาษาไทย)
160
  ###################################
 
164
  elif distance_au < 1.2:
165
  return "โคจรคล้ายโลกหรืออุ่นกว่านิดหน่อย"
166
  elif distance_au < 2.5:
167
+ return "โคจรห่างพอประมาณ อากาศค่อนข้างเย็น"
168
  else:
169
  return "โคจรไกลสุดข���้ว อากาศหนาวมาก"
170
 
 
203
  return "ไม่มีดวงจันทร์"
204
  elif n == 1:
205
  return "มีดวงจันทร์หนึ่งดวง"
206
+ elif n == 2:
207
+ return "มีดวงจันทร์สองดวง"
208
+ elif n == 3:
209
+ return "มีดวงจันทร์สามดวง"
210
+ elif n == 4:
211
+ return "มีดวงจันทร์สี่ดวง"
212
+ elif n == 5:
213
+ return "มีดวงจันทร์ห้าวง"
214
+ elif n == 6:
215
+ return "มีดวงจันทร์หกดวง"
216
+ elif n == 7:
217
+ return "มีดวงจันทร์เจ็ดดวง"
218
+ elif n == 8:
219
+ return "มีดวงจันทร์แปดดวง"
220
+ elif n == 9:
221
+ return "มีดวงจันทร์เก้าดวง"
222
+ elif n == 10:
223
+ return "มีดวงจันทร์สิบดวง"
224
  else:
225
+ return f"มีดวงจันทร์ {n} ดวง"
 
 
 
226
 
227
  def describe_oxygen(oxygen_percent):
228
  if oxygen_percent < 1:
 
243
  ):
244
  # Prompt 1
245
  prompt1 = (
246
+ f"A vibrant space painting of planet '{planet_name_en}' orbiting a {star_type_en} star. "
247
  f"It is {dist_desc_en}, with {temp_desc_en} conditions and {grav_desc_en} gravity. "
248
  f"{tilt_desc_en}, {moon_desc_en}, atmosphere has {oxygen_desc_en}. Cinematic details."
249
  )
 
260
  f"{tilt_desc_en} tilt, and {moon_desc_en}. Epic environment design, atmospheric perspective."
261
  )
262
 
263
+ return prompt1, prompt2, prompt3
 
 
 
 
 
264
 
265
  ###################################
266
  # 6) ฟังก์ชันหลัก generate_planet_info
 
297
  except:
298
  moon_count = 1
299
 
300
+ try:
301
+ oxygen_percent = float(oxygen_percent)
302
+ except:
303
+ oxygen_percent = 21.0
304
+
305
  # คำนวณ
306
  temp_c = approximate_temp_with_star(star_type_en, distance_au)
307
+ g_approx = approximate_gravity(diameter_factor, planet_type_th)
308
 
309
  # -----------------------------
310
  # (A) สรุปสำหรับเด็ก (ไทย)
311
  # -----------------------------
312
  child_summary = ""
313
  child_summary += f"สวัสดีหนูน้อยนักสำรวจ!\n\n"
314
+ child_summary += f"**{planet_name_th}** ที่หนูสร้าง เป็น{planet_type_th} "
315
+ child_summary += f"โคจรรอบดาวฤกษ์ **{star_type_en}**\n"
316
 
317
  child_summary += f"ระยะห่าง ~{distance_au} AU => ประเมินอุณหภูมิ ~{temp_c}°C\n"
318
  if temp_c < -20:
 
337
  else:
338
  child_summary += "มีฤดูกาลตามองศาเอียง\n"
339
 
340
+ child_summary += f"{describe_moons(moon_count)}\n"
341
  if moon_count > 2:
342
  child_summary += "น้ำขึ้นน้ำลงคงอลังการมาก\n"
343
 
 
347
  elif oxygen_percent > 30:
348
  child_summary += "สูงมาก ระวังไฟติดง่ายนะ\n"
349
 
350
+ child_summary += f"สิ่งมีชีวิต: **{life_th}**\n"
351
  child_summary += "ลองคิดดูสิว่าหน้าตาจะเป็นยังไง!\n\n"
352
  child_summary += "พร้อมลุยกันแล้วหรือยัง!?"
353
 
 
375
  planet_name_en = translate_th_to_en(planet_name_th)
376
  life_en = translate_th_to_en(life_th)
377
 
378
+ # 2) อธิบาย distance/temp/gravity/tilt/moon/oxygen เป็นภาษาไทย -> แปลเป็น EN
 
379
  dist_desc_th = describe_distance(distance_au)
380
  temp_desc_th = describe_temp(temp_c)
381
  grav_desc_th = describe_gravity(g_approx)
 
383
  moon_desc_th = describe_moons(moon_count)
384
  o2_desc_th = describe_oxygen(oxygen_percent)
385
 
386
+ # แปลงผ่าน Dictionary
387
+ dist_desc_en = describe_distance_th_to_en(dist_desc_th)
388
+ temp_desc_en = describe_temp_th_to_en(temp_desc_th)
389
+ grav_desc_en = describe_gravity_th_to_en(grav_desc_th)
390
+ tilt_desc_en = describe_tilt_th_to_en(tilt_desc_th)
391
+ moon_desc_en = describe_moons_th_to_en(moon_desc_th)
392
+ oxygen_desc_en = describe_oxygen_th_to_en(o2_desc_th)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
393
 
394
+ # 3) สร้าง Prompt
395
+ prompt1, prompt2, prompt3 = build_prompts_en(
396
  planet_name_en,
397
+ star_type_en,
398
  dist_desc_en,
399
  temp_desc_en,
400
  grav_desc_en,
 
404
  life_en
405
  )
406
 
407
+ return child_summary, detail_th, prompt1, prompt2, prompt3
408
 
409
  ###################################
410
  # สูตรโชว์
 
460
  border-radius: 10px;
461
  margin-right: 10px;
462
  }
463
+ #child-summary, #detail-th, #prompt1-en, #prompt2-en, #prompt3-en, #formula-box {
464
  background-color: #FFFDF5;
465
  border: 2px solid #FFE082;
466
  border-radius: 10px;
467
  padding: 10px;
468
  margin-bottom: 20px;
469
  }
470
+ .copy-btn {
471
+ background-color: #F06292;
472
+ border: 2px solid #E91E63;
473
+ font-weight: bold;
474
+ font-size: 0.8rem;
475
+ padding: 5px 10px;
476
+ border-radius: 5px;
477
+ margin-top: 5px;
478
+ }
479
  """
480
 
481
  def show_formula(state):
 
483
  return new_state, gr.update(visible=new_state)
484
 
485
  def welcome_text():
486
+ return "ยินดีต้อนรับสู่ **ZenityX Planetary Adventure**! ลองกรอกข้อมูลแล้วกด 'สร้างโลกแฟนตาซี' สิ!"
487
 
488
  with gr.Blocks(css=css_code) as demo:
489
  gr.Markdown("<h1 id='title'>ZenityX Planetary Adventure</h1>")
490
  gr.Markdown("""
491
  <div class="game-desc">
492
+ <p>พัฒนาโดย <strong>สถาบัน ZenityX AI Studio</strong></p>
493
+ <p>สร้างโลกแฟนตาซีของตัวเองด้วยการกรอกข้อมูลด้านล่าง! แล้วมาสนุกกับการสำรวจโลกใหม่กันเถอะ!</p>
494
  <p>ใส่ข้อมูล แล้วกด <strong>"สร้างโลกแฟนตาซี"</strong> เพื่อดู
495
  <em>สรุปสำหรับเด็ก</em>, <em>รายละเอียด (ไทย)</em>, และ <em>3 Prompts อังกฤษ</em></p>
496
+ <p>ถ้าต้องการดูสูตรคำนวณ กดปุ่ม "โชว์สูตรคำนวณ" ได้เลย!</p>
497
  </div>
498
  """)
499
 
 
505
 
506
  with gr.Row():
507
  with gr.Column():
508
+ planet_name_th = gr.Textbox(label="ชื่อดาวเคราะห์ (ไทย)", placeholder="เช่น ดาวซานาดา, ดาวโซลาริส...")
509
  star_type_en = gr.Dropdown(
510
  label="ประเภทดาวฤกษ์",
511
  choices=["Red Dwarf", "White Dwarf", "Sun-like", "Blue Giant", "Supergiant"],
512
  value="Sun-like"
513
  )
514
+ distance_au = gr.Textbox(label="ระยะห่าง AU (จำยนวนเท่าของระยะทางจากโลกถึงดวงอาทิตย์) ", placeholder="เช่น 1, 0.5, 2...")
515
+ diameter_factor = gr.Textbox(label="ขนาด (เท่าโลก)", placeholder="เช่น 1, 2, 0.5...")
 
 
 
 
 
516
  planet_type_th = gr.Dropdown(
517
  label="ชนิดดาวเคราะห์ (ไทย)",
518
  choices=["ดาวหิน", "ดาวก๊าซ", "ดาวน้ำแข็ง"],
519
  value="ดาวหิน"
520
  )
521
+
522
+ with gr.Column():
523
+ tilt_slider = gr.Slider(0, 90, step=1, value=23.5, label="แกนเอียง (องศา)")
524
+ moon_slider = gr.Slider(0, 10, step=1, value=1, label="จำนวนดวงจันทร์")
525
+ oxygen_slider = gr.Slider(0, 100, step=1, value=21, label="% ออกซิเจน")
526
+ life_th = gr.Textbox(label="สิ่งมีชีวิต (ไทย)", placeholder="เช่น แมลงยักษ์เรืองแสง...")
527
 
528
  create_btn = gr.Button("สร้างโลกแฟนตาซี", elem_classes="btn-main")
529
 
530
  child_summary_out = gr.Textbox(label="สรุปสำหรับเด็ก (ไทย)", interactive=False, elem_id="child-summary")
531
  detail_th_out = gr.Textbox(label="รายละเอียด (ไทย)", interactive=False, elem_id="detail-th")
532
+ prompt1_en_out = gr.Textbox(label="Prompt #1 (English)", interactive=False, elem_id="prompt1-en")
533
+ prompt2_en_out = gr.Textbox(label="Prompt #2 (English)", interactive=False, elem_id="prompt2-en")
534
+ prompt3_en_out = gr.Textbox(label="Prompt #3 (English)", interactive=False, elem_id="prompt3-en")
535
 
536
+ # ฟังก์ชันคัดลอก Prompt
537
  copy_button_html = """
538
+ <div style="display: flex; align-items: center; gap: 10px;">
539
+ <button class="copy-btn" onclick="copyText('prompt1')">คัดลอก Prompt #1</button>
540
+ <button class="copy-btn" onclick="copyText('prompt2')">คัดลอก Prompt #2</button>
541
+ <button class="copy-btn" onclick="copyText('prompt3')">คัดลอก Prompt #3</button>
542
+ </div>
543
  <script>
544
+ function copyText(promptId) {
545
+ const promptBox = document.querySelector(`#${promptId}-en textarea`);
546
  if (!promptBox) {
547
  alert('ไม่พบข้อความ Prompt!');
548
  return;
 
563
  star_type_en=s_type_en,
564
  distance_str=dist_au,
565
  diameter_str=dia_fac,
566
+ tilt_value=tilt_val,
567
+ moon_value=moon_val,
568
  oxygen_percent=oxy_val,
569
  planet_type_th=p_type_th,
570
  life_th=l_th
 
586
  outputs=[
587
  child_summary_out,
588
  detail_th_out,
589
+ prompt1_en_out,
590
+ prompt2_en_out,
591
+ prompt3_en_out
592
  ]
593
  )
594
 
 
 
 
595
  demo.load(fn=welcome_text, inputs=None, outputs=child_summary_out)
596
 
597
  demo.launch()