Skip to content

marcusjohnson11/XRF-Report-Generator

Repository files navigation

XRF Report Generator with EleutherAI Integration

πŸš€ Overview

Professional XRF (X-ray Fluorescence) analysis reporting system with advanced AI capabilities powered by both OpenAI and EleutherAI (community-driven AI) models through OpenRouter.

✨ Features

Core Functionality

  • Multi-format XRF Data Support: Delta and Vanta CSV formats
  • Professional PDF Reports: Customizable headers, element analysis, and statistics
  • Customer Information Management: Complete project tracking
  • Element Analysis: Automatic detection and statistical analysis of most prevalent elements

AI Enhancement (NEW!)

  • Dual AI Provider Support: OpenAI and OpenRouter (EleutherAI)
  • EleutherAI Models: Llama 3.1, Mixtral 8x7B, Claude Haiku, and more
  • Intelligent Analysis: Material identification, quality assessment, and technical recommendations
  • LangGraph Workflows: Multi-step AI analysis pipelines
  • Smart Fallback: Automatic fallback to standard reports when AI is unavailable

Interfaces

  • Command Line Interface (CLI): Batch processing and automation
  • Graphical User Interface (GUI): User-friendly point-and-click operation
  • Conversational Interface: Natural language report requests

πŸ›  Installation

Prerequisites

  • Python 3.11+
  • Virtual environment (recommended)

Quick Setup

# Clone or download the project
cd ReportGenerator

# Create virtual environment
python -m venv venv
venv\Scripts\activate  # Windows
# source venv/bin/activate  # macOS/Linux

# Install dependencies
pip install -r requirements.txt

API Keys (Optional - for AI features)

Create a .env file:

OPENAI_API_KEY=your-openai-key-here
OPENROUTER_API_KEY=your-openrouter-key-here

πŸš€ Usage

Command Line Interface

# Standard report
python simple_cli.py "ExampleData/DeltaData.csv" --customer-name "ABC Corp" --product-number "XRF-001"

# AI-enhanced with OpenAI
python simple_cli.py "data.csv" --ai-enhanced --ai-provider openai

# AI-enhanced with EleutherAI (via OpenRouter)
python simple_cli.py "data.csv" --ai-enhanced --ai-provider openrouter --ai-model llama-3.1-8b

Graphical Interface

python simple_main.py

Available AI Models

  • OpenRouter Models: auto, llama-3.1-8b, llama-3.1-70b, mixtral-8x7b, claude-haiku, hermes-3-8b
  • OpenAI Models: GPT-4, GPT-3.5-turbo (configured via OpenAI settings)

πŸ“ Project Structure

ReportGenerator/
β”œβ”€β”€ simple_cli.py              # Command line interface
β”œβ”€β”€ simple_main.py             # GUI application
β”œβ”€β”€ main.py                    # Legacy main application
β”œβ”€β”€ requirements.txt           # Python dependencies
β”œβ”€β”€ .env                       # API keys (create this)
β”‚
β”œβ”€β”€ src/                       # Core modules
β”‚   β”œβ”€β”€ data_parsers.py        # XRF data parsing
β”‚   β”œβ”€β”€ simple_report_generator.py  # PDF generation
β”‚   └── ai_enhanced_report_generator.py  # AI-enhanced reports
β”‚
β”œβ”€β”€ ai_modules/                # AI integration modules
β”‚   β”œβ”€β”€ ai_enhanced_generator.py         # OpenAI integration
β”‚   β”œβ”€β”€ simple_openrouter_ai_generator.py # EleutherAI integration
β”‚   β”œβ”€β”€ conversational_interface.py      # Natural language interface
β”‚   └── langgraph_example.py            # LangGraph workflows
β”‚
β”œβ”€β”€ tests/                     # Test files and demos
β”‚   β”œβ”€β”€ test_live_eleutherai.py         # Live EleutherAI test
β”‚   β”œβ”€β”€ test_fallback_ai.py            # Fallback system test
β”‚   └── eleutherai_complete_demo.py    # Complete demo
β”‚
β”œβ”€β”€ docs/                      # Documentation
β”‚   β”œβ”€β”€ README.md              # This file
β”‚   β”œβ”€β”€ API_KEY_SETUP.md       # API key configuration guide
β”‚   β”œβ”€β”€ LANGGRAPH_INTEGRATION.md  # LangGraph integration details
β”‚   └── PROJECT_STRUCTURE.md   # Detailed project structure
β”‚
β”œβ”€β”€ ExampleData/               # Sample XRF data files
β”œβ”€β”€ output/                    # Generated reports
└── venv/                      # Virtual environment

πŸ€– AI Features

EleutherAI Integration (Community-Driven AI)

  • Models: Meta Llama 3.1 (8B/70B), Mixtral 8x7B, and more
  • Provider: OpenRouter (cost-effective, open-source focused)
  • Analysis: Professional material identification and quality assessment
  • Cost: Typically lower cost than OpenAI

OpenAI Integration

  • Models: GPT-4, GPT-3.5-turbo
  • Analysis: Advanced material insights and recommendations
  • Reliability: Industry-standard AI analysis

AI Analysis Capabilities

  • Quality Assessment: Data consistency and measurement reliability
  • Material Identification: Alloy classification and composition analysis
  • Technical Recommendations: Industry-standard suggestions for further testing
  • Professional Reporting: AI insights integrated into PDF reports

πŸ“Š Example AI Output

QUALITY ASSESSMENT:
Overall data quality rating: 8/10
The XRF data shows good consistency with narrow concentration ranges 
for primary elements (Fe: 97.27-97.96%, Cr: 1.10-1.39%).

MATERIAL ANALYSIS:
Most likely material: Carbon Steel with high Cr content
- Fe (97.73%): Primary matrix element
- Cr (1.20%): Corrosion resistance contributor
- Mn (0.51%): Deoxidizer/strengthening element

RECOMMENDATIONS:
1. Optimize Cu and Ni detection limits
2. Verify sample preparation procedures
3. Consider SEM-EDS for microstructure confirmation

🎯 Getting Started

  1. Install the system following the installation guide above
  2. Try the GUI: Run python simple_main.py for point-and-click operation
  3. Test with sample data: Use files in ExampleData/ folder
  4. Add AI features: Set up API keys for intelligent analysis
  5. Explore demos: Run files in tests/ folder to see AI capabilities

πŸ”§ Configuration

CLI Options

  • --ai-enhanced: Enable AI analysis
  • --ai-provider: Choose openai or openrouter
  • --ai-model: Select specific model (e.g., llama-3.1-8b)
  • --customer-name: Customer information
  • --product-number: Product tracking
  • --elements N: Number of elements to analyze (5-15)

GUI Options

  • AI Provider selection (radio buttons)
  • Model selection dropdown
  • API key management
  • Customer information forms
  • Output directory selection

πŸ†˜ Support

Common Issues

  • Style errors: PDF generation issues (being resolved)
  • API quota: Add credits to OpenRouter/OpenAI accounts
  • Data format: Ensure CSV files are properly formatted

Getting Help

  • Check the docs/ folder for detailed guides
  • Run test files in tests/ folder to verify functionality
  • Review example data in ExampleData/ folder

πŸŽ‰ Success Story

This system successfully integrates cutting-edge AI analysis with professional XRF reporting:

  • βœ… Live EleutherAI Integration: Confirmed working with real API calls
  • βœ… Professional Analysis: Industry-standard material identification
  • βœ… Multiple Interfaces: CLI, GUI, and conversational options
  • βœ… Cost-Effective: Community-driven AI reduces analysis costs
  • βœ… Fallback Systems: Reliable operation even when AI is unavailable

Your XRF analysis system is now powered by both commercial and open-source AI! πŸš€

About

Professional XRF data analysis with AI-enhanced reporting using LangGraph and EleutherAI

Resources

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages