linoyts HF Staff commited on
Commit
9552bee
Β·
verified Β·
1 Parent(s): 9760de5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -22
app.py CHANGED
@@ -65,28 +65,11 @@ def cleanup_session_files(request: gr.Request):
65
  # Get the session ID from the request
66
  session_id = request.session_hash
67
 
68
- # Check common gradio temp locations
69
- gradio_temp_dirs = [
70
- "/tmp/gradio",
71
- os.path.join(tempfile.gettempdir(), "gradio"),
72
- os.path.join(os.getcwd(), "gradio")
73
- ]
74
-
75
- files_cleaned = 0
76
-
77
- # Clean session directories in gradio temp folders
78
- for temp_dir in gradio_temp_dirs:
79
- session_dir = os.path.join(temp_dir, session_id)
80
- if os.path.exists(session_dir):
81
- try:
82
- shutil.rmtree(session_dir)
83
- files_cleaned += 1
84
- print(f"Cleaned up session directory: {session_dir}")
85
- except (OSError, FileNotFoundError):
86
- pass
87
-
88
- if files_cleaned > 0:
89
- print(f"Session cleanup completed: {files_cleaned} directories removed for session {session_id}")
90
 
91
  except Exception as e:
92
  print(f"Error during session cleanup: {e}")
 
65
  # Get the session ID from the request
66
  session_id = request.session_hash
67
 
68
+ # Clean up the session directory
69
+ session_dir = os.path.join("/tmp/gradio", session_id)
70
+ if os.path.exists(session_dir):
71
+ shutil.rmtree(session_dir)
72
+ print(f"Cleaned up session directory: {session_dir}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
 
74
  except Exception as e:
75
  print(f"Error during session cleanup: {e}")