#Data Analysis 

## Headline

Python Developer | FastAPI | Local LLM Applications | Data Analysis APIs | Transformers

## About

I built **The Oracle**, a typed LLM-powered data analysis API using Python, FastAPI, Pandas, PyTorch, and Hugging Face Transformers.

The application allows users to upload a CSV dataset, generate statistical summaries, and ask natural-language questions about the data. The system processes each request through a structured runnable chain that builds a prompt, calls a local language model, and parses the final response.

This project gave me practical experience combining backend API development with local AI inference, typed data validation, error handling, and automated testing.

## LLM Model Used

- **Model:** `Qwen/Qwen2.5-0.5B-Instruct`
- **Provider/library:** Hugging Face Transformers
- **Task:** Text generation and question answering over dataset statistics
- **Execution:** Local inference on CPU using `transformers.pipeline`
- **Generation settings:** Deterministic generation with `do_sample=False` and a maximum of 256 new tokens
- **Prompt format:** Chat-style user messages using Qwen's chat template

The model receives only the statistical summary generated by Pandas and the user's question. The prompt instructs the model to answer exclusively from the provided statistics and to clearly state when the data is insufficient.

## What I Learned

### Large Language Models

- How to integrate a local instruction-tuned LLM into a Python application.
- How to use Hugging Face's `transformers.pipeline` for text generation.
- How chat messages and model-specific templates affect LLM input.
- How deterministic generation can make analytical responses more consistent.
- Why prompts should constrain the model to a defined data source.

### Backend Development

- How to build REST endpoints with FastAPI.
- How to handle CSV uploads and process data with Pandas.
- How to return meaningful HTTP status codes for invalid files, missing datasets, and model failures.
- How to keep uploaded data in memory for a simple single-process application.

### Software Design

- How to design a typed runnable pipeline using Pydantic models.
- How to compose processing steps with Python's `|` operator.
- How to separate prompt construction, model execution, and response parsing.
- How to make model output safer to consume by validating empty responses and cleaning Markdown-wrapped output.

### Testing and Reliability

- How to test an LLM chain by mocking the model instead of downloading or executing it during every test.
- How to test API endpoints for both successful requests and error conditions.
- How to isolate model failures and expose clear application-level errors.
- How to document assumptions, dependencies, and expected API behavior.

## Skills

Python · FastAPI · Pandas · Pydantic · PyTorch · Hugging Face Transformers · Local LLM Inference · Prompt Engineering · REST APIs · CSV Processing · Automated Testing · Software Design

## Featured Project Description

**KK2-Malmo – The Oracle: Typed LLM Data Analysis API**

- **GitHub repository:** [View the project on GitHub](https://github.com/arbazshah52/KK2-Malmo.git)

A FastAPI application that accepts CSV files, calculates descriptive statistics with Pandas, and answers user questions using the local `Qwen/Qwen2.5-0.5B-Instruct` model. The implementation uses a typed runnable chain consisting of `PromptBuilder`, `LLMRunner`, and `ResponseParser`.

## Short LinkedIn Post

I built a local LLM-powered data analysis API called **The Oracle**.

The project uses **Qwen/Qwen2.5-0.5B-Instruct** through Hugging Face Transformers, FastAPI for the backend, Pandas for statistical summaries, and Pydantic for typed data flow. Users can upload a CSV file and ask questions about the generated statistics.

The biggest lessons were integrating a local instruction-tuned model, designing constrained prompts, composing typed processing steps, handling model errors, and testing AI workflows with mocked model calls.

#Python #FastAPI #LLM #AI #MachineLearning #Transformers #DataAnalysis #BackendDevelopment
