Spaces:
Sleeping
Sleeping
arun3676 commited on
Commit ·
1b4857b
1
Parent(s): f5c4d0b
Fix Render deployment issues: update configs, add health check, fix environment handling
Browse files- Procfile +1 -1
- app.py +46 -4
- render.yaml +3 -2
- requirements.txt +3 -2
Procfile
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
web: streamlit run
|
|
|
|
| 1 |
+
web: streamlit run app.py --server.port=$PORT --server.address=0.0.0.0 --server.headless=true --server.enableCORS=false
|
app.py
CHANGED
|
@@ -1,11 +1,34 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import os
|
|
|
|
| 3 |
from dotenv import load_dotenv
|
| 4 |
from analyzer import CodeAnalyzer
|
| 5 |
import json
|
| 6 |
|
| 7 |
-
# Load environment variables
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
# Page config
|
| 11 |
st.set_page_config(
|
|
@@ -58,13 +81,32 @@ st.markdown("""
|
|
| 58 |
</style>
|
| 59 |
""", unsafe_allow_html=True)
|
| 60 |
|
| 61 |
-
# Initialize analyzer
|
| 62 |
@st.cache_resource
|
| 63 |
def get_analyzer():
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
analyzer = get_analyzer()
|
| 67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
def display_analysis_result(result: dict, model_name: str):
|
| 69 |
"""Display analysis result in a formatted way."""
|
| 70 |
if 'error' in result:
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import os
|
| 3 |
+
import time
|
| 4 |
from dotenv import load_dotenv
|
| 5 |
from analyzer import CodeAnalyzer
|
| 6 |
import json
|
| 7 |
|
| 8 |
+
# Load environment variables - only in development
|
| 9 |
+
if os.path.exists('.env'):
|
| 10 |
+
load_dotenv()
|
| 11 |
+
|
| 12 |
+
# Simple health check for Render
|
| 13 |
+
def is_health_check():
|
| 14 |
+
"""Check if this is a health check request"""
|
| 15 |
+
try:
|
| 16 |
+
# Check URL parameters
|
| 17 |
+
if "health" in st.query_params or "healthz" in st.query_params:
|
| 18 |
+
return True
|
| 19 |
+
return False
|
| 20 |
+
except:
|
| 21 |
+
return False
|
| 22 |
+
|
| 23 |
+
# Handle health check
|
| 24 |
+
if is_health_check():
|
| 25 |
+
st.json({
|
| 26 |
+
"status": "healthy",
|
| 27 |
+
"service": "ai-code-analyzer",
|
| 28 |
+
"timestamp": time.time(),
|
| 29 |
+
"uptime": "ok"
|
| 30 |
+
})
|
| 31 |
+
st.stop()
|
| 32 |
|
| 33 |
# Page config
|
| 34 |
st.set_page_config(
|
|
|
|
| 81 |
</style>
|
| 82 |
""", unsafe_allow_html=True)
|
| 83 |
|
| 84 |
+
# Initialize analyzer with better error handling
|
| 85 |
@st.cache_resource
|
| 86 |
def get_analyzer():
|
| 87 |
+
try:
|
| 88 |
+
return CodeAnalyzer()
|
| 89 |
+
except Exception as e:
|
| 90 |
+
st.error(f"Failed to initialize analyzer: {str(e)}")
|
| 91 |
+
st.info("Please ensure your API keys are properly configured in the environment variables.")
|
| 92 |
+
return None
|
| 93 |
|
| 94 |
analyzer = get_analyzer()
|
| 95 |
|
| 96 |
+
# Check if analyzer is available
|
| 97 |
+
if analyzer is None:
|
| 98 |
+
st.error("⚠️ Code Analyzer is not available. Please check your API key configuration.")
|
| 99 |
+
st.info("""
|
| 100 |
+
**Required Environment Variables:**
|
| 101 |
+
- `OPENAI_API_KEY` - For OpenAI GPT-4 analysis
|
| 102 |
+
- `ANTHROPIC_API_KEY` - For Claude analysis
|
| 103 |
+
- `GEMINI_API_KEY` - For Google Gemini analysis
|
| 104 |
+
- `DEEPSEEK_API_KEY` - For DeepSeek analysis
|
| 105 |
+
|
| 106 |
+
At least one API key is required for the application to work.
|
| 107 |
+
""")
|
| 108 |
+
st.stop()
|
| 109 |
+
|
| 110 |
def display_analysis_result(result: dict, model_name: str):
|
| 111 |
"""Display analysis result in a formatted way."""
|
| 112 |
if 'error' in result:
|
render.yaml
CHANGED
|
@@ -1,12 +1,13 @@
|
|
| 1 |
services:
|
| 2 |
- type: web
|
| 3 |
-
name:
|
| 4 |
env: python
|
| 5 |
repo: https://github.com/arun3676/ai-code-analyzer.git
|
| 6 |
branch: master
|
| 7 |
buildCommand: pip install -r requirements.txt
|
| 8 |
-
startCommand: streamlit run
|
| 9 |
plan: free
|
|
|
|
| 10 |
envVars:
|
| 11 |
- key: OPENAI_API_KEY
|
| 12 |
sync: false
|
|
|
|
| 1 |
services:
|
| 2 |
- type: web
|
| 3 |
+
name: ai-code-analyzer
|
| 4 |
env: python
|
| 5 |
repo: https://github.com/arun3676/ai-code-analyzer.git
|
| 6 |
branch: master
|
| 7 |
buildCommand: pip install -r requirements.txt
|
| 8 |
+
startCommand: streamlit run app.py --server.port=$PORT --server.address=0.0.0.0 --server.headless=true --server.enableCORS=false
|
| 9 |
plan: free
|
| 10 |
+
healthCheckPath: /?health=true
|
| 11 |
envVars:
|
| 12 |
- key: OPENAI_API_KEY
|
| 13 |
sync: false
|
requirements.txt
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
-
streamlit=
|
| 2 |
openai>=1.0.0
|
| 3 |
anthropic>=0.25.0
|
| 4 |
google-generativeai>=0.6.0
|
| 5 |
python-dotenv>=1.0.0
|
| 6 |
-
requests>=2.32.0
|
|
|
|
|
|
| 1 |
+
streamlit>=1.36.0
|
| 2 |
openai>=1.0.0
|
| 3 |
anthropic>=0.25.0
|
| 4 |
google-generativeai>=0.6.0
|
| 5 |
python-dotenv>=1.0.0
|
| 6 |
+
requests>=2.32.0
|
| 7 |
+
typing-extensions>=4.0.0
|