Spaces:
Running
Running
fix code
Browse files- backend/main.py +8 -1
- frontend/dist/js/app.js +2 -4
- frontend/src/App.js +4 -0
backend/main.py
CHANGED
@@ -82,7 +82,14 @@ async def upload_file(file: UploadFile = File(...)):
|
|
82 |
# Cleanup
|
83 |
os.unlink(file_path)
|
84 |
|
85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
|
87 |
except Exception as e:
|
88 |
raise HTTPException(status_code=500, detail=str(e))
|
|
|
82 |
# Cleanup
|
83 |
os.unlink(file_path)
|
84 |
|
85 |
+
# Change the response to include a header that prevents the popup
|
86 |
+
return JSONResponse(
|
87 |
+
content={"session_id": session_id, "message": "File processed successfully"},
|
88 |
+
headers={
|
89 |
+
"Content-Type": "application/json",
|
90 |
+
"X-Content-Type-Options": "nosniff"
|
91 |
+
}
|
92 |
+
)
|
93 |
|
94 |
except Exception as e:
|
95 |
raise HTTPException(status_code=500, detail=str(e))
|
frontend/dist/js/app.js
CHANGED
@@ -20,7 +20,6 @@ async function uploadFile() {
|
|
20 |
const uploadSpinner = document.getElementById('uploadSpinner');
|
21 |
|
22 |
if (!fileInput.files.length) {
|
23 |
-
alert('Please select a file first');
|
24 |
return;
|
25 |
}
|
26 |
|
@@ -40,7 +39,7 @@ async function uploadFile() {
|
|
40 |
sessionId = data.session_id;
|
41 |
|
42 |
} catch (error) {
|
43 |
-
|
44 |
} finally {
|
45 |
setLoading(false, 'upload');
|
46 |
}
|
@@ -50,7 +49,6 @@ async function submitQuery() {
|
|
50 |
const queryInput = document.getElementById('queryInput');
|
51 |
|
52 |
if (!queryInput.value.trim()) {
|
53 |
-
alert('Please enter a question');
|
54 |
return;
|
55 |
}
|
56 |
|
@@ -91,7 +89,7 @@ async function submitQuery() {
|
|
91 |
}
|
92 |
|
93 |
} catch (error) {
|
94 |
-
|
95 |
} finally {
|
96 |
setLoading(false, 'query');
|
97 |
}
|
|
|
20 |
const uploadSpinner = document.getElementById('uploadSpinner');
|
21 |
|
22 |
if (!fileInput.files.length) {
|
|
|
23 |
return;
|
24 |
}
|
25 |
|
|
|
39 |
sessionId = data.session_id;
|
40 |
|
41 |
} catch (error) {
|
42 |
+
console.error('Error uploading file:', error);
|
43 |
} finally {
|
44 |
setLoading(false, 'upload');
|
45 |
}
|
|
|
49 |
const queryInput = document.getElementById('queryInput');
|
50 |
|
51 |
if (!queryInput.value.trim()) {
|
|
|
52 |
return;
|
53 |
}
|
54 |
|
|
|
89 |
}
|
90 |
|
91 |
} catch (error) {
|
92 |
+
console.error('Error submitting query:', error);
|
93 |
} finally {
|
94 |
setLoading(false, 'query');
|
95 |
}
|
frontend/src/App.js
CHANGED
@@ -17,6 +17,7 @@ function App() {
|
|
17 |
const [isProcessing, setIsProcessing] = useState(false);
|
18 |
|
19 |
const handleFileUpload = async (event) => {
|
|
|
20 |
const formData = new FormData();
|
21 |
formData.append('file', event.target.files[0]);
|
22 |
setError('');
|
@@ -26,6 +27,9 @@ function App() {
|
|
26 |
const response = await fetch('http://localhost:8000/upload', {
|
27 |
method: 'POST',
|
28 |
body: formData,
|
|
|
|
|
|
|
29 |
});
|
30 |
const data = await response.json();
|
31 |
if (data.session_id) {
|
|
|
17 |
const [isProcessing, setIsProcessing] = useState(false);
|
18 |
|
19 |
const handleFileUpload = async (event) => {
|
20 |
+
event.preventDefault();
|
21 |
const formData = new FormData();
|
22 |
formData.append('file', event.target.files[0]);
|
23 |
setError('');
|
|
|
27 |
const response = await fetch('http://localhost:8000/upload', {
|
28 |
method: 'POST',
|
29 |
body: formData,
|
30 |
+
headers: {
|
31 |
+
'Accept': 'application/json'
|
32 |
+
}
|
33 |
});
|
34 |
const data = await response.json();
|
35 |
if (data.session_id) {
|