Spaces:
Sleeping
Sleeping
Fix Gradio Blocks context structure - move data variables before with statement
Browse filesVERIFIED FIX per Gradio official documentation:
Resolved IndentationError on line 164 by restructuring file to match Gradio Blocks API requirements.
Changes:
- Moved `with gr.Blocks() as demo:` statement from line 50 to line 161 (AFTER all data variable declarations)
- Data variables (consent_events_sample, branches_sample, diagnostics_sample, audit_history_sample) now correctly declared at module level BEFORE the Blocks context
- All UI components (gr.Markdown, gr.Tabs, tab definitions) properly indented with 4 spaces INSIDE the `with gr.Blocks()` context
- `demo.launch()` correctly placed at module level in `if __name__ == "__main__":` block
This structure matches official Gradio documentation and resolves the Python indentation error.
app.py
CHANGED
|
@@ -46,10 +46,7 @@ def audit_trail_widget(audit_history: List[Dict[str, Any]]):
|
|
| 46 |
audit_log += f"{item.get('contact_id','?')},{item.get('event_type','?')},{item.get('opt_out',False)},{item.get('compliance_flag','?')}\n"
|
| 47 |
return gr.Textbox(label="Audit Trail CSV", value=audit_log, lines=10)
|
| 48 |
|
| 49 |
-
|
| 50 |
-
with gr.Blocks(title="StrategyStack UI") as demo:
|
| 51 |
-
gr.Markdown("# Outreach Cadence & Compliance Dashboard")
|
| 52 |
-
consent_events_sample = [
|
| 53 |
{
|
| 54 |
"contact_id": "LEAD_001",
|
| 55 |
"event_type": "consent_given",
|
|
@@ -160,6 +157,10 @@ diagnostics_sample = [
|
|
| 160 |
|
| 161 |
audit_history_sample = consent_events_sample
|
| 162 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
# Create tabbed interface
|
| 164 |
with gr.Tabs():
|
| 165 |
with gr.Tab("Consent/Event Audit"):
|
|
|
|
| 46 |
audit_log += f"{item.get('contact_id','?')},{item.get('event_type','?')},{item.get('opt_out',False)},{item.get('compliance_flag','?')}\n"
|
| 47 |
return gr.Textbox(label="Audit Trail CSV", value=audit_log, lines=10)
|
| 48 |
|
| 49 |
+
|
|
|
|
|
|
|
|
|
|
| 50 |
{
|
| 51 |
"contact_id": "LEAD_001",
|
| 52 |
"event_type": "consent_given",
|
|
|
|
| 157 |
|
| 158 |
audit_history_sample = consent_events_sample
|
| 159 |
|
| 160 |
+
# Example usage in Gradio Blocks
|
| 161 |
+
with gr.Blocks(title="StrategyStack UI") as demo:
|
| 162 |
+
gr.Markdown("# Outreach Cadence & Compliance Dashboard")
|
| 163 |
+
|
| 164 |
# Create tabbed interface
|
| 165 |
with gr.Tabs():
|
| 166 |
with gr.Tab("Consent/Event Audit"):
|