CoolFace
Apppublic

assathe/data-analyst-agent2

sourceHugging Facemitupdated 1y agoView on Hugging Face
0likes
App README

๐Ÿง  Data Analyst Agent - FastAPI

This is a FastAPI-based Data Analyst Agent that can perform data analysis, web scraping, and visualization through API calls. It integrates with Anthropic Claude for automated Python code generation and executes the code securely.

The app is designed for deployment on [Hugging Face Spaces](https://huggingface.co/spaces) using Docker.


๐Ÿš€ Features

  • โ€”Web scraping with requests + BeautifulSoup
  • โ€”Data analysis with pandas & duckdb
  • โ€”Visualizations with matplotlib, seaborn, and plotly
  • โ€”File uploads for CSV, JSON, TXT datasets
  • โ€”Automated Python code generation via Claude
  • โ€”CORS enabled for web integration
  • โ€”API response formats support JSON, images (Base64), or text

๐Ÿ“‚ Project Structure

โ”œโ”€โ”€ main.py # FastAPI app entry point โ”œโ”€โ”€ claudeclient.py # Claude API integration โ”œโ”€โ”€ codeexecutor.py # User Python code execution environment โ”œโ”€โ”€ requirements.txt # Python dependencies โ”œโ”€โ”€ Dockerfile # Hugging Face Docker deployment file โ”œโ”€โ”€ .env # Local environment secrets (ignored in git) โ””โ”€โ”€ README.md # Documentation (this file)


โšก Local Development

1๏ธโƒฃ Install dependencies

pip install -r requirements.txt

2๏ธโƒฃ Run the app

uvicorn main:app --host 0.0.0.0 --port 8000 --reload

Then visit:


๐ŸŒ Deploying to Hugging Face Spaces (Docker)

Hugging Face Spaces requires apps to listen on port 7860 for Docker-based deployments.

1๏ธโƒฃ requirements.txt


2๏ธโƒฃ Dockerfile

Important: Port 7860 is required on Hugging Face Docker Spaces.


๐Ÿ“ก API Endpoints

https://assathe-data-analyst-agent2.hf.space/ to check the root status.

https://assathe-data-analyst-agent2.hf.space/health for the health endpoint.

https://assathe-data-analyst-agent2.hf.space/docs for the Swagger docs and API playground

POST /api/

curl -X POST "https://assathe-data-analyst-agent2.hf.space/api/" \ -F "questions=@questions.txt" \ -F "files=@edges.csv" # (optional)

Send a question and optional files for analysis.

  • โ€”Form fields:
  • โ€”questions โ†’ text file containing the question
  • โ€”files โ†’ one or more data files (CSV, JSON, TXT)
  • โ€”Returns: JSON with results or Base64-encoded image

Example: curl -X POST "https://assathe-data-analyst-agent2.hf.space/api/" \ -F "questions=@question.txt" -F "files=@data.csv # (optional)


GET /health

Detailed health probe.


๐Ÿ”‘ Environment Variables

In your .env or Hugging Face Secrets panel:

  • โ€”CLAUDE_API_KEY โ†’ Your Anthropic Claude API key
  • โ€”Any other secrets needed for custom integrations

๐Ÿ›  Troubleshooting

  • โ€”Build failure: Check Docker build logs in Hugging Face Spaces.
  • โ€”Missing modules: Ensure all dependencies are in requirements.txt.
  • โ€”Port issues: Ensure Dockerfile runs on port 7860.
  • โ€”Claude API errors: Verify CLAUDE_API_KEY is set correctly in Hugging Face secrets.

๐Ÿค Contributing

Pull requests are welcome. Please ensure:

  • โ€”Code is tested locally
  • โ€”Dependencies are updated in `requirements.txt`
  • โ€”Secrets are never committed to the repo

๐Ÿ“œ License

MIT License


๐Ÿ“Œ Notes for Hugging Face Deployment

  • โ€”Create a new Space and select Docker as SDK
  • โ€”Push the repo with git push to the provided Space repo link
  • โ€”Set Secrets in the Space settings (e.g., CLAUDE_API_KEY)
  • โ€”Hugging Face will automatically build and start the container