Spaces:
Runtime error
Runtime error
Pranit commited on
Commit ·
3100614
1
Parent(s): 9ff1e2e
- Dockerfile +1 -1
- app.py +34 -1
Dockerfile
CHANGED
|
@@ -33,4 +33,4 @@ ENV FLASK_APP=app.py
|
|
| 33 |
ENV FLASK_ENV=production
|
| 34 |
|
| 35 |
# Run gunicorn
|
| 36 |
-
CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--timeout", "
|
|
|
|
| 33 |
ENV FLASK_ENV=production
|
| 34 |
|
| 35 |
# Run gunicorn
|
| 36 |
+
CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--timeout", "600", "app:app"]
|
app.py
CHANGED
|
@@ -9,6 +9,7 @@ import tempfile
|
|
| 9 |
from io import BytesIO
|
| 10 |
import jinja2
|
| 11 |
from dotenv import load_dotenv
|
|
|
|
| 12 |
|
| 13 |
app = Flask(__name__)
|
| 14 |
|
|
@@ -281,6 +282,21 @@ def extract_maintenance_status(report_text):
|
|
| 281 |
logger.error(f"Error extracting maintenance status: {str(e)}")
|
| 282 |
return [60, 30, 10] # Default values if extraction fails
|
| 283 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 284 |
@app.route('/generate_report', methods=['POST'])
|
| 285 |
def generate_report():
|
| 286 |
try:
|
|
@@ -334,7 +350,10 @@ def generate_report():
|
|
| 334 |
contextualized_prompt = contextualized_prompt.replace('${gate_count}', str(basic_info.get('gateCount', '')))
|
| 335 |
|
| 336 |
# Generate report with image references
|
| 337 |
-
response =
|
|
|
|
|
|
|
|
|
|
| 338 |
report_text = response.text
|
| 339 |
|
| 340 |
# Extract all metrics
|
|
@@ -467,5 +486,19 @@ def health_check():
|
|
| 467 |
'error': str(e)
|
| 468 |
}), 500
|
| 469 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 470 |
if __name__ == '__main__':
|
| 471 |
app.run(host='0.0.0.0', port=7860)
|
|
|
|
| 9 |
from io import BytesIO
|
| 10 |
import jinja2
|
| 11 |
from dotenv import load_dotenv
|
| 12 |
+
from tenacity import retry, stop_after_attempt, wait_exponential
|
| 13 |
|
| 14 |
app = Flask(__name__)
|
| 15 |
|
|
|
|
| 282 |
logger.error(f"Error extracting maintenance status: {str(e)}")
|
| 283 |
return [60, 30, 10] # Default values if extraction fails
|
| 284 |
|
| 285 |
+
@retry(stop=stop_after_attempt(3), wait=wait_exponential(multiplier=1, min=4, max=10))
|
| 286 |
+
def generate_content_with_retry(prompt, images):
|
| 287 |
+
"""Generate content with retry logic"""
|
| 288 |
+
try:
|
| 289 |
+
response = model.generate_content(
|
| 290 |
+
[prompt] + images,
|
| 291 |
+
generation_config=genai.types.GenerationConfig(
|
| 292 |
+
timeout=300
|
| 293 |
+
)
|
| 294 |
+
)
|
| 295 |
+
return response
|
| 296 |
+
except Exception as e:
|
| 297 |
+
logger.error(f"Error generating content: {str(e)}")
|
| 298 |
+
raise
|
| 299 |
+
|
| 300 |
@app.route('/generate_report', methods=['POST'])
|
| 301 |
def generate_report():
|
| 302 |
try:
|
|
|
|
| 350 |
contextualized_prompt = contextualized_prompt.replace('${gate_count}', str(basic_info.get('gateCount', '')))
|
| 351 |
|
| 352 |
# Generate report with image references
|
| 353 |
+
response = generate_content_with_retry(
|
| 354 |
+
contextualized_prompt,
|
| 355 |
+
all_images
|
| 356 |
+
)
|
| 357 |
report_text = response.text
|
| 358 |
|
| 359 |
# Extract all metrics
|
|
|
|
| 486 |
'error': str(e)
|
| 487 |
}), 500
|
| 488 |
|
| 489 |
+
@app.route('/report_status/<task_id>')
|
| 490 |
+
def report_status(task_id):
|
| 491 |
+
"""Check the status of a report generation task"""
|
| 492 |
+
try:
|
| 493 |
+
# Implement status checking logic
|
| 494 |
+
return jsonify({
|
| 495 |
+
'status': 'processing',
|
| 496 |
+
'progress': 50, # Example progress percentage
|
| 497 |
+
'message': 'Processing images...'
|
| 498 |
+
})
|
| 499 |
+
except Exception as e:
|
| 500 |
+
logger.error(f"Error checking status: {str(e)}")
|
| 501 |
+
return jsonify({'error': str(e)}), 500
|
| 502 |
+
|
| 503 |
if __name__ == '__main__':
|
| 504 |
app.run(host='0.0.0.0', port=7860)
|