Spaces:
Sleeping
Sleeping
Update app.py
Browse filesfixed suggestion permission error by bypassing write protection for authorized users
app.py
CHANGED
|
@@ -63,18 +63,21 @@ with st.expander("📝 Suggest an Acronym / Report an Error"):
|
|
| 63 |
"timestamp": datetime.utcnow().isoformat()
|
| 64 |
}
|
| 65 |
|
| 66 |
-
# 2. Create a unique filename
|
| 67 |
-
# Example: suggestion_2026-01-11_uuid.json
|
| 68 |
file_name = f"suggestion_{datetime.now().strftime('%Y%m%d_%H%M%S')}_{uuid.uuid4().hex[:6]}.json"
|
| 69 |
|
| 70 |
-
#
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
json.dump(payload, f)
|
| 73 |
|
| 74 |
# 4. Upload to the "Mailbox" Dataset
|
| 75 |
api = HfApi(token=os.getenv("HF_TOKEN"))
|
| 76 |
api.upload_file(
|
| 77 |
-
path_or_fileobj=
|
| 78 |
path_in_repo=file_name,
|
| 79 |
repo_id=SUGGESTIONS_REPO,
|
| 80 |
repo_type="dataset"
|
|
@@ -83,7 +86,8 @@ with st.expander("📝 Suggest an Acronym / Report an Error"):
|
|
| 83 |
st.success("✅ Suggestion sent! I'll review it shortly.")
|
| 84 |
|
| 85 |
# Cleanup local temp file
|
| 86 |
-
os.
|
|
|
|
| 87 |
|
| 88 |
except Exception as e:
|
| 89 |
st.error(f"Error sending suggestion: {e}")
|
|
|
|
| 63 |
"timestamp": datetime.utcnow().isoformat()
|
| 64 |
}
|
| 65 |
|
| 66 |
+
# 2. Create a unique filename
|
|
|
|
| 67 |
file_name = f"suggestion_{datetime.now().strftime('%Y%m%d_%H%M%S')}_{uuid.uuid4().hex[:6]}.json"
|
| 68 |
|
| 69 |
+
# --- THE FIX: Save to /tmp folder ---
|
| 70 |
+
# We use /tmp because the container user always has write access there.
|
| 71 |
+
temp_path = os.path.join("/tmp", file_name)
|
| 72 |
+
|
| 73 |
+
# 3. Create the temporary local file
|
| 74 |
+
with open(temp_path, "w") as f:
|
| 75 |
json.dump(payload, f)
|
| 76 |
|
| 77 |
# 4. Upload to the "Mailbox" Dataset
|
| 78 |
api = HfApi(token=os.getenv("HF_TOKEN"))
|
| 79 |
api.upload_file(
|
| 80 |
+
path_or_fileobj=temp_path,
|
| 81 |
path_in_repo=file_name,
|
| 82 |
repo_id=SUGGESTIONS_REPO,
|
| 83 |
repo_type="dataset"
|
|
|
|
| 86 |
st.success("✅ Suggestion sent! I'll review it shortly.")
|
| 87 |
|
| 88 |
# Cleanup local temp file
|
| 89 |
+
if os.path.exists(temp_path):
|
| 90 |
+
os.remove(temp_path)
|
| 91 |
|
| 92 |
except Exception as e:
|
| 93 |
st.error(f"Error sending suggestion: {e}")
|