ALPHA0008 commited on
Commit
0b8db51
Β·
verified Β·
1 Parent(s): dc7cc4d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -6
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 (set in Settings β†’ Repository secrets)
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 in Space Settings β†’ Repository secrets."
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. Make sure your backend is running and KERNL_BACKEND_URL is correct."
46
  except requests.exceptions.Timeout:
47
- return "❌ Request timed out. The backend is taking too long to respond."
48
  except Exception as e:
49
  return f"❌ Error: {str(e)}"
50
 
51
- # Custom dark theme with deep teal accent
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",