ND06-25 commited on
Commit
f393828
Β·
1 Parent(s): 637d78d

Revert-Railway troubleshooting

Browse files
Procfile CHANGED
@@ -1 +1 @@
1
- web: bash railway-start.sh
 
1
+ web: uvicorn api.main:app --host 0.0.0.0 --port $PORT
RAILWAY-FIXES.md DELETED
@@ -1,74 +0,0 @@
1
- # πŸ”§ Railway Deployment Fixes Applied
2
-
3
- ## Issues Found & Fixed
4
-
5
- ### βœ… 1. Port Configuration Fixed
6
- **Problem:** `api/main.py` was hardcoded to port 8000
7
- **Fix:** Updated to use `$PORT` environment variable
8
- ```python
9
- port = int(os.getenv("PORT", 8000))
10
- uvicorn.run(app, host="0.0.0.0", port=port)
11
- ```
12
-
13
- ### βœ… 2. NLTK Data Download Added
14
- **Problem:** NLTK data not available on Railway
15
- **Fix:** Created `railway-start.sh` to download NLTK data on startup
16
- ```bash
17
- python -c "import nltk; nltk.download('punkt'); nltk.download('stopwords')"
18
- ```
19
-
20
- ### βœ… 3. Startup Script Created
21
- **Problem:** No proper startup sequence
22
- **Fix:** Created `railway-start.sh` and updated `Procfile`
23
- ```
24
- web: bash railway-start.sh
25
- ```
26
-
27
- ### βœ… 4. Memory Optimization
28
- **Problem:** Large AI model causing memory issues
29
- **Fix:** Changed default model from `facebook/bart-large-cnn` to `t5-small`
30
- - Smaller model (60MB vs 1.6GB)
31
- - Faster loading
32
- - Less memory usage
33
-
34
- ## Files Modified
35
-
36
- 1. **`api/main.py`** - Added PORT environment variable support
37
- 2. **`api/summarizer.py`** - Changed default model to t5-small
38
- 3. **`Procfile`** - Updated to use startup script
39
- 4. **`railway-start.sh`** - Created new startup script
40
- 5. **`railway-troubleshooting.md`** - Created troubleshooting guide
41
-
42
- ## Next Steps
43
-
44
- 1. **Commit and push** these changes to GitHub
45
- 2. **Redeploy** on Railway
46
- 3. **Check logs** for any remaining issues
47
- 4. **Test the API** at your Railway URL + `/docs`
48
-
49
- ## Expected Results
50
-
51
- - βœ… Build should succeed
52
- - βœ… App should start properly
53
- - βœ… API should be accessible
54
- - βœ… Model loading should work (with smaller model)
55
- - βœ… NLTK data should be available
56
-
57
- ## If Still Having Issues
58
-
59
- 1. **Check Railway logs** for specific error messages
60
- 2. **Upgrade Railway plan** if memory issues persist
61
- 3. **Consider Hugging Face Spaces** as alternative
62
- 4. **Use even smaller model** if needed
63
-
64
- ## Testing Your Deployment
65
-
66
- Once deployed, test these endpoints:
67
- - `GET /` - Basic info
68
- - `GET /health` - Health check
69
- - `GET /models` - Available models
70
- - `POST /upload-pdf` - PDF validation
71
- - `POST /summarize` - Full summarization
72
-
73
- Your Railway URL will be something like:
74
- `https://your-app-name.up.railway.app`
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
api/main.py CHANGED
@@ -221,8 +221,4 @@ async def change_model(model_name: str):
221
 
222
  if __name__ == "__main__":
223
  import uvicorn
224
- import os
225
-
226
- # Get port from environment variable (for Railway deployment)
227
- port = int(os.getenv("PORT", 8000))
228
- uvicorn.run(app, host="0.0.0.0", port=port)
 
221
 
222
  if __name__ == "__main__":
223
  import uvicorn
224
+ uvicorn.run(app, host="0.0.0.0", port=8000)
 
 
 
 
api/summarizer.py CHANGED
@@ -11,7 +11,7 @@ class BookSummarizer:
11
  Handles AI-powered text summarization using transformer models.
12
  """
13
 
14
- def __init__(self, model_name: str = "t5-small"):
15
  """
16
  Initialize the summarizer with a specific model.
17
 
 
11
  Handles AI-powered text summarization using transformer models.
12
  """
13
 
14
+ def __init__(self, model_name: str = "facebook/bart-large-cnn"):
15
  """
16
  Initialize the summarizer with a specific model.
17
 
railway-start.sh DELETED
@@ -1,9 +0,0 @@
1
- #!/bin/bash
2
-
3
- # Download NLTK data
4
- echo "πŸ“₯ Downloading NLTK data..."
5
- python -c "import nltk; nltk.download('punkt'); nltk.download('stopwords')"
6
-
7
- # Start the FastAPI server
8
- echo "πŸš€ Starting Book Summarizer API..."
9
- uvicorn api.main:app --host 0.0.0.0 --port $PORT
 
 
 
 
 
 
 
 
 
 
railway-troubleshooting.md DELETED
@@ -1,97 +0,0 @@
1
- # πŸš‚ Railway Deployment Troubleshooting
2
-
3
- ## Your Build Was Successful! βœ…
4
- The log shows "Successfully Built!" which means your Docker image was created correctly.
5
-
6
- ## Common Runtime Issues & Solutions
7
-
8
- ### 1. **Port Configuration Issue**
9
- **Problem:** App not listening on the correct port
10
- **Solution:** Make sure your FastAPI app uses the PORT environment variable
11
-
12
- Check your `api/main.py` - it should look like this:
13
- ```python
14
- import os
15
- import uvicorn
16
-
17
- if __name__ == "__main__":
18
- port = int(os.getenv("PORT", 8000))
19
- uvicorn.run("api.main:app", host="0.0.0.0", port=port, reload=False)
20
- ```
21
-
22
- ### 2. **Memory Issues (Most Common)**
23
- **Problem:** AI models require more memory than Railway's free tier provides
24
- **Solution:**
25
- - Upgrade to Railway's paid plan ($5/month)
26
- - Or use a smaller model in `api/summarizer.py`
27
-
28
- ### 3. **Model Download Timeout**
29
- **Problem:** Hugging Face models take too long to download
30
- **Solution:** Add model caching or use smaller models
31
-
32
- ### 4. **Missing Dependencies**
33
- **Problem:** Some packages not installed correctly
34
- **Solution:** Check your `requirements.txt` is complete
35
-
36
- ## Quick Fixes to Try
37
-
38
- ### Fix 1: Update your Procfile
39
- Make sure your `Procfile` contains:
40
- ```
41
- web: uvicorn api.main:app --host 0.0.0.0 --port $PORT
42
- ```
43
-
44
- ### Fix 2: Add startup script
45
- Create `start.sh`:
46
- ```bash
47
- #!/bin/bash
48
- python -c "import nltk; nltk.download('punkt'); nltk.download('stopwords')"
49
- uvicorn api.main:app --host 0.0.0.0 --port $PORT
50
- ```
51
-
52
- ### Fix 3: Use smaller model
53
- In `api/summarizer.py`, change default model to:
54
- ```python
55
- def __init__(self, model_name: str = "t5-small"): # Smaller, faster model
56
- ```
57
-
58
- ## How to Check Railway Logs
59
-
60
- 1. Go to your Railway dashboard
61
- 2. Click on your project
62
- 3. Go to "Deployments" tab
63
- 4. Click on the latest deployment
64
- 5. Check "Logs" for runtime errors
65
-
66
- ## Common Error Messages & Solutions
67
-
68
- | Error | Solution |
69
- |-------|----------|
70
- | `Port already in use` | Check Procfile uses `$PORT` |
71
- | `Out of memory` | Upgrade Railway plan or use smaller model |
72
- | `Model download failed` | Use smaller model or add retry logic |
73
- | `Module not found` | Check requirements.txt |
74
- | `NLTK data missing` | Add NLTK download to startup |
75
-
76
- ## Quick Test
77
-
78
- Try this minimal test first:
79
- 1. Temporarily comment out model loading in `api/main.py`
80
- 2. Deploy to Railway
81
- 3. If it works, the issue is with the AI model loading
82
- 4. Then gradually add back the AI functionality
83
-
84
- ## Alternative: Use Hugging Face Spaces
85
-
86
- If Railway continues to have issues, consider deploying to Hugging Face Spaces:
87
- - Free GPU support
88
- - Optimized for AI models
89
- - Automatic deployment from GitHub
90
- - Better for transformer models
91
-
92
- ## Need Help?
93
-
94
- 1. Check Railway logs for specific error messages
95
- 2. Try the quick fixes above
96
- 3. Consider upgrading Railway plan for more resources
97
- 4. Or switch to Hugging Face Spaces for AI-specific hosting
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
start.sh CHANGED
@@ -25,12 +25,4 @@ echo "βœ… Dependencies installed"
25
 
26
  echo ""
27
  echo "πŸš€ Starting Book Summarizer AI..."
28
- python3 start.py
29
-
30
- # Download NLTK data
31
- echo "πŸ“₯ Downloading NLTK data..."
32
- python -c "import nltk; nltk.download('punkt'); nltk.download('stopwords')"
33
-
34
- # Start the FastAPI server
35
- echo "πŸš€ Starting Book Summarizer API..."
36
- uvicorn api.main:app --host 0.0.0.0 --port $PORT
 
25
 
26
  echo ""
27
  echo "πŸš€ Starting Book Summarizer AI..."
28
+ python3 start.py