Skip to content

Latest commit

 

History

History
230 lines (171 loc) · 5.93 KB

File metadata and controls

230 lines (171 loc) · 5.93 KB

🧪 TransPolymer Streamlit Deployment

Deploy your TransPolymer model to Streamlit Cloud for interactive polymer property predictions!

📋 Prerequisites

  1. GitHub Repository: Your code needs to be in a public GitHub repository
  2. Streamlit Cloud Account: Sign up at share.streamlit.io
  3. Model Files: Ensure you have the TransPolymer model files

🚀 Quick Deployment Steps

1. Prepare Your Repository

Make sure your repository contains these essential files:

TransPolymer/
├── app.py                          # Main Streamlit application
├── requirements.txt                # Dependencies
├── PolymerSmilesTokenization.py   # Custom tokenizer
├── dataset.py                     # Dataset utilities (if needed)
├── ckpt/                          # Model checkpoints (optional)
│   └── pretrain.pt/
│       ├── config.json
│       └── pytorch_model.bin
├── .streamlit/
│   └── config.toml                # Streamlit configuration
└── README_streamlit.md            # This file

2. Deploy to Streamlit Cloud

  1. Go to Streamlit Cloud: Visit share.streamlit.io

  2. Connect GitHub: Sign in with your GitHub account

  3. Deploy New App:

    • Click "New app"
    • Select your repository
    • Set branch to main or master
    • Set main file path to app.py
    • Click "Deploy!"
  4. Wait for Deployment: The initial deployment may take 5-10 minutes

3. Configuration Options

Create .streamlit/config.toml for better performance:

[theme]
primaryColor = "#FF6B6B"
backgroundColor = "#FFFFFF"
secondaryBackgroundColor = "#F0F2F6"
textColor = "#262730"

[server]
maxUploadSize = 200
maxMessageSize = 200

[browser]
gatherUsageStats = false

📁 File Descriptions

app.py

The main Streamlit application with:

  • Interactive web interface for polymer property prediction
  • Model loading and caching
  • SMILES validation
  • Batch prediction capabilities
  • Property selection and visualization

requirements.txt

Essential dependencies including:

  • streamlit>=1.25.0 - Web framework
  • torch>=1.12.0 - PyTorch for model inference
  • transformers>=4.20.1 - Hugging Face transformers
  • rdkit-pypi>=2022.3.4 - Chemistry library
  • Other supporting libraries

PolymerSmilesTokenization.py

Custom tokenizer for chemical-aware SMILES processing.

🔧 Troubleshooting

Common Issues

1. Memory Errors

  • Streamlit Cloud has memory limits (~1GB)
  • Consider using CPU-only PyTorch: torch>=1.12.0+cpu
  • Use model caching with @st.cache_resource

2. Large Model Files

  • Streamlit Cloud has file size limits
  • Consider using Git LFS for large files
  • Or download models at runtime from external storage

3. Dependency Conflicts

# Test locally first
pip install -r requirements.txt
streamlit run app.py

4. RDKit Installation Issues

  • Use rdkit-pypi instead of rdkit
  • Ensure Python version compatibility

Performance Optimization

  1. Model Caching:

    @st.cache_resource
    def load_model():
        # Model loading code
  2. Lazy Loading:

    • Load models only when needed
    • Use session state for persistent data
  3. Memory Management:

    • Use CPU instead of GPU for inference
    • Implement model quantization if needed

🧪 Testing Your Deployment

Local Testing

# Clone your repository
git clone <your-repo-url>
cd TransPolymer

# Install dependencies
pip install -r requirements.txt

# Run locally
streamlit run app.py

Example SMILES for Testing

CC(C)(C)OC(=O)NC1=CC=CC=C1          # Polymer Electrolyte
c1ccc2c(c1)oc1ccccc12               # Band Gap
c1ccc(cc1)c2ccc(cc2)C3=CC=C(C=C3)c4ccccc4  # OPV

📊 Features

  • Interactive Prediction: Real-time polymer property prediction
  • Multiple Properties: Support for 10+ different polymer properties
  • Batch Processing: Upload CSV files for multiple predictions
  • Property Selection: Choose from conductivity, band gap, OPV efficiency, etc.
  • Validation: SMILES string validation and error handling
  • Results Download: Export predictions as CSV files

🔗 Usage Example

Once deployed, users can:

  1. Select Property: Choose from the sidebar (PE_I, OPV, Egc, etc.)
  2. Enter SMILES: Input polymer SMILES string
  3. Get Prediction: Click predict to get property value
  4. Batch Process: Upload CSV files for multiple predictions
  5. Download Results: Export predictions for further analysis

📈 App Features

Main Interface

  • Clean, intuitive design
  • Real-time SMILES validation
  • Property-specific examples
  • Responsive layout

Batch Predictions

  • CSV file upload
  • Progress tracking
  • Results preview
  • Download functionality

Information Panels

  • Property descriptions
  • Units and context
  • Model information
  • Citation and references

🚀 Advanced Deployment Options

Custom Domain (Pro Feature)

  • Connect your own domain
  • SSL certificates included
  • Custom branding options

Resource Management

  • Monitor app performance
  • Set resource limits
  • Implement auto-scaling

Environment Variables

  • Store sensitive configuration
  • Manage different environments
  • API keys and secrets

📚 References

🆘 Support

If you encounter issues:

  1. Check the Streamlit Cloud logs
  2. Test locally with the same requirements
  3. Review the Streamlit forum
  4. Check GitHub issues for common problems

📄 License

This deployment guide is provided as-is. Please ensure you comply with all relevant licenses for TransPolymer and its dependencies.


Happy Deploying! 🎉

Your TransPolymer model will be accessible at: https://your-app-name.streamlit.app