ALPHA0008 commited on
Commit
dc7cc4d
Β·
verified Β·
1 Parent(s): 419410b

create app.py

Browse files
Files changed (1) hide show
  1. app.py +105 -0
app.py ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 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:
9
+ BACKEND_URL = None
10
+
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."
18
+
19
+ try:
20
+ response = requests.post(
21
+ f"{BACKEND_URL}/agent/handle",
22
+ json={
23
+ "company_id": "rivanly-inc",
24
+ "scenario": scenario,
25
+ "with_brain": with_brain
26
+ },
27
+ timeout=30
28
+ )
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')}`")
36
+ output.append(f"**Message:** {data.get('message_to_customer', data.get('answer', 'N/A'))}")
37
+ if data.get('evidence'):
38
+ output.append(f"**Evidence:** {data.get('evidence')}")
39
+ output.append(f"**Skill Matched:** `{data.get('skill_matched', 'N/A')}`")
40
+ output.append(f"**Confidence:** `{data.get('confidence', 'N/A')}`")
41
+
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",
55
+ neutral_hue="gray",
56
+ font=gr.themes.GoogleFont("Inter")
57
+ )
58
+
59
+ with gr.Blocks(theme=theme, title="Kernl – Operational Memory for AI Agents") as demo:
60
+ gr.Markdown("""
61
+ # 🧠 Kernl
62
+ ### Operational memory for AI agents
63
+
64
+ Kernl compiles how your company actually decides things – from Slack, SOPs, and tickets – into an executable skills file.
65
+ Any agent. Any task. Correct every time.
66
+ """)
67
+
68
+ with gr.Row():
69
+ with gr.Column(scale=1):
70
+ scenario_input = gr.Textbox(
71
+ label="Enter your business scenario",
72
+ placeholder="Example: Enterprise customer, 18 months tenure, wants $1,200 refund",
73
+ lines=4
74
+ )
75
+ with_brain_toggle = gr.Checkbox(
76
+ label="🧠 Use Company Brain (Kernl)",
77
+ value=True,
78
+ info="ON = Kernl uses compiled company knowledge. OFF = generic AI answer."
79
+ )
80
+ submit_btn = gr.Button("Ask Kernl", variant="primary", size="lg")
81
+
82
+ with gr.Column(scale=2):
83
+ output_box = gr.Markdown(label="Kernl's Response", value="*Your answer will appear here...*")
84
+
85
+ gr.Markdown("""
86
+ ---
87
+ ### Try these example scenarios (copy & paste):
88
+
89
+ - `Enterprise customer, 18 months tenure, wants $1,200 refund`
90
+ - `Annual plan customer, day 10 of subscription, $300 refund requested`
91
+ - `Customer reporting P0 bug on dashboard, enterprise plan`
92
+ - `Customer showing 3 churn signals in last 30 days`
93
+ - `Startup requesting 40% discount`
94
+
95
+ ---
96
+ **Built with AMD MI300X, vLLM, and LangGraph** | [GitHub](https://github.com/your-repo) | **Track 1: AI Agents & Agentic Workflows**
97
+ """)
98
+
99
+ submit_btn.click(
100
+ fn=query_kernl,
101
+ inputs=[scenario_input, with_brain_toggle],
102
+ outputs=output_box
103
+ )
104
+
105
+ demo.launch()