Update app.py
Browse files
app.py
CHANGED
@@ -104,12 +104,39 @@ def run_single_frame_via_api(session_id, rgb_image_path, measurements_path):
|
|
104 |
raise gr.Error(f"حدث خطأ أثناء الاتصال بالـ API: {e}")
|
105 |
except Exception as e:
|
106 |
raise gr.Error(f"حدث خطأ غير متوقع: {e}")
|
107 |
-
|
108 |
# ==============================================================================
|
109 |
# 4. تعريف واجهة Gradio
|
110 |
# ==============================================================================
|
111 |
|
112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
session_id_state = gr.State(value=None)
|
114 |
|
115 |
gr.Markdown("# 🚗 واجهة التحكم لنظام Baseer للقيادة الذاتية")
|
@@ -126,39 +153,44 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="sky"), cs
|
|
126 |
gr.Markdown("")
|
127 |
|
128 |
with gr.Group(visible=False) as main_controls_group:
|
129 |
-
|
|
|
130 |
with gr.Column(scale=2):
|
131 |
with gr.Group():
|
132 |
gr.Markdown("### 🗂️ ارفع ملفات السيناريو")
|
133 |
api_rgb_image_path = gr.Image(type="filepath", label="صورة الكاميرا الأمامية (RGB)")
|
134 |
-
# api_rgb_image_path = gr.Image(type="filepath", label="صورة الكاميرا الأمامية (RGB)",height=500)
|
135 |
api_measurements_path = gr.File(label="ملف القياسات (JSON)", type="filepath")
|
136 |
api_run_button = gr.Button("🚀 أرسل البيانات للمعالجة", variant="primary")
|
137 |
|
138 |
-
gr.Markdown("")
|
139 |
with gr.Column(scale=3):
|
140 |
with gr.Group():
|
141 |
gr.Markdown("### 📊 النتائج من الخادم")
|
142 |
-
api_output_image = gr.Image(label="لوحة التحكم المرئية (من الـ API)", type="pil", interactive=False,height=600)
|
143 |
api_control_json = gr.JSON(label="أوامر التحكم (من الـ API)")
|
|
|
144 |
with gr.Row():
|
145 |
with gr.Group():
|
146 |
-
gr.Markdown("
|
147 |
if os.path.isdir(EXAMPLES_DIR) and \
|
148 |
os.path.exists(os.path.join(EXAMPLES_DIR, "sample1", "measurements.json")) and \
|
149 |
-
os.path.exists(os.path.join(EXAMPLES_DIR, "sample2", "measurements.json"))and \
|
150 |
os.path.exists(os.path.join(EXAMPLES_DIR, "sample3", "measurements.json")):
|
|
|
151 |
with open(os.path.join(EXAMPLES_DIR, "sample1", "measurements.json"), 'r') as f:
|
152 |
data1 = json.load(f)
|
153 |
with open(os.path.join(EXAMPLES_DIR, "sample2", "measurements.json"), 'r') as f:
|
154 |
data2 = json.load(f)
|
155 |
with open(os.path.join(EXAMPLES_DIR, "sample3", "measurements.json"), 'r') as f:
|
156 |
data3 = json.load(f)
|
|
|
|
|
157 |
with gr.Column(visible=False):
|
158 |
example_speed = gr.Textbox(label="السرعة (m/s)")
|
159 |
example_theta = gr.Textbox(label="الاتجاه (Theta)")
|
160 |
example_pos = gr.Textbox(label="الموقع العام")
|
161 |
example_target = gr.Textbox(label="النقطة المستهدفة")
|
|
|
|
|
162 |
gr.Examples(
|
163 |
examples=[
|
164 |
[
|
@@ -194,13 +226,11 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="sky"), cs
|
|
194 |
example_target
|
195 |
],
|
196 |
label="اختر سيناريو اختبار",
|
197 |
-
|
198 |
)
|
199 |
else:
|
200 |
gr.Markdown("لم يتم العثور على مجلد الأمثلة (`examples`) أو محتوياته.")
|
201 |
|
202 |
-
|
203 |
-
|
204 |
# --- ربط منطق الواجهة ---
|
205 |
start_session_button.click(
|
206 |
fn=start_new_session,
|
|
|
104 |
raise gr.Error(f"حدث خطأ أثناء الاتصال بالـ API: {e}")
|
105 |
except Exception as e:
|
106 |
raise gr.Error(f"حدث خطأ غير متوقع: {e}")
|
|
|
107 |
# ==============================================================================
|
108 |
# 4. تعريف واجهة Gradio
|
109 |
# ==============================================================================
|
110 |
|
111 |
+
# --- الخطوة 1: تعريف متغير CSS للتحكم في الأعمدة ---
|
112 |
+
CUSTOM_CSS = """
|
113 |
+
/* القاعدة الأساسية لتوسيع الواجهة */
|
114 |
+
.gradio-container {max-width: 100% !important;}
|
115 |
+
|
116 |
+
/* استهداف الجدول الذي أعطيناه اسم 'examples-table' */
|
117 |
+
.examples-table .gradio-table {
|
118 |
+
table-layout: fixed; /* ضروري للتحكم الدقيق في العرض */
|
119 |
+
width: 100%;
|
120 |
+
}
|
121 |
+
|
122 |
+
/* العمود الثاني (ملف القياسات): عرض ثابت وصغير */
|
123 |
+
.examples-table .gradio-table th:nth-child(2),
|
124 |
+
.examples-table .gradio-table td:nth-child(2) {
|
125 |
+
width: 200px !important; /* يمكنك تعديل هذه القيمة */
|
126 |
+
white-space: nowrap; /* لمنع التفاف اسم الملف الطويل */
|
127 |
+
overflow: hidden; /* إخفاء النص الزائد */
|
128 |
+
text-overflow: ellipsis; /* إضافة "..." للنص المقطوع */
|
129 |
+
}
|
130 |
+
|
131 |
+
/* الأعمدة من الثالث فصاعداً (البيانات الرقمية): عرض أصغر ومحاذاة للمنتصف */
|
132 |
+
.examples-table .gradio-table th:nth-child(n+3),
|
133 |
+
.examples-table .gradio-table td:nth-child(n+3) {
|
134 |
+
width: 160px !important; /* يمكنك تعديل هذه القيمة */
|
135 |
+
text-align: center !important;
|
136 |
+
}
|
137 |
+
"""
|
138 |
+
|
139 |
+
with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="sky"), css=CUSTOM_CSS) as demo:
|
140 |
session_id_state = gr.State(value=None)
|
141 |
|
142 |
gr.Markdown("# 🚗 واجهة التحكم لنظام Baseer للقيادة الذاتية")
|
|
|
153 |
gr.Markdown("")
|
154 |
|
155 |
with gr.Group(visible=False) as main_controls_group:
|
156 |
+
# --- إضافة 'equal_height=True' هنا ---
|
157 |
+
with gr.Row(equal_height=True):
|
158 |
with gr.Column(scale=2):
|
159 |
with gr.Group():
|
160 |
gr.Markdown("### 🗂️ ارفع ملفات السيناريو")
|
161 |
api_rgb_image_path = gr.Image(type="filepath", label="صورة الكاميرا الأمامية (RGB)")
|
|
|
162 |
api_measurements_path = gr.File(label="ملف القياسات (JSON)", type="filepath")
|
163 |
api_run_button = gr.Button("🚀 أرسل البيانات للمعالجة", variant="primary")
|
164 |
|
|
|
165 |
with gr.Column(scale=3):
|
166 |
with gr.Group():
|
167 |
gr.Markdown("### 📊 النتائج من الخادم")
|
168 |
+
api_output_image = gr.Image(label="لوحة التحكم المرئية (من الـ API)", type="pil", interactive=False, height=600)
|
169 |
api_control_json = gr.JSON(label="أوامر التحكم (من الـ API)")
|
170 |
+
|
171 |
with gr.Row():
|
172 |
with gr.Group():
|
173 |
+
gr.Markdown("### ✨ أمثلة جاهزة")
|
174 |
if os.path.isdir(EXAMPLES_DIR) and \
|
175 |
os.path.exists(os.path.join(EXAMPLES_DIR, "sample1", "measurements.json")) and \
|
176 |
+
os.path.exists(os.path.join(EXAMPLES_DIR, "sample2", "measurements.json")) and \
|
177 |
os.path.exists(os.path.join(EXAMPLES_DIR, "sample3", "measurements.json")):
|
178 |
+
|
179 |
with open(os.path.join(EXAMPLES_DIR, "sample1", "measurements.json"), 'r') as f:
|
180 |
data1 = json.load(f)
|
181 |
with open(os.path.join(EXAMPLES_DIR, "sample2", "measurements.json"), 'r') as f:
|
182 |
data2 = json.load(f)
|
183 |
with open(os.path.join(EXAMPLES_DIR, "sample3", "measurements.json"), 'r') as f:
|
184 |
data3 = json.load(f)
|
185 |
+
|
186 |
+
# استخدام عمود مخفي هو الطريقة الصحيحة لتجنب الفوضى في الواجهة
|
187 |
with gr.Column(visible=False):
|
188 |
example_speed = gr.Textbox(label="السرعة (m/s)")
|
189 |
example_theta = gr.Textbox(label="الاتجاه (Theta)")
|
190 |
example_pos = gr.Textbox(label="الموقع العام")
|
191 |
example_target = gr.Textbox(label="النقطة المستهدفة")
|
192 |
+
|
193 |
+
# --- إضافة 'elem_classes' هنا ---
|
194 |
gr.Examples(
|
195 |
examples=[
|
196 |
[
|
|
|
226 |
example_target
|
227 |
],
|
228 |
label="اختر سيناريو اختبار",
|
229 |
+
elem_classes="examples-table"
|
230 |
)
|
231 |
else:
|
232 |
gr.Markdown("لم يتم العثور على مجلد الأمثلة (`examples`) أو محتوياته.")
|
233 |
|
|
|
|
|
234 |
# --- ربط منطق الواجهة ---
|
235 |
start_session_button.click(
|
236 |
fn=start_new_session,
|