This project demonstrates how to build a modern AI chatbot with file upload capabilities using POML (Prompt Orchestration Markup Language) for advanced prompt engineering. Perfect for beginners learning AI development and prompt engineering concepts.
- Modern prompt engineering with POML
- FastAPI backend development
- Angular v20+ frontend with signals
- Document processing and analysis
- File upload handling
- AI integration best practices
- 💬 Text Chat: Conversational AI powered by POML templates
- 📄 Document Analysis: Upload and analyze PDF, TXT, DOCX, CSV files
- 🎨 Modern UI: Angular v20+ with signals and standalone components
- 🔄 POML Integration: Native document parsing without custom logic
- 🚀 Simplified API: Clean, beginner-friendly FastAPI endpoints
- Python 3.10+ with FastAPI
- POML for prompt orchestration
- Google Gemini AI for language processing
- Langchain for AI framework integration
- Angular v20+ with signals
- Standalone Components architecture
- Drag & Drop file upload
- Real-time chat interface
ai-chatbot-with-python-and-angular/
├── 🐍 Backend (Python FastAPI)
│ ├── api.py # Main FastAPI application (30 lines!)
│ ├── chatbot.py # Core chatbot logic
│ ├── prompt.poml # POML template for chat & documents
│ ├── requirements.txt # Python dependencies
│ └── .env # Environment variables
│
├── 🅰️ Frontend (Angular)
│ └── chat-interface/
│ ├── src/app/
│ │ ├── components/chat/
│ │ └── services/
│ ├── public/
│ │ └── branding.json
│ └── package.json
│
└── 📚 Documentation
└── README.md # This file
Before you start, ensure you have:
- Node.js 18+ installed
- Python 3.10+ installed
- Git installed
- Google Gemini API Key (Get it here)
# Clone the repository
git clone https://github.com/hereandnowai/ai-chatbot-with-python-and-angular.git
# Navigate to project directory
cd ai-chatbot-with-python-and-angular
# Create virtual environment
python3 -m venv .venv
# Activate virtual environment
# On Linux/Mac:
source .venv/bin/activate
# On Windows:
# .venv\Scripts\activate
# Install Python packages
pip install -r requirements.txt
# Create environment file
cp .env.example .env
# Edit .env file and add your API key
nano .env
Add your Google Gemini API key to .env
:
GEMINI_API_KEY=your_gemini_api_key_here
# Start the FastAPI server
python api.py
# Alternative: Use uvicorn directly
# uvicorn api:app --host 0.0.0.0 --port 8001 --reload
✅ Backend Running: http://localhost:8001
Open a new terminal and navigate to the frontend directory:
# Navigate to frontend directory
cd frontend/chat-interface
# Install Node.js dependencies
npm install
# Start Angular development server
npm start
# Alternative command:
# ng serve
✅ Frontend Running: http://localhost:4200
- Open http://localhost:4200
- Type your question about Angular development
- Press Send or hit Enter
Example Questions:
What are Angular signals?
How do I create standalone components?
Explain the new control flow syntax
- Click the 📎 attachment icon
- Upload a document (PDF, TXT, DOCX, CSV)
- Ask questions about the document content
Example Questions:
What are the key features in this document?
Summarize the main points
What technologies are mentioned?
GET http://localhost:8001/api/health
POST http://localhost:8001/api/chat
Content-Type: application/json
{
"message": "What is Angular?"
}
POST http://localhost:8001/api/chat/upload
Content-Type: multipart/form-data
file: [your-document.pdf]
message: "Analyze this document"
# Custom file parsing - 300+ lines of code
if file.endswith('.pdf'):
content = extract_pdf_text(file)
elif file.endswith('.docx'):
content = extract_docx_text(file)
elif file.endswith('.txt'):
content = read_text_file(file)
# ... more parsing logic
<!-- Just 1 line in POML template! -->
<document src="{{ file_path }}" parser="auto" />
<poml>
<system-msg>
<p if="{{ file_path }}">Document analysis assistant</p>
<p if="{{ !file_path }}">Angular development expert</p>
</system-msg>
<human-msg>
<!-- Document content (if uploaded) -->
<cp if="{{ file_path }}" caption="Document Content">
<document src="{{ file_path }}" parser="auto" />
</cp>
<!-- User question -->
<cp caption="User Question">
<p>{{ question }}</p>
</cp>
</human-msg>
</poml>
- Modify Code: Edit
api.py
,chatbot.py
, orprompt.poml
- Auto-Reload: FastAPI automatically reloads on changes
- Test: Use curl or frontend to test changes
# Test text chat
curl -X POST "http://localhost:8001/api/chat" \
-H "Content-Type: application/json" \
-d '{"message": "Hello!"}'
# Test file upload
curl -X POST "http://localhost:8001/api/chat/upload" \
-F "[email protected]" \
-F "message=Analyze this file"
- Modify Code: Edit Angular components in
src/app/
- Auto-Reload: Angular CLI automatically reloads browser
- Test: Interact with the chat interface
- 30 lines of FastAPI code instead of 200+
- 2 endpoints handle all functionality
- Clean error handling and file management
// Using signals for reactive state
isConnected = signal<boolean>(false);
// Standalone components
@Component({
standalone: true,
imports: [CommonModule, ReactiveFormsModule]
})
// New control flow
@if (isConnected()) {
<p>Backend connected ✅</p>
} @else {
<p>Backend disconnected ❌</p>
}
- Conditional logic with
if="{{ condition }}"
- Semantic components like
<cp>
and<document>
- Template reuse for multiple scenarios
Problem: ModuleNotFoundError
# Solution: Activate virtual environment
source .venv/bin/activate
pip install -r requirements.txt
Problem: GEMINI_API_KEY not found
# Solution: Check .env file
cat .env
# Make sure GEMINI_API_KEY=your_key_here
Problem: Port 8001 already in use
# Solution: Kill existing process
pkill -f "python.*api.py"
# Or use different port
uvicorn api:app --port 8002
Problem: ng: command not found
# Solution: Install Angular CLI
npm install -g @angular/cli
Problem: Port 4200 already in use
# Solution: Use different port
ng serve --port 4201
Problem: Backend connection failed
- ✅ Check backend is running on http://localhost:8001
- ✅ Check CORS is enabled in
api.py
- ✅ Verify
/api/health
endpoint responds
User: "What are the benefits of signals in Angular?"
AI: "Signals provide fine-grained reactivity, better performance..."
Upload: project-requirements.pdf
Question: "What are the main requirements?"
AI: "The document lists 5 key requirements: 1. User authentication..."
Upload: component.ts
Question: "How can I improve this component?"
AI: "Consider using signals instead of observables for state management..."
Create specialized templates for different use cases:
<!-- Code review template -->
<poml>
<system-msg>
<p>You are a senior Angular developer reviewing code for best practices.</p>
</system-msg>
<human-msg>
<cp caption="Code to Review">
<document src="{{ file_path }}" />
</cp>
<hint>Provide specific, actionable feedback using Angular v20+ best practices.</hint>
</human-msg>
</poml>
# Development
GEMINI_API_KEY=dev_key
DEBUG=true
# Production
GEMINI_API_KEY=prod_key
DEBUG=false
CORS_ORIGINS=["https://yourdomain.com"]
We welcome contributions! Here's how to get started:
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
HERE AND NOW AI
🌐 Website: hereandnowai.com
📧 Email: [email protected]
📱 Mobile: +91 996 296 1000
Connect with us:
This project is open source and available under the MIT License.