You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I upload documents using the UI upload button, the files are correctly stored in the specified path associated with the collection (e.g., test_path/Introduction - Ladakh Expedition.pdf). However, when uploading the same files using the /upload_api and /add_file_api endpoints, the files are being stored in a temporary folder (e.g., /tmp/gradio/<random_hash>/).
This discrepancy in behavior between the UI and API uploads causes inconsistency in file storage, making it difficult to manage uploaded files.
Steps to Reproduce
Upload a file through the UI upload button.
Result: File is stored in the correct path (e.g., test_path/).
Upload the same file using the /upload_api and /add_file_api endpoints.
Result: File is stored in a temp folder (e.g., /tmp/gradio/<random_hash>/).
Expected Behavior
Files uploaded via the API should be stored in the same path as those uploaded through the UI (e.g., test_path/).
Actual Behavior
Files uploaded via the API are stored in a temporary folder instead of the intended path.
@app.post("/upload_add_document")
async def upload_add_document(
langchain_mode: str = Form(...),
file: UploadFile = File(...)
):
try:
allowed_extensions = {".pdf", ".txt", ".docx"}
_, ext = os.path.splitext(file.filename)
if ext.lower() not in allowed_extensions:
raise HTTPException(status_code=400, detail="Unsupported file type. Allowed types: .pdf, .txt, .docx")
# Save the uploaded file locally
local_file_path = f"{file.filename}"
with open(local_file_path, "wb") as f:
f.write(file.file.read())
# Step 1: Upload the document
try:
with tqdm(total=100, desc=f"Uploading {file.filename}", unit='%', ncols=80) as pbar:
x, server_file_path = client.predict(local_file_path, api_name='/upload_api')
pbar.update(100)
except Exception as e:
raise HTTPException(status_code=500, detail=f"Failed to upload document: {str(e)}")
# Step 2: Add the document with OCR processing
try:
loaders = tuple([None, None, None, None, None, None]) # Adjust loaders as needed
with tqdm(total=100, desc=f"Adding {file.filename} to {langchain_mode}", unit='%', ncols=80) as pbar:
response = client.predict(
server_file_path, langchain_mode, True, 512, True, *loaders, api_name='/add_file_api'
)
pbar.update(100)
except Exception as e:
raise HTTPException(status_code=500, detail=f"Failed to add document: {str(e)}")
# Cleanup: Delete the local file after processing
if os.path.exists(local_file_path):
os.remove(local_file_path)
return {
"status": "success",
"langchain_mode": langchain_mode,
"filename": file.filename,
"server_file_path": server_file_path,
}
except Exception as e:
if os.path.exists(local_file_path):
os.remove(local_file_path)
raise HTTPException(status_code=500, detail=f"Error: {str(e)}")
Observed File Paths
UI Uploads: test_path/Introduction - Ladakh Expedition.pdf
API Uploads: /tmp/gradio/<random_hash>/Rahul_text.txt
Its urgent please help me or suggest a way to resolve this issue on priority basis. @pseudotensor
The text was updated successfully, but these errors were encountered:
Description
When I upload documents using the UI upload button, the files are correctly stored in the specified path associated with the collection (e.g., test_path/Introduction - Ladakh Expedition.pdf). However, when uploading the same files using the /upload_api and /add_file_api endpoints, the files are being stored in a temporary folder (e.g., /tmp/gradio/<random_hash>/).
This discrepancy in behavior between the UI and API uploads causes inconsistency in file storage, making it difficult to manage uploaded files.
Steps to Reproduce
Upload a file through the UI upload button.
Result: File is stored in the correct path (e.g., test_path/).
Upload the same file using the /upload_api and /add_file_api endpoints.
Result: File is stored in a temp folder (e.g., /tmp/gradio/<random_hash>/).
Expected Behavior
Files uploaded via the API should be stored in the same path as those uploaded through the UI (e.g., test_path/).
Actual Behavior
Files uploaded via the API are stored in a temporary folder instead of the intended path.
Observed File Paths
UI Uploads: test_path/Introduction - Ladakh Expedition.pdf
API Uploads: /tmp/gradio/<random_hash>/Rahul_text.txt
Its urgent please help me or suggest a way to resolve this issue on priority basis.
@pseudotensor
The text was updated successfully, but these errors were encountered: