Spaces:
Sleeping
Sleeping
File size: 15,244 Bytes
b45622c de34a67 b45622c 3edf72f b45622c 3edf72f b45622c 3edf72f b45622c 3edf72f b45622c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
"""
Tasty Bytes Cortex Analyst - Demo Space
========================================
An interactive showcase of the Tasty Bytes Customer Analytics Cortex Analyst agent.
This Gradio app demonstrates:
- Natural language querying capabilities
- Example queries and results
- Architecture and setup instructions
- Live demo video
Note: This is a demo/showcase space. The actual Cortex Analyst runs on Snowflake infrastructure.
To try it yourself, follow the setup instructions in the GitHub repository.
"""
import gradio as gr
import pandas as pd
# Sample data for demonstration
sample_customer_counts = pd.DataFrame([
{"Rank": 1, "Country": "United States", "Customers": 5420, "Total Sales": "$1,250,890.75"},
{"Rank": 2, "Country": "India", "Customers": 3890, "Total Sales": "$980,230.50"},
{"Rank": 3, "Country": "Egypt", "Customers": 2110, "Total Sales": "$520,450.00"},
])
sample_top_customers = pd.DataFrame([
{"Customer ID": 110913, "Name": "Anna Sanchez", "City": "Boston", "Total Sales": "$3,302.00"},
{"Customer ID": 130576, "Name": "Grace Kline", "City": "Mumbai", "Total Sales": "$2,809.50"},
{"Customer ID": 90298, "Name": "Dahlia Buchanan", "City": "Cairo", "Total Sales": "$1,745.75"},
])
example_queries = [
("How many customers are in our loyalty program?", "SELECT COUNT(DISTINCT customer_id) FROM customer_loyalty_metrics_v", "11,420 customers"),
("Which countries have the most customers?", "SELECT country, COUNT(DISTINCT customer_id) FROM customer_loyalty_metrics_v GROUP BY country ORDER BY COUNT(DISTINCT customer_id) DESC", "See table below"),
("Show me the top 5 customers by total sales", "SELECT customer_id, first_name, last_name, city, total_sales FROM customer_loyalty_metrics_v ORDER BY total_sales DESC LIMIT 5", "See table below"),
("What's the total sales by country?", "SELECT country, SUM(total_sales) FROM customer_loyalty_metrics_v GROUP BY country ORDER BY SUM(total_sales)", "See results in table"),
]
def create_demo():
with gr.Blocks(theme=gr.themes.Soft(), title="Tasty Bytes Cortex Analyst Demo") as demo:
gr.Markdown("""
# π Tasty Bytes Customer Analytics - Cortex Analyst Demo
**Natural Language Interface for Customer Loyalty Data**
This demo showcases a Snowflake Cortex Analyst agent built on the TASTY_BYTES public dataset.
Ask questions in plain English and get instant insights - no SQL knowledge required!
β οΈ **Note**: This is a demonstration space. To try the actual agent, follow the setup instructions in the GitHub repository.
""")
# Main demo section
with gr.Tab("π₯ Demo Video"):
gr.Markdown("""
## Watch the Full Demo
See Cortex Analyst in action: natural language queries, automatic SQL generation, and instant results.
""")
# Placeholder for video (you'll upload your actual demo video)
gr.Markdown("""
πΉ **Demo video coming soon!**
The video will demonstrate:
- Asking questions in natural language
- Automatic SQL generation by Cortex Analyst
- Real-time results and insights
- Various query types (counts, aggregations, rankings)
**Until then, explore the other tabs to see example queries and results!**
""")
# Example queries tab
with gr.Tab("π‘ Example Queries"):
gr.Markdown("""
## Try These Questions
Here are some examples of natural language queries you can ask the Cortex Analyst agent:
""")
for i, (question, sql, result) in enumerate(example_queries, 1):
with gr.Accordion(f"Example {i}: {question}", open=(i==1)):
gr.Markdown(f"**Natural Language Query:**")
gr.Code(question, language=None)
gr.Markdown(f"**Generated SQL:**")
gr.Code(sql, language="sql")
gr.Markdown(f"**Result:**")
gr.Markdown(f"`{result}`")
gr.Markdown("""
### More Example Questions:
**Customer Analytics:**
- "How many customers do we have in total?"
- "Show me all customers from Boston"
- "Which customer has the highest total sales?"
- "List customers who have visited more than 50 locations"
**Geographic Analysis:**
- "What cities have the most customers?"
- "Compare customer counts across countries"
- "Show me the geographic distribution of our customers"
**Sales Insights:**
- "What's the average sales per customer?"
- "Which country generates the most revenue?"
- "Show me total sales by city"
- "Who are our top 10 customers by spend?"
""")
# Sample results tab
with gr.Tab("π Sample Results"):
gr.Markdown("""
## Example Query Results
Here's what the actual results look like when you query the agent:
""")
gr.Markdown("### Query: 'Which countries have the highest number of customers?'")
gr.Dataframe(sample_customer_counts, label="Customer Count by Country")
gr.Markdown("---")
gr.Markdown("### Query: 'Show me the top 3 customers by total sales'")
gr.Dataframe(sample_top_customers, label="Top Customers")
gr.Markdown("""
---
π‘ **Tip**: All numeric values are automatically rounded to 2 decimal places as specified
in the semantic view's custom instructions.
""")
# Architecture tab
with gr.Tab("ποΈ Architecture"):
gr.Markdown("""
## System Architecture
The Cortex Analyst agent uses a layered architecture to transform natural language
into actionable insights:
""")
gr.Markdown("""
```
βββββββββββββββββββββββββββββββββββββββββββ
β Business User β
β (Natural Language Questions) β
ββββββββββββββββ¬βββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββ
β Cortex Analyst (AI Layer) β
β β’ Understands natural language β
β β’ Maps questions to business concepts β
β β’ Generates SQL queries β
ββββββββββββββββ¬βββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββ
β Semantic View (Business Logic) β
β β’ Business-friendly names β
β β’ Metrics & dimensions β
β β’ Pre-verified queries β
β β’ Custom instructions β
ββββββββββββββββ¬βββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββ
β TASTY_BYTES Dataset β
β β’ Customer loyalty data β
β β’ Order history β
β β’ Geographic information β
βββββββββββββββββββββββββββββββββββββββββββ
```
""")
gr.Markdown("""
### Key Components:
**1. Data Layer** - Snowflake TASTY_BYTES public dataset
- Customer loyalty program data
- Order transactions
- Location and geographic information
**2. Semantic Layer** - Native Snowflake Semantic View
- Translates technical column names to business terms
- Defines metrics (e.g., "total sales") and dimensions (e.g., "country")
- Includes verified query examples
- Enforces data access controls
**3. AI Layer** - Cortex Analyst
- Powered by LLM (Large Language Model)
- Understands natural language intent
- Automatically generates SQL queries
- Returns results in business-friendly format
**4. Interface** - Snowflake Intelligence & Cortex Analyst UI
- Chat-based interaction
- Visual result presentation
- Query history and refinement
""")
# Setup guide tab
with gr.Tab("π Setup Guide"):
gr.Markdown("""
## How to Set This Up Yourself
Follow these steps to create your own Cortex Analyst agent with the TASTY_BYTES dataset:
### Prerequisites
- Snowflake account (free trial available at [signup.snowflake.com](https://signup.snowflake.com))
- ACCOUNTADMIN role or equivalent permissions
- Cortex Analyst feature enabled (available in most regions)
### Step 1: Clone the Repository
```bash
git clone https://github.com/aamanlamba/tasty-bytes-cortex-analyst.git
cd tasty-bytes-cortex-analyst
```
### Step 2: Load the TASTY_BYTES Dataset
```sql
-- Execute in Snowflake Snowsight or your SQL client
-- This creates the database, schemas, and loads sample data
@scripts/load_tasty_bytes_data.sql
```
β±οΈ Takes approximately 5-10 minutes
### Step 3: Create the Semantic View
```sql
-- Execute the semantic view creation script
@scripts/create_semantic_view.sql
```
β±οΈ Takes less than 1 minute
### Step 4: Create the Cortex Analyst Agent
1. Navigate to **AI & ML** β **Cortex Analyst** in Snowsight
2. Click **Create new agent**
3. Configure:
- **Name**: Tasty Bytes Customer Analytics
- **Description**: Natural language interface for customer data
4. Add Tool:
- **Type**: Semantic View
- **View**: `HARMONIZEDCUSTOMERMETRICSSEMANTICVIEW`
- **Description**:
```
Use this tool to answer questions about Tasty Bytes customer
loyalty program metrics, including customer demographics,
total sales, and location visit patterns.
```
5. Click **Create agent**
### Step 5: Test Your Agent
Try asking:
- "How many customers are in our loyalty program?"
- "Which countries have the most customers?"
- "Show me the top 10 customers by sales"
### π Full Documentation
For detailed instructions, troubleshooting, and advanced customization:
- [GitHub Repository](https://github.com/aamanlamba/tasty-bytes-cortex-analyst)
- [Snowflake Cortex Analyst Docs](https://docs.snowflake.com/en/user-guide/snowflake-cortex/cortex-analyst)
- [Semantic Views Guide](https://docs.snowflake.com/en/user-guide/views-semantic/overview)
""")
# About tab
with gr.Tab("βΉοΈ About"):
gr.Markdown("""
## About This Project
This demo showcases **Snowflake Cortex Analyst**, an AI-powered natural language
interface for querying structured data. The project uses the publicly available
TASTY_BYTES sample dataset from Snowflake.
### Dataset
**TASTY_BYTES** represents a fictional global food truck franchise with:
- 11,420+ customer loyalty program members
- Order transaction history
- Multiple countries and cities
- Customer demographics and preferences
### Features Demonstrated
- β
Natural language to SQL translation
- β
Automatic query generation
- β
Business-friendly semantic layer
- β
Pre-verified query examples
- β
Custom SQL generation instructions
### Use Cases
This pattern applies to many industries:
- **Retail**: Customer segmentation, sales analysis
- **Finance**: Client analytics, transaction patterns
- **Healthcare**: Patient demographics, visit patterns
- **SaaS**: User engagement, feature adoption
- **E-commerce**: Customer lifetime value, purchase behavior
### Author
**Aaman Lamba**
- Strategy Consultant & Author
- AI Governance & Data Economy Expert
- Former Senior Industry Principal, Infosys
- IAPP Certified AI Governance Professional (in progress)
### Resources
- π¦ [GitHub Repository](https://github.com/aamanlamba/tasty-bytes-cortex-analyst)
- π [Snowflake Documentation](https://docs.snowflake.com/en/user-guide/snowflake-cortex/cortex-analyst)
- πΌ [LinkedIn](https://linkedin.com/in/aamanlamba)
### License
MIT License - Open source and free to use
---
β **Like this project?** Star it on [GitHub](https://github.com/aamanlamba/tasty-bytes-cortex-analyst)!
π **Found an issue?** [Report it here](https://github.com/aamanlamba/tasty-bytes-cortex-analyst/issues)
""")
return demo
# Launch the app
if __name__ == "__main__":
demo = create_demo()
demo.launch()
|