Getting Started with LouieAI Notebook Interface¶
This notebook demonstrates the basic usage of the LouieAI notebook-friendly API (lui).
Authentication Requirements¶
LouieAI uses PyGraphistry for authentication. Before running this notebook, you need:
PyGraphistry Account: Sign up for free at hub.graphistry.com
Set Credentials: Use one of these methods:
# Option 1: Environment variables (recommended for notebooks) export GRAPHISTRY_USERNAME="your_username" export GRAPHISTRY_PASSWORD="your_password"
# Option 2: Authenticate in code import graphistry graphistry.register(api=3, server="hub.graphistry.com", username="your_username", password="your_password")
Setup¶
First, make sure you have LouieAI installed and your credentials configured.
import os
import graphistry
from louieai import louie
# Authenticate with credentials from environment variables
# Set these before running:
# export GRAPHISTRY_USERNAME="your_username"
# export GRAPHISTRY_PASSWORD="your_password"
# export GRAPHISTRY_SERVER="your_server"
# export LOUIE_SERVER="your_louie_server"
g = graphistry.register(
api=3,
server=os.environ.get("GRAPHISTRY_SERVER", "hub.graphistry.com"),
username=os.environ.get("GRAPHISTRY_USERNAME"),
password=os.environ.get("GRAPHISTRY_PASSWORD"),
)
print("✅ Authenticated with Graphistry")
# Create the Louie interface
LOUIE_SERVER = os.environ.get("LOUIE_SERVER", "https://den.louie.ai")
lui = louie(g, server_url=LOUIE_SERVER)
print(f"✅ Connected to: {LOUIE_SERVER}")
# Display status
lui
✅ Authenticated with Graphistry ✅ Connected to: http://localhost:8000
🤖 LouieAI Session
⚪ Session: Not started (use lui('your query'))
📚 History: 0 responses
🔍 Traces: Disabled (use lui.traces = True to enable)
Quick Help (click to expand)
# Make a query
lui('Show me sales data from last week')
# Control visibility
lui('query', share_mode='Private') # Default: only you
lui('query', share_mode='Organization') # Share within org
lui('query', share_mode='Public') # Share publicly
# Access results
df = lui.df # Latest dataframe
text = lui.text # Latest text response
all_dfs = lui.dfs # All dataframes
# History
lui[-1].df # Previous response's dataframe
# Traces (AI reasoning)
lui.traces = True # Enable for session
lui('query', traces=True) # Enable for one query
Basic Queries¶
The lui interface accepts natural language queries and returns AI-generated responses. Let's verify it works with a simple arithmetic question:
# Ask a simple arithmetic question
lui("2 + 2 = ?")
print(f"Answer: {lui.text}")
🤖 LouieAI Response
D_NX8yJBHIrMpAHHSY8pTw | Time: 33.7sAnswer: The question is a simple arithmetic problem asking for the sum of 2 and 2.
# Validation: check the response
if "4" in str(lui.text):
print("✅ Basic query working correctly!")
Working with Data¶
LouieAI can generate and analyze data. Let's create a sample dataset:
# Create a sample DataFrame
import pandas as pd
from IPython.display import display
sample_df = pd.DataFrame(
{
"name": ["Alice", "Bob", "Charlie"],
"age": [25, 30, 35],
"city": ["New York", "Los Angeles", "Chicago"],
}
)
# Upload to LouieAI for analysis
lui("Describe this data", sample_df)
# Display the response
print(f"Text response: {lui.text}")
print(f"DataFrame ID: {lui.df_id}")
# Show the DataFrame using native display
if lui.df is not None:
print("\nDataFrame returned:")
display(lui.df) # Native Jupyter display
Text response: DataFrame with 3 rows and 3 columns. Columns: name, age, city DataFrame ID: B_KT2IcA3d DataFrame returned:
| name | age | city | |
|---|---|---|---|
| 0 | Alice | 25 | New York |
| 1 | Bob | 30 | Los Angeles |
| 2 | Charlie | 35 | Chicago |
Analyzing Data¶
Once you have data, you can ask LouieAI to perform calculations and analysis using its code agent:
# Analyze the DataFrame - calculate average age using LouieAI
# Note: The server should calculate the average (30) when using the 'average' keyword
if lui.df is not None:
# Ask LouieAI to calculate the average age - use 'average' keyword
lui("Calculate the average of the age column", lui.df)
print("📊 Age Analysis:")
print(f"LouieAI response: {lui.text}")
else:
print("No DataFrame available for analysis")
📊 Age Analysis: LouieAI response: The average age is 30.0
# Validation: Check if the age calculation was performed
if lui.text and "30" in str(lui.text):
print("✅ Average age calculation completed!")
else:
print("Age analysis in progress...")
✅ Average age calculation completed!
Beyond DataFrames¶
LouieAI can also analyze images, PDFs, Excel files, and more!
For comprehensive examples of uploading different file types, see the Data Upload Guide:
- Image analysis (PNG, JPEG, etc.)
- Document processing (PDF, Word, PowerPoint)
- Excel file handling
- Advanced upload options
# Create a products DataFrame for inventory analysis
import pandas as pd
products_df = pd.DataFrame(
{
"product": ["Widget A", "Widget B", "Widget C"],
"price": [10.99, 15.49, 8.99],
"quantity": [100, 75, 150],
}
)
print("Product inventory:")
print(products_df)
# Upload and analyze with LouieAI
# Server should calculate total as price * quantity
lui(
"Calculate the total inventory value (sum of price * quantity for each product)",
products_df,
)
# Show the response
print(f"\n📤 LouieAI Response: {lui.text}")
# Show the DataFrame that was uploaded
if lui.df is not None:
print(f"\nDataFrame ID: {lui.df_id}")
Product inventory:
product price quantity
0 Widget A 10.99 100
1 Widget B 15.49 75
2 Widget C 8.99 150
📤 LouieAI Response: The total calculated value is $3609.25 DataFrame ID: B_Ch4dXSk8
# Validation: Check if LouieAI returned the inventory calculation
if lui.df is not None:
print("✅ Inventory calculation received from LouieAI!")
else:
print("Waiting for LouieAI response...")
✅ Inventory calculation received from LouieAI!
Uploading Your Own Data¶
LouieAI can analyze DataFrames you create or load from files:
import numpy as np
import pandas as pd
# Create your own DataFrame (or load from CSV/Excel)
my_data = pd.DataFrame(
{
"date": pd.date_range("2024-01-01", periods=30, freq="D"),
"sales": np.random.randn(30).cumsum() + 100,
"visitors": np.random.randint(50, 200, 30),
"region": np.random.choice(["North", "South", "East", "West"], 30),
}
)
print("Sample of your data:")
my_data.head()
Sample of your data:
| date | sales | visitors | region | |
|---|---|---|---|---|
| 0 | 2024-01-01 | 99.094253 | 104 | East |
| 1 | 2024-01-02 | 98.690385 | 80 | East |
| 2 | 2024-01-03 | 101.031939 | 85 | South |
| 3 | 2024-01-04 | 100.059336 | 184 | North |
| 4 | 2024-01-05 | 101.043540 | 183 | South |
# Upload and analyze your DataFrame with LouieAI
lui("Calculate the total sum of the sales column", my_data)
print("📊 Sales Analysis:")
print(f"LouieAI response: {lui.text}")
# Ask a follow-up question - use 'unique' keyword for unique count
lui("Count unique values in the region column", my_data)
print("\n📊 Region Analysis:")
print(f"LouieAI response: {lui.text}")
📊 Sales Analysis: LouieAI response: The total sum of sales is 3060.75
📊 Region Analysis: LouieAI response: There are 4 unique values in the region column
# Validation: Check that LouieAI processed the regions query
if lui.text:
print("✅ Region analysis received from LouieAI!")
else:
print("Waiting for LouieAI response...")
✅ Region analysis received from LouieAI!
Session History¶
The lui interface maintains a history of your interactions:
# Access previous responses by index
# lui[-1] # Last response
# lui[-2] # Second to last response
# Check the number of interactions
print(f"Total interactions: {len(lui._history)}")
Total interactions: 6
Enabling Traces¶
For complex queries, you might want to see the AI's reasoning process:
# Enable traces to see reasoning steps
lui.traces = True
# Now queries will show reasoning steps
lui("What is 100 + 50? Please respond with just the number.")
print(f"Answer with traces: {lui.text}")
# Disable traces
lui.traces = False
🤖 LouieAI Response
D_NX8yJBHIrMpAHHSY8pTw | Time: 5.7sAnswer with traces: 150
# Or enable traces for just one query
lui("The sum of integers from 1 to 10 equals?", traces=True)
print(f"Sum calculation: {lui.text}")
# Validation: The sum of 1 to 10 is 55
if "55" in str(lui.text):
print("✅ Sum formula working!")
🤖 LouieAI Response
D_NX8yJBHIrMpAHHSY8pTw | Time: 6.6sCalculation: \(\text{Sum} = \frac{10}{2} \times (1 + 10) = 5 \times 11 =
Sum calculation: The sum of integers from 1 to 10 can be calculated using the formula for the sum of an arithmetic series: \(\text{Sum} = \frac{n}{2} \times (\text{first term} + \text{last term})\), where \(n\) is the number of terms. In this case, \(n = 10\), the first term is 1, and the last term is 10.
Calculation: \(\text{Sum} = \frac{10}{2} \times (1 + 10) = 5 \times 11 =
Error Handling¶
The interface handles errors gracefully:
# Check if the last operation had errors
if lui.has_errors:
print("Last operation had errors:", lui.errors)
else:
print("No errors in last operation")
No errors in last operation
Tips and Tricks¶
Here are some helpful patterns for using the notebook interface:
- Use clear prompts: Be specific about what you want to analyze
- Check outputs: Always verify
lui.dfandlui.textafter queries - Enable traces for debugging: Use
traces=Truewhen troubleshooting - Leverage history: Access previous results with
lui[-1],lui[-2], etc. - Upload various formats: DataFrames, images, PDFs all work seamlessly