# 🌐 Free Cloud Deployment Guide ## 🎯 Best Free Options for Your Project ### ✅ **Recommended: Streamlit Community Cloud** - **Perfect for your project** (Streamlit frontend) - **Completely free** - **Easy GitHub integration** - **Custom domain support** ### ✅ **Alternative: Hugging Face Spaces** - **Free GPU/CPU hosting** - **Perfect for AI/ML projects** - **Great for showcasing AI models** ### ✅ **Backup: Railway/Render** - **Full-stack deployment** - **Free tiers available** - **Good for production demos** --- ## 🚀 **Option 1: Streamlit Community Cloud (RECOMMENDED)** ### Prerequisites: 1. **GitHub account** (free) 2. **Streamlit account** (free - sign up with GitHub) ### Step 1: Prepare Your Repository Create these files for Streamlit Cloud deployment: #### **requirements.txt** (for Streamlit Cloud) ```txt # Core dependencies streamlit==1.28.2 requests==2.31.0 pandas==2.1.3 numpy==1.24.3 python-dateutil==2.8.2 # Visualization plotly==5.17.0 altair==5.1.2 # UI components streamlit-option-menu==0.3.6 streamlit-aggrid==0.3.4.post3 # For language detection (lightweight) langdetect==1.0.9 ``` #### **streamlit_app.py** (Entry point) ```python # Streamlit Cloud entry point import streamlit as st import sys import os # Add frontend directory to path sys.path.append(os.path.join(os.path.dirname(__file__), 'frontend')) # Import the main app from app import main if __name__ == "__main__": main() ``` #### **.streamlit/config.toml** (Streamlit configuration) ```toml [server] headless = true port = 8501 [browser] gatherUsageStats = false [theme] primaryColor = "#FF6B6B" backgroundColor = "#FFFFFF" secondaryBackgroundColor = "#F0F2F6" textColor = "#262730" ``` ### Step 2: Create Cloud-Compatible Backend Since Streamlit Cloud can't run your FastAPI backend, we'll create a lightweight version: #### **cloud_backend.py** (Mock backend for demo) ```python """ Lightweight backend simulation for Streamlit Cloud deployment This provides mock responses that look realistic for demos """ import random import time from typing import Dict, List import pandas as pd from datetime import datetime class CloudTranslationService: """Mock translation service for cloud deployment""" def __init__(self): self.languages = { "en": "English", "hi": "Hindi", "bn": "Bengali", "gu": "Gujarati", "kn": "Kannada", "ml": "Malayalam", "mr": "Marathi", "or": "Odia", "pa": "Punjabi", "ta": "Tamil", "te": "Telugu", "ur": "Urdu", "as": "Assamese", "ne": "Nepali", "sa": "Sanskrit" } # Sample translations for realistic demo self.sample_translations = { ("hello", "en", "hi"): "नमस्ते", ("smartphone", "en", "hi"): "स्मार्टफोन", ("book", "en", "hi"): "किताब", ("computer", "en", "hi"): "कंप्यूटर", ("beautiful", "en", "hi"): "सुंदर", ("hello", "en", "ta"): "வணக்கம்", ("smartphone", "en", "ta"): "ஸ்மார்ட்ஃபோன்", ("book", "en", "ta"): "புத்தகம்", ("hello", "en", "te"): "నమస్కారం", ("smartphone", "en", "te"): "స్మార్ట్‌ఫోన్", } # Mock translation history self.history = [] self._generate_sample_history() def _generate_sample_history(self): """Generate realistic sample history""" sample_data = [ ("Premium Smartphone with 128GB storage", "प्रीमियम स्मार्टफोन 128GB स्टोरेज के साथ", "en", "hi", 0.94), ("Wireless Bluetooth Headphones", "वायरलेस ब्लूटूथ हेडफोन्स", "en", "hi", 0.91), ("Cotton T-Shirt for Men", "पुरुषों के लिए कॉटन टी-शर्ट", "en", "hi", 0.89), ("Premium Smartphone with 128GB storage", "128GB சேமிப்பகத்துடன் பிரீமியம் ஸ்மார்ட்ஃபோன்", "en", "ta", 0.92), ("Wireless Bluetooth Headphones", "వైర్‌లెస్ బ్లూటూత్ హెడ్‌ఫోన్‌లు", "en", "te", 0.90), ] for i, (orig, trans, src, tgt, conf) in enumerate(sample_data): self.history.append({ "id": i + 1, "original_text": orig, "translated_text": trans, "source_language": src, "target_language": tgt, "model_confidence": conf, "created_at": "2025-01-25T10:30:00", "corrected_text": None }) def detect_language(self, text: str) -> Dict: """Mock language detection""" # Simple heuristic detection if any(char in text for char in "अआइईउऊएऐओऔकखगघचछजझटठडढणतथदधनपफबभमयरलवशषसह"): return {"language": "hi", "confidence": 0.95, "language_name": "Hindi"} elif any(char in text for char in "அஆஇஈஉஊஎஏஐஒஓஔகஙசஞடணதநபமயரலவழளறன"): return {"language": "ta", "confidence": 0.94, "language_name": "Tamil"} else: return {"language": "en", "confidence": 0.98, "language_name": "English"} def translate(self, text: str, source_lang: str, target_lang: str) -> Dict: """Mock translation with realistic responses""" time.sleep(1) # Simulate processing time # Check for exact matches first key = (text.lower(), source_lang, target_lang) if key in self.sample_translations: translated = self.sample_translations[key] confidence = round(random.uniform(0.88, 0.96), 2) else: # Generate realistic-looking translations if target_lang == "hi": translated = f"[Hindi] {text}" elif target_lang == "ta": translated = f"[Tamil] {text}" elif target_lang == "te": translated = f"[Telugu] {text}" else: translated = f"[{self.languages.get(target_lang, target_lang)}] {text}" confidence = round(random.uniform(0.82, 0.94), 2) # Add to history translation_id = len(self.history) + 1 self.history.append({ "id": translation_id, "original_text": text, "translated_text": translated, "source_language": source_lang, "target_language": target_lang, "model_confidence": confidence, "created_at": datetime.now().isoformat(), "corrected_text": None }) return { "translated_text": translated, "source_language": source_lang, "target_language": target_lang, "confidence": confidence, "translation_id": translation_id } def get_history(self, limit: int = 50) -> List[Dict]: """Get translation history""" return self.history[-limit:] def submit_correction(self, translation_id: int, corrected_text: str, feedback: str = "") -> Dict: """Submit correction""" for item in self.history: if item["id"] == translation_id: item["corrected_text"] = corrected_text break return { "correction_id": random.randint(1000, 9999), "message": "Correction submitted successfully", "status": "success" } def get_supported_languages(self) -> Dict: """Get supported languages""" return { "languages": self.languages, "total_count": len(self.languages) } # Global instance cloud_service = CloudTranslationService() ``` ### Step 3: Modify Frontend for Cloud #### **frontend/cloud_app.py** (Cloud-optimized version) ```python """ Cloud-optimized version of the Multi-Lingual Catalog Translator Works without FastAPI backend by using mock services """ import streamlit as st import sys import os # Add parent directory to path to import cloud_backend sys.path.append(os.path.dirname(os.path.dirname(__file__))) from cloud_backend import cloud_service # Copy your existing app.py code here but replace API calls with cloud_service calls # For example: st.set_page_config( page_title="Multi-Lingual Catalog Translator", page_icon="🌐", layout="wide" ) def main(): st.title("🌐 Multi-Lingual Product Catalog Translator") st.markdown("### Powered by IndicTrans2 by AI4Bharat") st.markdown("**🚀 Cloud Demo Version**") # Add a banner explaining this is a demo st.info("🌟 **This is a cloud demo version with simulated AI responses**. The full version with real IndicTrans2 models runs locally and can be deployed on cloud infrastructure with GPU support.") # Your existing UI code here... # Replace API calls with cloud_service calls if __name__ == "__main__": main() ``` ### Step 4: Deploy to Streamlit Cloud 1. **Push to GitHub:** ```bash git add . git commit -m "Add Streamlit Cloud deployment" git push origin main ``` 2. **Deploy on Streamlit Cloud:** - Go to [share.streamlit.io](https://share.streamlit.io) - Sign in with GitHub - Click "New app" - Select your repository - Set main file path: `streamlit_app.py` - Click "Deploy" 3. **Your app will be live at:** `https://[your-username]-[repo-name]-streamlit-app-[hash].streamlit.app` --- ## 🤗 **Option 2: Hugging Face Spaces** Perfect for AI/ML projects with free GPU access! ### Step 1: Create Space Files #### **app.py** (Hugging Face entry point) ```python import gradio as gr import requests import json def translate_text(text, source_lang, target_lang): # Your translation logic here # Can use the cloud_backend for demo return f"Translated: {text} ({source_lang} → {target_lang})" # Create Gradio interface demo = gr.Interface( fn=translate_text, inputs=[ gr.Textbox(label="Text to translate"), gr.Dropdown(["en", "hi", "ta", "te", "bn"], label="Source Language"), gr.Dropdown(["en", "hi", "ta", "te", "bn"], label="Target Language") ], outputs=gr.Textbox(label="Translation"), title="Multi-Lingual Catalog Translator", description="AI-powered translation for e-commerce using IndicTrans2" ) if __name__ == "__main__": demo.launch() ``` #### **requirements.txt** (for Hugging Face) ```txt gradio==3.50.0 transformers==4.35.0 torch==2.1.0 fasttext==0.9.2 ``` ### Step 2: Deploy to Hugging Face 1. Create account at [huggingface.co](https://huggingface.co) 2. Create new Space 3. Upload your files 4. Your app will be live at `https://huggingface.co/spaces/[username]/[space-name]` --- ## 🚂 **Option 3: Railway (Full-Stack)** For deploying both frontend and backend: ### Step 1: Create Railway Configuration #### **railway.json** ```json { "build": { "builder": "NIXPACKS" }, "deploy": { "startCommand": "streamlit run streamlit_app.py --server.port $PORT --server.address 0.0.0.0", "healthcheckPath": "/", "healthcheckTimeout": 100 } } ``` ### Step 2: Deploy 1. Go to [railway.app](https://railway.app) 2. Connect GitHub repository 3. Deploy automatically --- ## 📋 **Quick Setup for Streamlit Cloud** Let me create the necessary files for you: