Star 历史趋势
数据来源: GitHub API · 生成自 Stargazers.cn
README.md
🚀 Streamlit Travel Agent Setup Guide
📁 Project Structure (Updated)
ai-travel-agent/
├── app.py # 🆕 Main Streamlit application
├── Assignment.ipynb # Original Jupyter notebook
├── README.md # Project documentation
├── requirements.txt # 🔄 Updated dependencies (includes Streamlit)
├── .env # Environment variables (keep local)
├── .gitignore # Git ignore file
└── .streamlit/ # 🆕 Streamlit configuration (optional)
└── config.toml # Custom Streamlit settings
🔧 Setup Instructions
1. Create the Streamlit App File
Create app.py in your project folder and copy the code from the artifact above.
2. Update Requirements
Replace your requirements.txt with the updated version that includes Streamlit.
3. Verify Your .env File
Make sure your .env file contains:
OPENAI_API_KEY=your_openai_api_key_here
SERPER_API_KEY=your_serper_api_key_here
OPENWEATHERMAP_API_KEY=your_openweathermap_api_key_here4. Install Dependencies
pip install -r requirements.txt🚀 Running Locally
Method 1: Simple Run
streamlit run app.pyMethod 2: Custom Port
streamlit run app.py --server.port 8080Method 3: Development Mode
streamlit run app.py --server.runOnSave trueYour app will open automatically in your browser at http://localhost:8501
🌐 Deployment Options
Option 1: Streamlit Community Cloud (FREE & RECOMMENDED)
- Push to GitHub (make sure your code is on GitHub)
- Go to share.streamlit.io
- Connect your GitHub account
- Deploy your repository:
- Repository:
your-username/ai-travel-agent - Branch:
main - Main file path:
app.py
- Repository:
- Add secrets in Streamlit Cloud dashboard:
- Go to "Manage app" → "Secrets"
- Add your API keys:
OPENAI_API_KEY = "your_key_here" SERPER_API_KEY = "your_key_here" OPENWEATHERMAP_API_KEY = "your_key_here"
Your app will be live at: https://your-app-name.streamlit.app
Option 2: Heroku
- Create
Procfile:
web: sh setup.sh && streamlit run app.py --server.port=$PORT --server.address=0.0.0.0
- Create
setup.sh:
mkdir -p ~/.streamlit/
echo "\
[server]\n\
headless = true\n\
port = $PORT\n\
enableCORS = false\n\
\n\
" > ~/.streamlit/config.toml- Deploy to Heroku:
heroku create your-travel-agent-app
git push heroku main
heroku config:set OPENAI_API_KEY=your_key_here
heroku config:set SERPER_API_KEY=your_key_here
heroku config:set OPENWEATHERMAP_API_KEY=your_key_hereOption 3: Railway
- Connect your GitHub repository
- Add environment variables in Railway dashboard
- Deploy automatically
🎨 Optional: Custom Streamlit Configuration
Create .streamlit/config.toml:
[theme]
primaryColor = "#667eea"
backgroundColor = "#ffffff"
secondaryBackgroundColor = "#f0f2f6"
textColor = "#262730"
[server]
runOnSave = true🧪 Testing Your App
Test Locally:
- Run
streamlit run app.py - Try different example queries
- Verify all tools are working
Test Features:
- ✅ Weather information displays
- ✅ Search results appear
- ✅ Calculations work correctly
- ✅ YouTube videos load
- ✅ Currency conversion functions
- ✅ Cost breakdown is accurate
📱 Mobile Responsiveness
Your Streamlit app is automatically mobile-responsive! Users can access it on:
- 💻 Desktop computers
- 📱 Mobile phones
- 📟 Tablets
🔒 Security Best Practices
For Production:
- Never commit API keys to GitHub
- Use Streamlit Secrets for deployment
- Add rate limiting if needed
- Monitor API usage to avoid overages
Environment Variables:
# In app.py - already handled
import os
from dotenv import load_dotenv
load_dotenv()
# API keys loaded securely
openai_key = os.getenv("OPENAI_API_KEY")🐛 Troubleshooting
Common Issues:
"ModuleNotFoundError"
pip install -r requirements.txt"API Key Error"
- Check your
.envfile - Verify API keys are correct
- Ensure no extra spaces in API keys
"Streamlit Command Not Found"
pip install streamlit"Port Already in Use"
streamlit run app.py --server.port 8502📈 Performance Tips
- Cache API calls using
@st.cache_data - Use session state for expensive operations
- Optimize large responses with pagination
- Add loading indicators for better UX
🎯 Next Steps
- ✅ Create the Streamlit app
- ✅ Test locally
- ✅ Deploy to Streamlit Cloud
- ✅ Share your live app link!
🌟 Features in Your Streamlit App
- 🎨 Beautiful UI with custom styling
- 📱 Mobile responsive design
- 🔄 Real-time processing with loading indicators
- 📊 Interactive components (selectboxes, buttons, metrics)
- 💾 Session state for chat history
- 🎯 Example queries for easy testing
- 📈 API status monitoring
- 🎥 Embedded YouTube videos
Your travel agent is now a full-featured web application! 🎉
Live Demo: https://your-app-name.streamlit.app (after deployment)