Skip to content

Add AI gallery item #1019

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added doc/_static/ai_windturbines.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions doc/gallery/ai_windturbines.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Wind Turbines

<img src="../_static/ai_windturbines.png" width="100%">

```{literalinclude} ../../examples/gallery/ai_windturbines/windturbines.py
---
language: python
```
18 changes: 18 additions & 0 deletions doc/gallery/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# Gallery

## Lumen AI

::::{grid} 2 2 3 3
:gutter: 1

:::{grid-item-card} Windturbines
:link: ai_windturbines
:link-type: doc

```{image} ../_static/ai_windturbines.png
```
:::

::::

## Lumen Spec

::::{grid} 2 2 3 3
:gutter: 1

Expand Down Expand Up @@ -58,6 +75,7 @@
---
hidden: true
---
Wind Turbines <ai_windturbines>
Precipitation <precip>
Penguins <penguins>
NYC Taxi Trips <nyc_taxi>
Expand Down
66 changes: 66 additions & 0 deletions examples/gallery/ai_windturbines/windturbines.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import lumen.ai as lmai

from lumen.ai.analysis import Analysis
from lumen.sources.duckdb import DuckDBSource
from lumen.views import YdataProfilingView


class Profiling(Analysis):
"""
Generates a profiling report for the given dataset.
"""

def __call__(self, pipeline):
return YdataProfilingView(pipeline=pipeline)


def duckduckgo_search(queries: list[str]) -> dict:
"""
Perform a DuckDuckGo search for the provided queries.

Parameters
----------
queries : list[str]
Search queries.

Returns
-------
dict
A dictionary mapping each query to a list of search results.
Each search result is a dict containing 'title' and 'url'.
"""
import requests

from bs4 import BeautifulSoup

results = {}
for query in queries:
url = f"https://duckduckgo.com/html/?q={query}"
headers = {"User-Agent": "Mozilla/5.0"}
response = requests.get(url, headers=headers)
soup = BeautifulSoup(response.text, "html.parser")
links = soup.find_all("a", {"class": "result__a"}, href=True)

results[query] = [
{"title": link.get_text(strip=True), "url": link["href"]} for link in links
]
return results


data = [
"https://datasets.holoviz.org/windturbines/v1/windturbines.parq",
"https://github.com/jakevdp/data-USstates/raw/refs/heads/master/state-areas.csv",
]
analyst_agent = lmai.agents.AnalystAgent(
template_overrides={
"main": {"instructions": "Please focus on the outliers of the data."}
}
)
assistant = lmai.ExplorerUI(
data=data,
llm=lmai.llm.OpenAI(),
agents=[analyst_agent],
analyses=[Profiling],
tools=[duckduckgo_search],
)
assistant.servable()
1 change: 1 addition & 0 deletions pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ packaging = "*"
pandas = "*"
panel = ">=1.5.0"
param = ">=1.9.0"
lumen = "*"
pip = "*"

[feature.py310.dependencies]
Expand Down
Loading