Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,7 @@ import gradio as gr
|
|
| 2 |
import requests
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
# Read backend URL from Hugging Face secret
|
| 6 |
BACKEND_URL = os.environ.get("KERNL_BACKEND_URL", "").rstrip('/')
|
| 7 |
|
| 8 |
if not BACKEND_URL:
|
|
@@ -11,7 +11,7 @@ if not BACKEND_URL:
|
|
| 11 |
def query_kernl(scenario, with_brain):
|
| 12 |
"""Call the Kernl /agent/handle endpoint and format the response."""
|
| 13 |
if not BACKEND_URL:
|
| 14 |
-
return "β Backend URL not configured. Please set the KERNL_BACKEND_URL secret
|
| 15 |
|
| 16 |
if not scenario or not scenario.strip():
|
| 17 |
return "β Please enter a scenario."
|
|
@@ -29,7 +29,6 @@ def query_kernl(scenario, with_brain):
|
|
| 29 |
response.raise_for_status()
|
| 30 |
data = response.json()
|
| 31 |
|
| 32 |
-
# Format the response nicely
|
| 33 |
output = []
|
| 34 |
output.append(f"**Action:** `{data.get('action', 'N/A')}`")
|
| 35 |
output.append(f"**Rule Applied:** `{data.get('rule_applied', 'N/A')}`")
|
|
@@ -42,13 +41,13 @@ def query_kernl(scenario, with_brain):
|
|
| 42 |
return "\n\n".join(output)
|
| 43 |
|
| 44 |
except requests.exceptions.ConnectionError:
|
| 45 |
-
return "β Cannot connect to Kernl backend.
|
| 46 |
except requests.exceptions.Timeout:
|
| 47 |
-
return "β Request timed out.
|
| 48 |
except Exception as e:
|
| 49 |
return f"β Error: {str(e)}"
|
| 50 |
|
| 51 |
-
#
|
| 52 |
theme = gr.themes.Soft(
|
| 53 |
primary_hue="teal",
|
| 54 |
secondary_hue="teal",
|
|
|
|
| 2 |
import requests
|
| 3 |
import os
|
| 4 |
|
| 5 |
+
# Read backend URL from Hugging Face secret
|
| 6 |
BACKEND_URL = os.environ.get("KERNL_BACKEND_URL", "").rstrip('/')
|
| 7 |
|
| 8 |
if not BACKEND_URL:
|
|
|
|
| 11 |
def query_kernl(scenario, with_brain):
|
| 12 |
"""Call the Kernl /agent/handle endpoint and format the response."""
|
| 13 |
if not BACKEND_URL:
|
| 14 |
+
return "β Backend URL not configured. Please set the KERNL_BACKEND_URL secret."
|
| 15 |
|
| 16 |
if not scenario or not scenario.strip():
|
| 17 |
return "β Please enter a scenario."
|
|
|
|
| 29 |
response.raise_for_status()
|
| 30 |
data = response.json()
|
| 31 |
|
|
|
|
| 32 |
output = []
|
| 33 |
output.append(f"**Action:** `{data.get('action', 'N/A')}`")
|
| 34 |
output.append(f"**Rule Applied:** `{data.get('rule_applied', 'N/A')}`")
|
|
|
|
| 41 |
return "\n\n".join(output)
|
| 42 |
|
| 43 |
except requests.exceptions.ConnectionError:
|
| 44 |
+
return "β Cannot connect to Kernl backend."
|
| 45 |
except requests.exceptions.Timeout:
|
| 46 |
+
return "β Request timed out."
|
| 47 |
except Exception as e:
|
| 48 |
return f"β Error: {str(e)}"
|
| 49 |
|
| 50 |
+
# Theme
|
| 51 |
theme = gr.themes.Soft(
|
| 52 |
primary_hue="teal",
|
| 53 |
secondary_hue="teal",
|