Update app.py
Browse files
app.py
CHANGED
|
@@ -793,5 +793,47 @@ async def get_server_status():
|
|
| 793 |
"message": "Server is ready for new translations"
|
| 794 |
}
|
| 795 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 796 |
if __name__ == "__main__":
|
| 797 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
| 793 |
"message": "Server is ready for new translations"
|
| 794 |
}
|
| 795 |
|
| 796 |
+
@app.get("/api/detailed-status")
|
| 797 |
+
async def get_detailed_server_status():
|
| 798 |
+
"""Get detailed server status with live progress tracking"""
|
| 799 |
+
with translator.translation_lock:
|
| 800 |
+
if not translator.current_translation:
|
| 801 |
+
return {
|
| 802 |
+
"has_active": False,
|
| 803 |
+
"message": "No active translations",
|
| 804 |
+
"server_status": "idle"
|
| 805 |
+
}
|
| 806 |
+
|
| 807 |
+
# Get all active translations with detailed info
|
| 808 |
+
active_translations = []
|
| 809 |
+
for session_id, progress in translator.current_translation.items():
|
| 810 |
+
elapsed_time = time.time() - progress['start_time']
|
| 811 |
+
current_chunk = progress['completed_chunks'] + 1
|
| 812 |
+
|
| 813 |
+
if progress['completed_chunks'] > 0:
|
| 814 |
+
avg_time_per_chunk = elapsed_time / progress['completed_chunks']
|
| 815 |
+
remaining_chunks = progress['total_chunks'] - progress['completed_chunks']
|
| 816 |
+
estimated_remaining = avg_time_per_chunk * remaining_chunks
|
| 817 |
+
else:
|
| 818 |
+
estimated_remaining = None
|
| 819 |
+
|
| 820 |
+
active_translations.append({
|
| 821 |
+
"session_id": session_id,
|
| 822 |
+
"current_chunk": current_chunk,
|
| 823 |
+
"total_chunks": progress['total_chunks'],
|
| 824 |
+
"progress_percentage": (progress['completed_chunks'] / progress['total_chunks']) * 100,
|
| 825 |
+
"elapsed_time": elapsed_time,
|
| 826 |
+
"estimated_remaining": estimated_remaining,
|
| 827 |
+
"status_message": f"Processing chunk {current_chunk}/{progress['total_chunks']} | {progress['source_lang']} → {progress['target_lang']}",
|
| 828 |
+
"detailed_log": f"[SESSION:{session_id}] Starting chunk {current_chunk}/{progress['total_chunks']} | {progress['source_lang']} → {progress['target_lang']}"
|
| 829 |
+
})
|
| 830 |
+
|
| 831 |
+
return {
|
| 832 |
+
"has_active": True,
|
| 833 |
+
"active_count": len(active_translations),
|
| 834 |
+
"translations": active_translations,
|
| 835 |
+
"server_status": "processing"
|
| 836 |
+
}
|
| 837 |
+
|
| 838 |
if __name__ == "__main__":
|
| 839 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|