A prototype interactive estimation system using FastAPI, Langgraph, and Streamlit. This system guides users through a conversational flow to gather information for a service (e.g., roofing) and provides a structured estimate.
- Conversational Flow: Natural language conversation to gather project requirements
- Image Upload Support: Users can upload images related to their projects
- Smart Information Extraction: Uses AI to extract relevant information from user messages
- Dynamic Questioning: Adapts questions based on missing information
- Configurable Estimation Logic: Estimation calculations based on a flexible configuration
- Real-time Feedback: Updates the estimate as more information is provided
Windows:
# Run the PowerShell script
.\run.ps1
macOS/Linux:
# Make the script executable
chmod +x run.sh
# Run the script
./run.sh
- Clone the repository and navigate to the project directory
- Create and activate a virtual environment
- Install dependencies:
pip install -e .
- Set up your environment variables (copy
.env.example
to.env
and add your OpenAI API key) - Run the application:
python run.py
docker-compose up
- Installation Guide - Detailed setup instructions
- User Guide - How to use the system
- Architecture - System design and components
The system is built using a modern stack:
- Backend: FastAPI, Pydantic, Langchain, Langgraph, Uvicorn
- Frontend: Streamlit
- State Management: In-memory dictionary (for prototype simplicity)
- Language Model: OpenAI GPT-4o (via Langchain)
-
Input Handler (FastAPI & Streamlit):
- Accept text input and image uploads from users
- Manages session state and communication between frontend and backend
-
Conversation Manager (FastAPI & Langgraph):
- Maintains conversation state for each user session
- Uses Langgraph to define and manage the conversation flow
- Extracts information from user inputs
- Generates appropriate responses and questions
-
Estimation Logic (Python):
- Calculates estimates based on the provided configuration
- Supports various parameters (materials, regions, timelines, etc.)
- Generates a structured output with cost breakdown
interactive-estimation-system/
├── backend/ # FastAPI backend
│ ├── app/ # Application code
│ │ ├── __init__.py
│ │ ├── main.py # FastAPI app, endpoints
│ │ ├── models.py # Pydantic models
│ │ ├── graph.py # Langgraph definition
│ │ ├── estimator.py # Estimation calculation logic
│ │ ├── config.py # Load estimation config, API keys
│ │ └── utils.py # Helper functions
│ └── requirements.txt # Backend dependencies
├── frontend/ # Streamlit frontend
│ ├── app.py # Streamlit application
│ └── requirements.txt # Frontend dependencies
├── docker-compose.yml # Docker Compose configuration
├── Dockerfile # Docker build instructions
├── setup.py # Package installation
├── run.py # Script to run both servers
├── run.ps1 # PowerShell script for Windows
├── run.sh # Bash script for Unix/Linux
├── .env.example # Example environment variables
├── .gitignore # Git ignore file
├── ARCHITECTURE.md # System architecture details
├── INSTALL.md # Installation instructions
├── USER_GUIDE.md # User documentation
└── README.md # Project documentation
# Install test dependencies
pip install -e ".[test]"
# Run tests
pytest
To add new service types:
- Update the
config.json
file with the new service configuration - Add appropriate question templates in
utils.py
- Update the information extraction schema in
graph.py
if needed
This prototype has several limitations that could be addressed in future versions:
- State Management: Currently uses in-memory storage, which is not persistent
- Error Handling: Basic error handling implemented
- Service Types: Currently focused on roofing; could be expanded
Potential enhancements:
- Persistent Storage: Add a database for session storage
- Real Image Analysis: Integrate computer vision to extract information from images
- Multiple Service Types: Expand to support various service types
- User Authentication: Add user accounts and authentication
- Enhanced UI: More interactive and responsive frontend
A few notable issues have been fixed in this version:
-
Recursion Limit Error: Fixed by using
ainvoke()
instead ofinvoke()
with a higher recursion limit. -
Infinite Recursion Loop: The graph was transitioning back to
input_processor
without waiting for new user input. Fixed by modifying the graph to end after generating a response. -
Langgraph Return Type: Fixed the issue where Langgraph returns
AddableValuesDict
instead of aGraphState
object. This is now properly converted usingGraphState(**result)
. -
Pydantic Warnings: Added filters to suppress PydanticSchemaJson warnings.
- Shakil Mosharrof
- Github Copilot
- Windsurf IDE
- OpenAI for the GPT models
- Langchain and Langgraph for the conversation flow management
- FastAPI and Streamlit for the application framework