metadata
title: Reflection With Code Execuation Chart Generation
emoji: π
colorFrom: green
colorTo: green
sdk: gradio
sdk_version: 6.5.1
app_file: app.py
pinned: false
license: apache-2.0
Chart Generation with LLM Agents
A Gradio app that uses LLM agents with reflection pattern to generate and improve data visualizations.
Features
- π€ LLM-Powered Chart Generation: Uses GPT-4 or Claude to generate matplotlib code
- π Reflection Pattern: Automatically improves charts by analyzing V1 and generating V2
- π Coffee Sales Dataset: Pre-loaded dataset for demonstration
- π¨ Clean UI: User-friendly Gradio interface
How It Works
- Generate V1: LLM creates initial chart code based on your instruction
- Execute V1: Code runs and generates first chart
- Reflect: LLM analyzes V1 chart image and original code
- Generate V2: LLM creates improved code based on feedback
- Execute V2: Improved code runs and generates final chart
Setup
Local Development
- Install dependencies:
pip install -r requirements.txt
- Set up environment variables:
export OPENAI_API_KEY="your-key-here"
# OR
export ANTHROPIC_API_KEY="your-key-here"
- Run the app:
python app.py
HuggingFace Spaces Deployment
Create a new Space on HuggingFace
Upload all files:
app.pyutils.pycoffee_sales_local.csvrequirements.txtREADME.md(this file)
Add secrets in Space settings:
OPENAI_API_KEY(if using OpenAI models)ANTHROPIC_API_KEY(if using Anthropic models)
Set Space SDK to Gradio
The app will automatically deploy!
Usage
- Enter your chart instruction (e.g., "Create a plot comparing Q1 coffee sales in 2024 and 2025")
- Select models for generation (V1) and reflection (V2)
- Click "Generate Charts"
- Compare V1 and V2 charts side by side
- Review the reflection feedback and code
Dataset Schema
The coffee sales dataset includes:
date(M/D/YY)time(HH:MM)cash_type(card or cash)card(string)price(number)coffee_name(string)quarter(1-4) - auto-derivedmonth(1-12) - auto-derivedyear(YYYY) - auto-derived
Model Recommendations
- Generation (V1): Fast models like
gpt-4o-miniorgpt-4o - Reflection (V2): Strong reasoning models like
o1-mini,o1-preview, orclaude-3-5-sonnet-20241022
Requirements
- Python 3.8+
- OpenAI API key OR Anthropic API key
- See
requirements.txtfor full dependency list
License
Educational project for demonstrating LLM agents with reflection pattern.
Note: The code is from Deepleraning.ai Agnetic AI Course