Update app.py
Browse files
app.py
CHANGED
|
@@ -742,7 +742,7 @@ async def get_session_status(session_id: str):
|
|
| 742 |
|
| 743 |
@app.get("/api/server-status")
|
| 744 |
async def get_server_status():
|
| 745 |
-
"""Get current server translation status"""
|
| 746 |
active_sessions = []
|
| 747 |
|
| 748 |
with translator.translation_lock:
|
|
@@ -752,8 +752,10 @@ async def get_server_status():
|
|
| 752 |
avg_time_per_chunk = elapsed_time / progress['completed_chunks']
|
| 753 |
remaining_chunks = progress['total_chunks'] - progress['completed_chunks']
|
| 754 |
estimated_remaining = avg_time_per_chunk * remaining_chunks
|
|
|
|
| 755 |
else:
|
| 756 |
estimated_remaining = None
|
|
|
|
| 757 |
|
| 758 |
active_sessions.append({
|
| 759 |
'session_id': session_id,
|
|
@@ -761,25 +763,34 @@ async def get_server_status():
|
|
| 761 |
'target_lang': progress['target_lang'],
|
| 762 |
'total_chunks': progress['total_chunks'],
|
| 763 |
'completed_chunks': progress['completed_chunks'],
|
| 764 |
-
'progress_percentage':
|
| 765 |
'elapsed_time': elapsed_time,
|
| 766 |
-
'estimated_remaining': estimated_remaining
|
|
|
|
|
|
|
| 767 |
})
|
| 768 |
|
| 769 |
if active_sessions:
|
| 770 |
-
# Return the most recent active session
|
| 771 |
latest_session = active_sessions[-1]
|
| 772 |
return {
|
| 773 |
"has_active_translation": True,
|
| 774 |
"status": "processing",
|
| 775 |
-
"message":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 776 |
"session_data": latest_session
|
| 777 |
}
|
| 778 |
else:
|
| 779 |
return {
|
| 780 |
"has_active_translation": False,
|
| 781 |
-
"status": "
|
| 782 |
-
"message": "
|
| 783 |
}
|
| 784 |
|
| 785 |
if __name__ == "__main__":
|
|
|
|
| 742 |
|
| 743 |
@app.get("/api/server-status")
|
| 744 |
async def get_server_status():
|
| 745 |
+
"""Get current server translation status with detailed progress info"""
|
| 746 |
active_sessions = []
|
| 747 |
|
| 748 |
with translator.translation_lock:
|
|
|
|
| 752 |
avg_time_per_chunk = elapsed_time / progress['completed_chunks']
|
| 753 |
remaining_chunks = progress['total_chunks'] - progress['completed_chunks']
|
| 754 |
estimated_remaining = avg_time_per_chunk * remaining_chunks
|
| 755 |
+
progress_percentage = (progress['completed_chunks'] / progress['total_chunks']) * 100
|
| 756 |
else:
|
| 757 |
estimated_remaining = None
|
| 758 |
+
progress_percentage = 0
|
| 759 |
|
| 760 |
active_sessions.append({
|
| 761 |
'session_id': session_id,
|
|
|
|
| 763 |
'target_lang': progress['target_lang'],
|
| 764 |
'total_chunks': progress['total_chunks'],
|
| 765 |
'completed_chunks': progress['completed_chunks'],
|
| 766 |
+
'progress_percentage': progress_percentage,
|
| 767 |
'elapsed_time': elapsed_time,
|
| 768 |
+
'estimated_remaining': estimated_remaining,
|
| 769 |
+
'current_status': f"Processing chunk {progress['completed_chunks'] + 1}/{progress['total_chunks']}",
|
| 770 |
+
'detailed_status': f"[TRANSLATE] Starting chunk translation [{progress['completed_chunks'] + 1}/{progress['total_chunks']}] | {progress['source_lang']} → {progress['target_lang']}"
|
| 771 |
})
|
| 772 |
|
| 773 |
if active_sessions:
|
| 774 |
+
# Return the most recent active session with detailed info
|
| 775 |
latest_session = active_sessions[-1]
|
| 776 |
return {
|
| 777 |
"has_active_translation": True,
|
| 778 |
"status": "processing",
|
| 779 |
+
"message": latest_session['detailed_status'],
|
| 780 |
+
"progress_info": {
|
| 781 |
+
"current_chunk": latest_session['completed_chunks'] + 1,
|
| 782 |
+
"total_chunks": latest_session['total_chunks'],
|
| 783 |
+
"progress_percentage": latest_session['progress_percentage'],
|
| 784 |
+
"elapsed_time": latest_session['elapsed_time'],
|
| 785 |
+
"estimated_remaining": latest_session['estimated_remaining']
|
| 786 |
+
},
|
| 787 |
"session_data": latest_session
|
| 788 |
}
|
| 789 |
else:
|
| 790 |
return {
|
| 791 |
"has_active_translation": False,
|
| 792 |
+
"status": "idle",
|
| 793 |
+
"message": "Server is ready for new translations"
|
| 794 |
}
|
| 795 |
|
| 796 |
if __name__ == "__main__":
|