Skip to content

krishpatel143x-netizen/Claude_API_Version-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

34 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ€– Claude Assistant β€” Full Stack AI Chat Application

A production-ready ChatGPT-like application built with Streamlit, FastAPI, and Claude API (Anthropic).

Python FastAPI Streamlit Claude


✨ Features

  • πŸ’¬ 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

πŸ—οΈ Architecture

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

πŸš€ Quick Start

Prerequisites

1. Clone Repository

git clone <your-repo-url>
cd claude_assistant

2. Set Up Environment

# Copy environment template
cp .env.example .env

# Add your API key to .env
echo "ANTHROPIC_API_KEY=your_actual_key_here" > .env

3. Install Dependencies

Backend:

cd backend
pip install -r requirements.txt

Frontend:

cd ../frontend
pip install -r requirements.txt

4. Run the Application

Terminal 1 β€” Start Backend:

cd backend
uvicorn main:app --reload --port 8000

Terminal 2 β€” Start Frontend:

cd frontend
streamlit run app.py

Access the app:


☁️ Deploy to Streamlit Cloud

Option 1: Frontend Only (Simplified)

For Streamlit Cloud deployment, you can modify the frontend to call the Claude API directly:

  1. Push your code to GitHub
  2. Go to share.streamlit.io
  3. Connect your repository
  4. Add ANTHROPIC_API_KEY to Secrets (Settings β†’ Secrets)
  5. Deploy!

Note: For production with backend, deploy FastAPI separately (e.g., Railway, Render, Fly.io).

Option 2: Full Stack Deploy

  1. Backend: Deploy to Railway/Render

    # Railway example
    railway init
    railway up
  2. Frontend: Deploy to Streamlit Cloud

    • Set BACKEND_URL in Streamlit Secrets to your Railway/Render URL
    • Set ANTHROPIC_API_KEY in Secrets

πŸ› οΈ Available Tools

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?"

πŸ“ API Endpoints

POST /chat

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"
}

GET /

Health check.

GET /tools

List available tools.

DELETE /thread/{thread_id}

Delete a conversation thread.


πŸ” Environment Variables

Create a .env file:

# Required
ANTHROPIC_API_KEY=sk-ant-...

# Optional (for production)
BACKEND_URL=http://localhost:8000

For Streamlit Cloud, add these in Settings β†’ Secrets:

ANTHROPIC_API_KEY = "sk-ant-..."
BACKEND_URL = "https://your-backend.railway.app"

πŸ“¦ Project Dependencies

Backend:

  • fastapi β€” Web framework
  • anthropic β€” Claude API client
  • uvicorn β€” ASGI server
  • PyPDF2 β€” PDF processing

Frontend:

  • streamlit β€” UI framework
  • requests β€” HTTP client

🎯 Usage Examples

Basic Chat

User: Hello! How are you?
Claude: I'm doing well, thank you! How can I assist you today?

With Tools

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.

With File Upload

User: [uploads data.csv] Summarize this data
Claude: I've analyzed your CSV file. It contains sales data with 3 columns...

πŸ› Troubleshooting

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_URL in 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 .env is in the correct directory

πŸ“„ License

MIT License β€” feel free to use in your own projects!


🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Submit a pull request

πŸ“§ Support


πŸŽ‰ Credits

Built with ❀️ using:


Ready to deploy? Just push to GitHub and connect to Streamlit Cloud! πŸš€

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages