mohammed-aljafry commited on
Commit
97c9dda
·
verified ·
1 Parent(s): 8eef426

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -34
app.py CHANGED
@@ -149,16 +149,16 @@ CUSTOM_CSS = ".gradio-container {max-width: 100% !important;}"
149
  with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="sky"), css=CUSTOM_CSS) as demo:
150
  session_id_state = gr.State(value=None)
151
 
152
- gr.Markdown("# 🚗 واجهة التحكم لنظام Baseer للقيادة الذاتية")
153
- gr.Markdown("هذه الواجهة تعمل كـ **عميل (Client)** يتصل بـ **[Baseer Self-Driving API](https://huggingface.co/spaces/BaseerAI/baseer-server)** لمعالجة البيانات.")
154
  gr.Markdown("---")
155
 
156
  with gr.Group():
157
- gr.Markdown("## ⚙️ التحكم بالجلسة")
158
  with gr.Row():
159
- start_session_button = gr.Button("🟢 بدء جلسة جديدة", variant="primary")
160
- end_session_button = gr.Button("🔴 إنهاء الجلسة الحالية")
161
- status_textbox = gr.Textbox(label="حالة الجلسة", interactive=False, value="في انتظار بدء الجلسة...")
162
 
163
  gr.Markdown("")
164
 
@@ -166,58 +166,48 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="sky"), cs
166
  with gr.Row(equal_height=False):
167
  with gr.Column(scale=2):
168
  with gr.Group():
169
- gr.Markdown("### 🗂️ ارفع ملفات السيناريو")
170
- api_rgb_image_path = gr.Image(type="filepath", label="(RGB)")
171
- api_measurements_path = gr.File(label="(JSON)", type="filepath")
172
- api_run_button = gr.Button("🚀 أرسل البيانات للمعالجة", variant="primary")
173
 
174
  with gr.Group():
175
- gr.Markdown("### ✨ أمثلة جاهزة")
176
  if SAMPLES_FOR_DISPLAY:
177
- # --- دالة التحديد ---
178
  def on_example_select(evt: gr.SelectData):
179
- # evt.index هو رقم الصف الذي تم الضغط عليه
180
  selected_example = FULL_EXAMPLES_DATA[evt.index]
181
  return gr.update(value=selected_example["img_path"]), gr.update(value=selected_example["json_path"])
182
-
183
- # --- استخدام gr.Dataset مع إخفاء المكونات ---
184
- with gr.Column(visible=False): # المكونات التي تظهر فوق الجدول سيتم طيّها داخل هذا الـ Accordion
185
- example_image = gr.Image(label="الصورة", type="filepath")
186
- example_speed = gr.Textbox(label="السرعة")
187
- example_theta = gr.Textbox(label="الاتجاه")
188
- example_position = gr.Textbox(label="الموقع")
189
- example_target = gr.Textbox(label="الهدف")
190
 
191
  example_components = [example_image, example_speed, example_theta, example_position, example_target]
192
 
193
  if SAMPLES_FOR_DISPLAY:
194
- # --- دالة التحديد ---
195
- def on_example_select(evt: gr.SelectData):
196
- selected_example = FULL_EXAMPLES_DATA[evt.index]
197
- return gr.update(value=selected_example["img_path"]), gr.update(value=selected_example["json_path"])
198
-
199
- # --- الجدول بدون عرض المكونات العلوية بشكل مزعج ---
200
  example_dataset = gr.Dataset(
201
  components=example_components,
202
  samples=SAMPLES_FOR_DISPLAY,
203
- label="اختر سيناريو اختبار"
204
  )
205
 
206
- # --- ربط حدث التحديد بالدالة ---
207
  example_dataset.select(
208
  fn=on_example_select,
209
  inputs=None,
210
  outputs=[api_rgb_image_path, api_measurements_path]
211
  )
212
  else:
213
- gr.Markdown("لم يتم العثور على أمثلة صالحة.")
214
 
215
-
216
  with gr.Column(scale=3):
217
  with gr.Group():
218
- gr.Markdown("### 📊 النتائج من الخادم")
219
- api_output_image = gr.Image(label="لوحة التحكم المرئية (من الـ API)", type="pil", interactive=False, height=600)
220
- api_control_json = gr.JSON(label="أوامر التحكم (من الـ API)")
 
221
 
222
  start_session_button.click(fn=start_new_session, inputs=None, outputs=[session_id_state, status_textbox, main_controls_group])
223
  end_session_button.click(fn=handle_end_session, inputs=[session_id_state], outputs=[status_textbox, session_id_state, main_controls_group])
 
149
  with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="sky"), css=CUSTOM_CSS) as demo:
150
  session_id_state = gr.State(value=None)
151
 
152
+ gr.Markdown("# 🚗 Baseer Self-Driving System Dashboard")
153
+ gr.Markdown("This interface acts as a **client** that connects to the **[Baseer Self-Driving API](https://huggingface.co/spaces/BaseerAI/baseer-server)** for data processing.")
154
  gr.Markdown("---")
155
 
156
  with gr.Group():
157
+ gr.Markdown("## ⚙️ Session Control")
158
  with gr.Row():
159
+ start_session_button = gr.Button("🟢 Start New Session", variant="primary")
160
+ end_session_button = gr.Button("🔴 End Current Session")
161
+ status_textbox = gr.Textbox(label="Session Status", interactive=False, value="Waiting to start session...")
162
 
163
  gr.Markdown("")
164
 
 
166
  with gr.Row(equal_height=False):
167
  with gr.Column(scale=2):
168
  with gr.Group():
169
+ gr.Markdown("### 🗂️ Upload Scenario Files")
170
+ api_rgb_image_path = gr.Image(type="filepath", label="(RGB Image)")
171
+ api_measurements_path = gr.File(label="(Measurements JSON)", type="filepath")
172
+ api_run_button = gr.Button("🚀 Send Data for Processing", variant="primary")
173
 
174
  with gr.Group():
175
+ gr.Markdown("### ✨ Preloaded Examples")
176
  if SAMPLES_FOR_DISPLAY:
 
177
  def on_example_select(evt: gr.SelectData):
 
178
  selected_example = FULL_EXAMPLES_DATA[evt.index]
179
  return gr.update(value=selected_example["img_path"]), gr.update(value=selected_example["json_path"])
180
+
181
+ with gr.Column(visible=False):
182
+ example_image = gr.Image(label="Image", type="filepath")
183
+ example_speed = gr.Textbox(label="Speed")
184
+ example_theta = gr.Textbox(label="Direction (theta)")
185
+ example_position = gr.Textbox(label="Position")
186
+ example_target = gr.Textbox(label="Target Point")
 
187
 
188
  example_components = [example_image, example_speed, example_theta, example_position, example_target]
189
 
190
  if SAMPLES_FOR_DISPLAY:
 
 
 
 
 
 
191
  example_dataset = gr.Dataset(
192
  components=example_components,
193
  samples=SAMPLES_FOR_DISPLAY,
194
+ label="Select Test Scenario"
195
  )
196
 
 
197
  example_dataset.select(
198
  fn=on_example_select,
199
  inputs=None,
200
  outputs=[api_rgb_image_path, api_measurements_path]
201
  )
202
  else:
203
+ gr.Markdown("No valid examples found.")
204
 
 
205
  with gr.Column(scale=3):
206
  with gr.Group():
207
+ gr.Markdown("### 📊 Results from API")
208
+ api_output_image = gr.Image(label="Dashboard Image (from API)", type="pil", interactive=False, height=600)
209
+ api_control_json = gr.JSON(label="Control Commands (from API)")
210
+
211
 
212
  start_session_button.click(fn=start_new_session, inputs=None, outputs=[session_id_state, status_textbox, main_controls_group])
213
  end_session_button.click(fn=handle_end_session, inputs=[session_id_state], outputs=[status_textbox, session_id_state, main_controls_group])