Spaces:
Runtime error
Runtime error
lionelgarnier
commited on
Commit
·
73911dd
1
Parent(s):
593768d
enhance session management with error handling for session start and end
Browse files
app.py
CHANGED
@@ -54,13 +54,24 @@ _trellis_pipeline = None
|
|
54 |
|
55 |
|
56 |
def start_session(req: gr.Request):
|
57 |
-
|
58 |
-
|
|
|
|
|
|
|
|
|
|
|
59 |
|
60 |
|
61 |
def end_session(req: gr.Request):
|
62 |
-
|
63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
|
65 |
|
66 |
@spaces.GPU()
|
@@ -585,8 +596,7 @@ def create_interface():
|
|
585 |
outputs=[download_gs]
|
586 |
)
|
587 |
|
588 |
-
return demo
|
589 |
-
|
590 |
|
591 |
if __name__ == "__main__":
|
592 |
# Initialize models if PRELOAD_MODELS is True
|
|
|
54 |
|
55 |
|
56 |
def start_session(req: gr.Request):
|
57 |
+
"""Create a temporary directory for the user session"""
|
58 |
+
try:
|
59 |
+
user_dir = os.path.join(TMP_DIR, str(req.session_hash))
|
60 |
+
os.makedirs(user_dir, exist_ok=True)
|
61 |
+
print(f"Session started: {req.session_hash}")
|
62 |
+
except Exception as e:
|
63 |
+
print(f"Error starting session: {str(e)}")
|
64 |
|
65 |
|
66 |
def end_session(req: gr.Request):
|
67 |
+
"""Clean up the temporary directory when the session ends"""
|
68 |
+
try:
|
69 |
+
user_dir = os.path.join(TMP_DIR, str(req.session_hash))
|
70 |
+
if os.path.exists(user_dir):
|
71 |
+
shutil.rmtree(user_dir)
|
72 |
+
print(f"Session ended: {req.session_hash}")
|
73 |
+
except Exception as e:
|
74 |
+
print(f"Error ending session: {str(e)}")
|
75 |
|
76 |
|
77 |
@spaces.GPU()
|
|
|
596 |
outputs=[download_gs]
|
597 |
)
|
598 |
|
599 |
+
return demo
|
|
|
600 |
|
601 |
if __name__ == "__main__":
|
602 |
# Initialize models if PRELOAD_MODELS is True
|