Skip to content
Merged
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
30 changes: 29 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,35 @@ def server_status() -> str:
outputs=gr.JSON(),
title="SQL Query Tool",
description="Execute read-only SQL queries",
examples=["SELECT 1 AS one"]
examples=["SELECT 1 AS one"],
api_name="sql"
)

summarise_csv_interface = gr.Interface(
fn=summarise_csv,
inputs=gr.Textbox(label="CSV File Path"),
outputs=gr.JSON(),
title="CSV Summary Tool",
description="Analyze and summarize a CSV file",
examples=["sample_data/people.csv"],
api_name="csv"
)

create_pdf_interface = gr.Interface(
fn=create_pdf,
inputs=[
gr.JSON(label="Report Data"),
gr.Textbox(label="Output Path (optional)",
placeholder="Leave empty for default location"),
gr.Checkbox(label="Include Chart", value=True)
],
outputs=gr.Textbox(label="Generated PDF Path"),
title="PDF Report Generator",
description="Create professional PDF reports with data and optional charts",
examples=[
[{"customer": "ACME", "order_id": 12345, "total": 999, "items": 5}, None, True]
],
api_name="pdf"
)

# Add simple UI components
Expand Down
16 changes: 14 additions & 2 deletions tests/test_gradio_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,21 @@ def test_mcp_end_to_end(tmp_path):
client = Client("http://127.0.0.1:7860")
print(f"Available endpoints: {client.view_api()}")

# Test SQL tool - use the "/predict" endpoint (auto-created for the Interface)
result = client.predict("SELECT 1 AS one", api_name="/predict")
# Test SQL tool
result = client.predict("SELECT 1 AS one", api_name="/sql")
assert result == [{"one": 1}]

# Test CSV tool
csv_result = client.predict("sample_data/people.csv", api_name="/csv")
assert csv_result["row_count"] == 3
assert csv_result["column_count"] == 3
assert len(csv_result["columns"]) == 3

# Test PDF tool with minimal data
test_data = {"test_key": "test_value", "test_number": 42}
pdf_path = client.predict(test_data, None, True, api_name="/pdf")
assert os.path.exists(pdf_path)
assert os.path.getsize(pdf_path) > 1000 # Ensure PDF was created and has content
finally:
# Clean up
os.kill(proc.pid, signal.SIGTERM)
Expand Down
17 changes: 17 additions & 0 deletions tools/csv_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,23 @@


def summarise_csv(path: str | Path) -> Dict[str, object]:
"""
Analyze a CSV file and provide summary statistics.

Opens the CSV file using pandas and returns basic statistics including the number of rows,
columns, and per-column information (name, data type, missing value count).

Args:
path: Path to the CSV file (must exist and have .csv extension)

Returns:
Dictionary with row_count, column_count, and detailed column information

Raises:
FileNotFoundError: If the file doesn't exist
ValueError: If the file doesn't have a .csv extension
MemoryError: If the file contains more than 1,000,000 rows
"""
path = Path(path)
if not path.exists():
raise FileNotFoundError(f"No such file: {path}")
Expand Down
20 changes: 20 additions & 0 deletions tools/pdf_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,26 @@ def create_pdf(
out_path: str | None = None,
include_chart: bool = True,
) -> str:
"""
Generate a professional PDF report from provided data.

Creates a PDF document with the given data formatted as a table. Optionally includes
a bar chart visualization of numeric values, if at least 3 numeric fields are present.
The PDF includes the company logo if available in the assets directory.

Args:
data: Dictionary containing the data to include in the report
out_path: Optional custom path for the generated PDF file
(default: reports/report-{timestamp}.pdf)
include_chart: Whether to include a bar chart visualization of numeric values
(default: True)

Returns:
Absolute path to the generated PDF file

Raises:
ValueError: If the data dictionary is empty
"""
if not data:
raise ValueError("data cannot be empty.")

Expand Down