manikandan18ramalingam commited on
Commit
b527386
·
verified ·
1 Parent(s): ee78bc5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -42,17 +42,18 @@ def check_file_size(file):
42
 
43
 
44
  def save_uploaded_file_to_temp(uploaded_file) -> str:
45
- """
46
- Saves uploaded file to a temp folder and returns the absolute path.
47
- This avoids filename collisions and issues with Streamlit reruns.
48
- """
49
- tmp_dir = Path(tempfile.gettempdir())
50
  safe_name = uploaded_file.name.replace("/", "_").replace("\\", "_")
51
  save_path = tmp_dir / safe_name
52
- print("save path is", "/app"+save_path)
53
  with open(save_path, "wb") as f:
54
  f.write(uploaded_file.getbuffer())
55
- return str("/app"+save_path)
 
 
56
 
57
 
58
  def list_demo_files(task_name: str, limit: int = 6):
 
42
 
43
 
44
  def save_uploaded_file_to_temp(uploaded_file) -> str:
45
+ # Explicit temp directory (works reliably on HF Spaces)
46
+ tmp_dir = Path("/tmp")
47
+ tmp_dir.mkdir(parents=True, exist_ok=True)
48
+
 
49
  safe_name = uploaded_file.name.replace("/", "_").replace("\\", "_")
50
  save_path = tmp_dir / safe_name
51
+
52
  with open(save_path, "wb") as f:
53
  f.write(uploaded_file.getbuffer())
54
+
55
+ print("Saved uploaded file to:", save_path)
56
+ return str(save_path)
57
 
58
 
59
  def list_demo_files(task_name: str, limit: int = 6):