A production-ready ChatGPT-like application built with Streamlit, FastAPI, and Claude API (Anthropic).
- π¬ Multi-turn conversations with thread-based memory
- π File upload support (TXT, CSV, PDF)
- π οΈ Function calling with built-in tools:
- Weather information
- Mathematical operations
- Date/time queries
- π¨ Clean, modern UI (ChatGPT-style)
- π Secure API communication
- βοΈ Deploy-ready for Streamlit Cloud
claude_assistant/
β
βββ backend/ # FastAPI server
β βββ main.py # API endpoints
β βββ tools.py # Tool definitions
β βββ requirements.txt
β
βββ frontend/ # Streamlit UI
β βββ app.py # Chat interface
β βββ requirements.txt
β
βββ .env.example # Environment template
βββ Procfile # Deployment config
βββ README.md
- Python 3.9+
- Anthropic API key (Get one here)
git clone <your-repo-url>
cd claude_assistant# Copy environment template
cp .env.example .env
# Add your API key to .env
echo "ANTHROPIC_API_KEY=your_actual_key_here" > .envBackend:
cd backend
pip install -r requirements.txtFrontend:
cd ../frontend
pip install -r requirements.txtTerminal 1 β Start Backend:
cd backend
uvicorn main:app --reload --port 8000Terminal 2 β Start Frontend:
cd frontend
streamlit run app.pyAccess the app:
- Frontend: http://localhost:8501
- Backend API: http://localhost:8000
- API docs: http://localhost:8000/docs
For Streamlit Cloud deployment, you can modify the frontend to call the Claude API directly:
- Push your code to GitHub
- Go to share.streamlit.io
- Connect your repository
- Add
ANTHROPIC_API_KEYto Secrets (Settings β Secrets) - Deploy!
Note: For production with backend, deploy FastAPI separately (e.g., Railway, Render, Fly.io).
-
Backend: Deploy to Railway/Render
# Railway example railway init railway up -
Frontend: Deploy to Streamlit Cloud
- Set
BACKEND_URLin Streamlit Secrets to your Railway/Render URL - Set
ANTHROPIC_API_KEYin Secrets
- Set
The assistant can execute these tools automatically:
| Tool | Example Query |
|---|---|
| Weather | "What's the weather in Tokyo?" |
| Addition | "Add 42 and 17" |
| Multiplication | "Multiply 8 by 12" |
| Time | "What time is it?" |
Main chat endpoint.
Request:
{
"message": "Hello!",
"thread_id": "optional-thread-id",
"file_content": "optional file text",
"file_name": "document.txt"
}Response:
{
"reply": "Hi! How can I help?",
"thread_id": "uuid-here",
"tool_used": "get_weather",
"tool_result": "βοΈ Sunny, 72Β°F"
}Health check.
List available tools.
Delete a conversation thread.
Create a .env file:
# Required
ANTHROPIC_API_KEY=sk-ant-...
# Optional (for production)
BACKEND_URL=http://localhost:8000For Streamlit Cloud, add these in Settings β Secrets:
ANTHROPIC_API_KEY = "sk-ant-..."
BACKEND_URL = "https://your-backend.railway.app"Backend:
fastapiβ Web frameworkanthropicβ Claude API clientuvicornβ ASGI serverPyPDF2β PDF processing
Frontend:
streamlitβ UI frameworkrequestsβ HTTP client
User: Hello! How are you?
Claude: I'm doing well, thank you! How can I assist you today?
User: What's the weather in London?
π οΈ Tool used: get_weather
Claude: The weather in London is currently π§οΈ Rainy, 55Β°F (13Β°C), with moderate wind.
User: [uploads data.csv] Summarize this data
Claude: I've analyzed your CSV file. It contains sales data with 3 columns...
Backend won't start:
# Check if port 8000 is in use
lsof -i :8000
# Use different port
uvicorn main:app --port 8001"Cannot connect to backend" error:
- Ensure backend is running on port 8000
- Check
BACKEND_URLin frontend - Verify CORS settings in
main.py
API key errors:
- Verify key is correctly set in
.env - Check key format starts with
sk-ant- - Ensure
.envis in the correct directory
MIT License β feel free to use in your own projects!
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
- Issues: Open a GitHub issue
- Anthropic API Docs: https://docs.anthropic.com
- Streamlit Docs: https://docs.streamlit.io
Built with β€οΈ using:
Ready to deploy? Just push to GitHub and connect to Streamlit Cloud! π