ChaoticEconomist commited on
Commit
630d6b3
·
verified ·
1 Parent(s): c1e69c8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -13
app.py CHANGED
@@ -83,11 +83,12 @@ def run_flow(blocks):
83
  def add_block(blocks, block_type):
84
  blocks.append(create_block(block_type))
85
 
86
- choices = [
87
- f"{i}: {b['title']}" for i, b in enumerate(blocks)
88
- ]
 
 
89
 
90
- return blocks, choices
91
 
92
  def load_block(blocks, selected):
93
  if not selected:
@@ -98,6 +99,7 @@ def load_block(blocks, selected):
98
 
99
  return b["var"], b["value"], b["prompt"], b["system"], b["output"]
100
 
 
101
  def save_block(blocks, selected, var, value, prompt, system):
102
  if not selected:
103
  return blocks
@@ -125,24 +127,24 @@ with gr.Blocks() as demo:
125
 
126
  with gr.Row():
127
 
128
- # ---------------- SIDEBAR ----------------
129
  with gr.Column(scale=1):
130
  gr.Markdown("## 🧩 Blocks")
131
-
132
  add_text = gr.Button("➕ Text Input")
133
  add_ai = gr.Button("➕ AI Block")
134
 
135
- # ---------------- CANVAS ----------------
136
  with gr.Column(scale=2):
137
  gr.Markdown("## 🧠 Canvas")
138
 
139
  block_list = gr.Radio(
140
  choices=[],
 
141
  label="Blocks",
142
  interactive=True
143
  )
144
 
145
- # ---------------- INSPECTOR ----------------
146
  with gr.Column(scale=2):
147
  gr.Markdown("## ⚙️ Inspector")
148
 
@@ -152,9 +154,8 @@ with gr.Blocks() as demo:
152
  system = gr.Textbox(label="System Prompt")
153
  output = gr.Textbox(label="Output", interactive=False)
154
 
155
- # ---------------- RUN ----------------
156
  run_btn = gr.Button("▶ Run Flow")
157
-
158
  variables_out = gr.JSON(label="Variables")
159
  logs = gr.Textbox(label="Logs")
160
 
@@ -163,13 +164,13 @@ with gr.Blocks() as demo:
163
  add_text.click(
164
  fn=lambda b: add_block(b, "text"),
165
  inputs=blocks_state,
166
- outputs=[blocks_state, block_list]
167
  )
168
 
169
  add_ai.click(
170
  fn=lambda b: add_block(b, "ai"),
171
  inputs=blocks_state,
172
- outputs=[blocks_state, block_list]
173
  )
174
 
175
  block_list.change(
@@ -208,7 +209,7 @@ with gr.Blocks() as demo:
208
  outputs=[blocks_state, variables_out, logs]
209
  )
210
 
211
- # ✅ FIXED CSS placement (Gradio 6+)
212
  demo.launch(css="""
213
  body { background-color: #0f172a; color: white; }
214
  """)
 
83
  def add_block(blocks, block_type):
84
  blocks.append(create_block(block_type))
85
 
86
+ choices = [f"{i}: {b['title']}" for i, b in enumerate(blocks)]
87
+
88
+ selected = choices[-1] if choices else None
89
+
90
+ return blocks, choices, selected
91
 
 
92
 
93
  def load_block(blocks, selected):
94
  if not selected:
 
99
 
100
  return b["var"], b["value"], b["prompt"], b["system"], b["output"]
101
 
102
+
103
  def save_block(blocks, selected, var, value, prompt, system):
104
  if not selected:
105
  return blocks
 
127
 
128
  with gr.Row():
129
 
130
+ # SIDEBAR
131
  with gr.Column(scale=1):
132
  gr.Markdown("## 🧩 Blocks")
 
133
  add_text = gr.Button("➕ Text Input")
134
  add_ai = gr.Button("➕ AI Block")
135
 
136
+ # CANVAS
137
  with gr.Column(scale=2):
138
  gr.Markdown("## 🧠 Canvas")
139
 
140
  block_list = gr.Radio(
141
  choices=[],
142
+ value=None,
143
  label="Blocks",
144
  interactive=True
145
  )
146
 
147
+ # INSPECTOR
148
  with gr.Column(scale=2):
149
  gr.Markdown("## ⚙️ Inspector")
150
 
 
154
  system = gr.Textbox(label="System Prompt")
155
  output = gr.Textbox(label="Output", interactive=False)
156
 
157
+ # RUN
158
  run_btn = gr.Button("▶ Run Flow")
 
159
  variables_out = gr.JSON(label="Variables")
160
  logs = gr.Textbox(label="Logs")
161
 
 
164
  add_text.click(
165
  fn=lambda b: add_block(b, "text"),
166
  inputs=blocks_state,
167
+ outputs=[blocks_state, block_list, block_list]
168
  )
169
 
170
  add_ai.click(
171
  fn=lambda b: add_block(b, "ai"),
172
  inputs=blocks_state,
173
+ outputs=[blocks_state, block_list, block_list]
174
  )
175
 
176
  block_list.change(
 
209
  outputs=[blocks_state, variables_out, logs]
210
  )
211
 
212
+ # ✅ CSS FIX (Gradio 6)
213
  demo.launch(css="""
214
  body { background-color: #0f172a; color: white; }
215
  """)