EngReem85 commited on
Commit
2592828
·
verified ·
1 Parent(s): 1acff7f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +153 -46
app.py CHANGED
@@ -329,7 +329,7 @@ def launch_mission(role, context, launch_command, state):
329
  {"role": "assistant", "content": orbit_response}
330
  ]
331
 
332
- fuel_status = f"⛽ {orbit_system.fuel:.1f}% متبقي (استهلك: {fuel_cost:.1f})"
333
 
334
  return orbit_response, state, orbit_system.orbit_state, orbit_system.fuel, fuel_status
335
 
@@ -422,7 +422,7 @@ def launch_mission(role, context, launch_command, state):
422
  "hallucination_score": quality_assessment["hallucination_score"]
423
  })
424
 
425
- fuel_status = f"⛽ {orbit_system.fuel:.1f}% متبقي (استهلك: {fuel_cost:.1f})"
426
 
427
  return formatted_response, state, orbit_system.orbit_state, orbit_system.fuel, fuel_status
428
 
@@ -474,7 +474,7 @@ def course_correction(correction, state):
474
  state["trajectory"].append({"role": "user", "content": correction})
475
  state["trajectory"].append({"role": "assistant", "content": demo_response})
476
 
477
- fuel_status = f"⛽ {orbit_system.fuel:.1f}% متبقي (استهلك: {fuel_cost:.1f})"
478
 
479
  return demo_response, state, orbit_system.orbit_state, orbit_system.fuel, fuel_status
480
 
@@ -524,7 +524,7 @@ def course_correction(correction, state):
524
 
525
  state["trajectory"].append({"role": "assistant", "content": orbit_response})
526
 
527
- fuel_status = f"⛽ {orbit_system.fuel:.1f}% متبقي (استهلك: {fuel_cost:.1f})"
528
 
529
  return formatted_response, state, orbit_system.orbit_state, orbit_system.fuel, fuel_status
530
 
@@ -550,6 +550,51 @@ def get_api_status():
550
  else:
551
  return "🟡 الوضع التجريبي (أضف API Key)"
552
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
553
  # ==============================
554
  # CSS فضائي محسن
555
  # ==============================
@@ -683,12 +728,40 @@ button:hover {
683
  backdrop-filter: blur(10px);
684
  }
685
 
686
- .fuel-gauge {
687
- background: linear-gradient(90deg, #4CAF50, #FF9800, #F44336);
688
- height: 20px;
689
- border-radius: 10px;
690
- margin: 10px 0;
691
- transition: width 0.5s ease;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
692
  }
693
 
694
  .api-status {
@@ -747,7 +820,7 @@ button:hover {
747
 
748
  .state-launch { background: rgba(255, 152, 0, 0.2); color: #ffcc80; }
749
  .state-orbit { background: rgba(76, 175, 80, 0.2); color: #c8e6c9; }
750
- -state-warning { background: rgba(255, 193, 7, 0.2); color: #fff59d; }
751
  .state-blackhole {
752
  background: linear-gradient(135deg, #4a1a1a, #8b0000);
753
  color: #ffcccc;
@@ -757,6 +830,60 @@ button:hover {
757
  background: linear-gradient(135deg, #1a5276, #3498db);
758
  color: #d6eaf8;
759
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
760
  """
761
 
762
  # ==============================
@@ -840,19 +967,12 @@ with gr.Blocks(css=css, title="🛰️ مدار الذكاء الاصطناعي
840
 
841
  fuel_display = gr.Textbox(
842
  label="⛽ مستوى الوقود",
843
- value="100%",
844
  interactive=False
845
  )
846
 
847
  # مقياس الوقود الديناميكي
848
- fuel_html = gr.HTML("""
849
- <div class="fuel-gauge" style="width: 100%;"></div>
850
- <div style="text-align: center; color: #cfd6b5; margin-top: 5px;">
851
- <span>🟢 ممتاز (70-100%)</span> |
852
- <span>🟡 متوسط (30-70%)</span> |
853
- <span>🔴 منخفض (0-30%)</span>
854
- </div>
855
- """)
856
 
857
  # عرض المدار
858
  orbit_display = gr.Markdown(
@@ -900,48 +1020,35 @@ with gr.Blocks(css=css, title="🛰️ مدار الذكاء الاصطناعي
900
 
901
  # حالة النظام
902
  state = gr.State({})
903
-
904
- # وظيفة لتحديث مقياس الوقود
905
- def update_fuel_gauge(fuel_level):
906
- fuel_percent = max(0, min(100, fuel_level))
907
- color = "#4CAF50" if fuel_percent > 70 else "#FF9800" if fuel_percent > 30 else "#F44336"
908
-
909
- return f"""
910
- <div class="fuel-gauge" style="width: {fuel_percent}%; background: linear-gradient(90deg, {color}, {color});"></div>
911
- <div style="text-align: center; color: #cfd6b5; margin-top: 5px;">
912
- <span>🟢 ممتاز (70-100%)</span> |
913
- <span>🟡 متوسط (30-70%)</span> |
914
- <span>🔴 منخفض (0-30%)</span>
915
- </div>
916
- """
917
 
918
  # ربط الأحداث
919
  launch_btn.click(
920
  launch_mission,
921
  inputs=[role, context, launch_command, state],
922
- outputs=[orbit_display, state, orbit_status, gr.Number(visible=False), fuel_display]
923
  ).then(
924
- lambda fuel: (f"⛽ {fuel:.1f}%", update_fuel_gauge(fuel)),
925
- inputs=[gr.Number(visible=False)],
926
- outputs=[fuel_display, fuel_html]
927
  )
928
 
929
  refine_btn.click(
930
  course_correction,
931
  inputs=[correction, state],
932
- outputs=[orbit_display, state, orbit_status, gr.Number(visible=False), fuel_display]
933
  ).then(
934
- lambda fuel: (f"⛽ {fuel:.1f}%", update_fuel_gauge(fuel)),
935
- inputs=[gr.Number(visible=False)],
936
- outputs=[fuel_display, fuel_html]
937
  )
938
 
939
  reset_btn.click(
940
- reset_system,
941
- outputs=[orbit_display, state, orbit_status, gr.Number(visible=False), fuel_display]
942
  ).then(
943
- lambda: ("🚀 على منصة الإطلاق", "⛽ 100%", update_fuel_gauge(100)),
944
- outputs=[orbit_status, fuel_display, fuel_html]
945
  )
946
 
947
  # ==============================
 
329
  {"role": "assistant", "content": orbit_response}
330
  ]
331
 
332
+ fuel_status = f"⛽ {orbit_system.fuel:.1f}% متبقي (استهلك: {fuel_cost:.1f}%)"
333
 
334
  return orbit_response, state, orbit_system.orbit_state, orbit_system.fuel, fuel_status
335
 
 
422
  "hallucination_score": quality_assessment["hallucination_score"]
423
  })
424
 
425
+ fuel_status = f"⛽ {orbit_system.fuel:.1f}% متبقي (استهلك: {fuel_cost:.1f}%)"
426
 
427
  return formatted_response, state, orbit_system.orbit_state, orbit_system.fuel, fuel_status
428
 
 
474
  state["trajectory"].append({"role": "user", "content": correction})
475
  state["trajectory"].append({"role": "assistant", "content": demo_response})
476
 
477
+ fuel_status = f"⛽ {orbit_system.fuel:.1f}% متبقي (استهلك: {fuel_cost:.1f}%)"
478
 
479
  return demo_response, state, orbit_system.orbit_state, orbit_system.fuel, fuel_status
480
 
 
524
 
525
  state["trajectory"].append({"role": "assistant", "content": orbit_response})
526
 
527
+ fuel_status = f"⛽ {orbit_system.fuel:.1f}% متبقي (استهلك: {fuel_cost:.1f}%)"
528
 
529
  return formatted_response, state, orbit_system.orbit_state, orbit_system.fuel, fuel_status
530
 
 
550
  else:
551
  return "🟡 الوضع التجريبي (أضف API Key)"
552
 
553
+ # ==============================
554
+ # تحديث مقياس الوقود
555
+ # ==============================
556
+ def update_fuel_gauge(fuel_level):
557
+ """تحديث مقياس الوقود بشكل صحيح"""
558
+ fuel_percent = max(0, min(100, fuel_level))
559
+
560
+ # تحديد اللون بناءً على النسبة
561
+ if fuel_percent > 70:
562
+ gradient = "linear-gradient(90deg, #4CAF50, #8BC34A)"
563
+ emoji = "🟢"
564
+ status = "ممتاز"
565
+ elif fuel_percent > 30:
566
+ gradient = "linear-gradient(90deg, #FF9800, #FFB74D)"
567
+ emoji = "🟡"
568
+ status = "متوسط"
569
+ else:
570
+ gradient = "linear-gradient(90deg, #F44336, #EF5350)"
571
+ emoji = "🔴"
572
+ status = "منخفض"
573
+
574
+ return f"""
575
+ <div style="margin: 15px 0;">
576
+ <div style="display: flex; justify-content: space-between; margin-bottom: 5px;">
577
+ <span style="color: #cfd6b5; font-weight: bold;">{emoji} حالة الوقود: {status}</span>
578
+ <span style="color: #cfd6b5; font-weight: bold;">{fuel_percent:.1f}%</span>
579
+ </div>
580
+
581
+ <div style="width: 100%; height: 25px; background: rgba(40, 40, 40, 0.5); border-radius: 15px; overflow: hidden; position: relative;">
582
+ <div class="fuel-fill" style="width: {fuel_percent}%; height: 100%; background: {gradient}; transition: width 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);"></div>
583
+
584
+ <!-- علامات النسبة -->
585
+ <div style="position: absolute; left: 30%; top: 0; height: 100%; width: 2px; background: rgba(255,255,255,0.2);"></div>
586
+ <div style="position: absolute; left: 70%; top: 0; height: 100%; width: 2px; background: rgba(255,255,255,0.2);"></div>
587
+ </div>
588
+
589
+ <div style="display: flex; justify-content: space-between; margin-top: 5px; font-size: 0.8em; color: #aaa;">
590
+ <span>0%</span>
591
+ <span>30%</span>
592
+ <span>70%</span>
593
+ <span>100%</span>
594
+ </div>
595
+ </div>
596
+ """
597
+
598
  # ==============================
599
  # CSS فضائي محسن
600
  # ==============================
 
728
  backdrop-filter: blur(10px);
729
  }
730
 
731
+ .fuel-fill {
732
+ position: relative;
733
+ overflow: hidden;
734
+ }
735
+
736
+ .fuel-fill::after {
737
+ content: '';
738
+ position: absolute;
739
+ top: 0;
740
+ left: 0;
741
+ right: 0;
742
+ bottom: 0;
743
+ background: linear-gradient(
744
+ 90deg,
745
+ transparent 0%,
746
+ rgba(255, 255, 255, 0.2) 50%,
747
+ transparent 100%
748
+ );
749
+ animation: fuelShine 3s infinite;
750
+ }
751
+
752
+ @keyframes fuelShine {
753
+ 0% { transform: translateX(-100%); }
754
+ 100% { transform: translateX(100%); }
755
+ }
756
+
757
+ .fuel-warning {
758
+ animation: fuelPulse 2s infinite;
759
+ }
760
+
761
+ @keyframes fuelPulse {
762
+ 0% { opacity: 1; }
763
+ 50% { opacity: 0.7; }
764
+ 100% { opacity: 1; }
765
  }
766
 
767
  .api-status {
 
820
 
821
  .state-launch { background: rgba(255, 152, 0, 0.2); color: #ffcc80; }
822
  .state-orbit { background: rgba(76, 175, 80, 0.2); color: #c8e6c9; }
823
+ .state-warning { background: rgba(255, 193, 7, 0.2); color: #fff59d; }
824
  .state-blackhole {
825
  background: linear-gradient(135deg, #4a1a1a, #8b0000);
826
  color: #ffcccc;
 
830
  background: linear-gradient(135deg, #1a5276, #3498db);
831
  color: #d6eaf8;
832
  }
833
+
834
+ .response-box {
835
+ background: linear-gradient(135deg, rgba(20, 25, 20, 0.9), rgba(10, 15, 10, 0.95));
836
+ border-left: 4px solid #7a8450;
837
+ padding: 20px;
838
+ border-radius: 10px;
839
+ margin: 10px 0;
840
+ animation: fadeIn 0.5s ease-out;
841
+ }
842
+
843
+ @keyframes fadeIn {
844
+ from { opacity: 0; transform: translateY(10px); }
845
+ to { opacity: 1; transform: translateY(0); }
846
+ }
847
+
848
+ .rocket-launch {
849
+ position: relative;
850
+ overflow: hidden;
851
+ }
852
+
853
+ .rocket-launch::after {
854
+ content: "🚀";
855
+ position: absolute;
856
+ right: -50px;
857
+ animation: rocketFly 2s ease-out;
858
+ }
859
+
860
+ @keyframes rocketFly {
861
+ 0% { transform: translateX(0) translateY(0); opacity: 1; }
862
+ 100% { transform: translateX(-100vw) translateY(-100vh); opacity: 0; }
863
+ }
864
+
865
+ @media (max-width: 768px) {
866
+ .gradio-container {
867
+ padding: 10px;
868
+ }
869
+
870
+ h1 {
871
+ font-size: 1.5em;
872
+ }
873
+
874
+ button {
875
+ padding: 15px !important;
876
+ font-size: 1.1em;
877
+ }
878
+
879
+ textarea {
880
+ font-size: 16px;
881
+ }
882
+
883
+ .planet-1, .planet-2 {
884
+ display: none;
885
+ }
886
+ }
887
  """
888
 
889
  # ==============================
 
967
 
968
  fuel_display = gr.Textbox(
969
  label="⛽ مستوى الوقود",
970
+ value="100% (ممتلئ)",
971
  interactive=False
972
  )
973
 
974
  # مقياس الوقود الديناميكي
975
+ fuel_html = gr.HTML(update_fuel_gauge(100))
 
 
 
 
 
 
 
976
 
977
  # عرض المدار
978
  orbit_display = gr.Markdown(
 
1020
 
1021
  # حالة النظام
1022
  state = gr.State({})
1023
+ current_fuel = gr.State(100) # متغير لحفظ الوقود الحالي
 
 
 
 
 
 
 
 
 
 
 
 
 
1024
 
1025
  # ربط الأحداث
1026
  launch_btn.click(
1027
  launch_mission,
1028
  inputs=[role, context, launch_command, state],
1029
+ outputs=[orbit_display, state, orbit_status, current_fuel, fuel_display]
1030
  ).then(
1031
+ lambda fuel: update_fuel_gauge(fuel),
1032
+ inputs=[current_fuel],
1033
+ outputs=[fuel_html]
1034
  )
1035
 
1036
  refine_btn.click(
1037
  course_correction,
1038
  inputs=[correction, state],
1039
+ outputs=[orbit_display, state, orbit_status, current_fuel, fuel_display]
1040
  ).then(
1041
+ lambda fuel: update_fuel_gauge(fuel),
1042
+ inputs=[current_fuel],
1043
+ outputs=[fuel_html]
1044
  )
1045
 
1046
  reset_btn.click(
1047
+ lambda: (reset_system(), 100),
1048
+ outputs=[orbit_display, state, orbit_status, current_fuel, fuel_display]
1049
  ).then(
1050
+ lambda: (update_fuel_gauge(100), "⛽ 100% (ممتلئ)"),
1051
+ outputs=[fuel_html, fuel_display]
1052
  )
1053
 
1054
  # ==============================