bobbyni819's picture
Upload 15 files
abb96d7 verified

A newer version of the Streamlit SDK is available: 1.56.0

Upgrade
metadata
title: Hickey Lab AI Assistant
emoji: 🧬
colorFrom: blue
colorTo: purple
sdk: streamlit
sdk_version: 1.52.1
app_file: app.py
pinned: false

Hickey Lab AI Assistant - Production Ready ✨

A production-ready Streamlit chatbot powered by Google Gemini 2.5 Flash and the File Search API.

🎯 Features

  • βœ… Cost Management - Tracks usage and enforces budget limits
  • βœ… Rate Limiting - Prevents abuse (20 queries/hour per user)
  • βœ… Security - Input validation and prompt injection protection
  • βœ… Push Notifications - Get alerted about important events (via ntfy.sh)
  • βœ… Conversation Context - Remembers previous messages for better responses
  • βœ… Mobile Friendly - Responsive design for all devices
  • βœ… Usage Statistics - Real-time monitoring in sidebar

πŸš€ Quick Start (5 minutes)

See QUICK_START.md for deployment instructions.

TL;DR:

  1. Upload files to HuggingFace Space
  2. Set GEMINI_API_KEY secret
  3. (Optional) Set NTFY_TOPIC for notifications
  4. Done!

πŸ“š Documentation

Document Description
QUICK_START.md 5-minute deployment guide
FEATURE_SUMMARY.md What each tool does (for non-technical users)
IMPLEMENTATION_GUIDE.md Detailed technical documentation

πŸ§ͺ Testing

Run the setup test to verify everything works:

python test_setup.py

This tests all modules and configurations.

πŸ“ Project Structure

gemini_file_search/
β”œβ”€β”€ app.py                    # Main Streamlit app (enhanced)
β”œβ”€β”€ config.py                 # Configuration settings
β”œβ”€β”€ requirements.txt          # Python dependencies
β”œβ”€β”€ test_setup.py            # Setup verification script
β”œβ”€β”€ utils/                   # Utility modules
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ cost_tracker.py      # Cost management
β”‚   β”œβ”€β”€ rate_limiter.py      # Rate limiting
β”‚   β”œβ”€β”€ security.py          # Security validation
β”‚   └── alerts.py            # Push notifications (ntfy.sh)
└── docs/
    β”œβ”€β”€ QUICK_START.md       # Quick deployment guide
    β”œβ”€β”€ FEATURE_SUMMARY.md   # What each feature does
    └── IMPLEMENTATION_GUIDE.md  # Technical details

βš™οΈ Configuration

Edit config.py to customize:

# Cost limits
MONTHLY_BUDGET_USD = 50.0
DAILY_QUERY_LIMIT = 200

# Rate limits
RATE_LIMIT_PER_HOUR = 20
RATE_LIMIT_PER_DAY = 200

# Suggested questions
SUGGESTED_QUESTIONS = [...]

# And more...

πŸ”‘ Environment Variables

Variable Required Description
GEMINI_API_KEY βœ… Yes Your Google AI API key from aistudio.google.com
NTFY_TOPIC ⭐ Recommended Your ntfy.sh topic for push notifications

πŸ“Š Monitoring

In the App:

  • Check "πŸ“Š Show Usage Stats" in sidebar
  • See today's query count and cost
  • View monthly totals

Push Notifications (if enabled):

  • Rate limit violations
  • Cost threshold alerts
  • Security warnings
  • Budget exceeded alerts

πŸ†˜ Troubleshooting

App won't start:

  • Check logs in HuggingFace Space
  • Verify GEMINI_API_KEY is set as a Secret
  • Make sure all files are uploaded

Notifications not working:

  • Check NTFY_TOPIC is set
  • Test with: curl -d "test" ntfy.sh/your-topic
  • Verify you're subscribed to the correct topic

Rate limit too strict:

  • Edit RATE_LIMIT_PER_HOUR in config.py
  • Default is 20 queries/hour

See IMPLEMENTATION_GUIDE.md for more troubleshooting.

πŸ’‘ What's New

This is an upgraded version with production features:

  • Cost tracking prevents surprise bills
  • Rate limiting prevents abuse
  • Security validation blocks attacks
  • Push notifications keep you informed
  • Conversation context improves responses

See FEATURE_SUMMARY.md for detailed explanations.

πŸ”— Embedding in Google Sites

Once deployed, you'll get a public URL. To add to Google Sites:

  1. Simple Link (Always works):

    • Add a button: "Chat with our AI Assistant β†’"
    • Link to your HuggingFace Space URL
  2. Embed (HuggingFace Spaces):

    • In Google Sites: Insert β†’ Embed β†’ By URL
    • Paste your Space URL
    • Adjust size as needed

πŸ“ˆ Cost Estimates

Based on Gemini 2.5 Flash pricing:

  • ~$0.0003 per query (average)
  • 100 queries = $0.03
  • 1,000 queries = $0.30
  • 10,000 queries = $3.00

Default monthly cap: $50 (adjustable in config)

🀝 Support

For issues or questions:

  1. Check the documentation files
  2. Review HuggingFace Space logs
  3. Run python test_setup.py to verify setup
  4. Check that environment variables are set correctly

Production ready and deployed in minutes! πŸš€