Faran Butt
commited on
Commit
·
2018cf4
1
Parent(s):
43affd4
Fixed this fucking Bug
Browse files- src/pages/index.tsx +29 -12
src/pages/index.tsx
CHANGED
@@ -6,30 +6,47 @@ import { Button } from "@/components/ui/button";
|
|
6 |
import { Input } from "@/components/ui/input";
|
7 |
import { client } from "@gradio/client";
|
8 |
import axios from "axios";
|
|
|
9 |
export default function Home() {
|
|
|
10 |
const [file,setFile] = useState(null);
|
11 |
const [result,setResult] = useState('');
|
12 |
const [query,setQuery] = useState('');
|
13 |
const [collection,setCollection] = useState('');
|
14 |
-
|
15 |
const handleFileChange = (event:any) => {
|
16 |
-
console.log(event.target.files[0])
|
17 |
-
setFile(event.target.files[0]
|
|
|
|
|
|
|
|
|
|
|
18 |
}
|
19 |
const SendFile = async() => {
|
20 |
console.log("File Recieved: ",file)
|
21 |
console.log("Query Recieved: ",query)
|
22 |
console.log("Collection Recieved: ",collection)
|
|
|
|
|
|
|
|
|
23 |
try{
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
29 |
headers: {
|
30 |
-
'Content-Type': '
|
31 |
-
}
|
32 |
-
})
|
|
|
33 |
console.log(response)
|
34 |
}catch(error){
|
35 |
console.error('Error:', error);
|
@@ -65,7 +82,7 @@ export default function Home() {
|
|
65 |
</div>
|
66 |
<div>
|
67 |
<label htmlFor="" className="font-bold text-3xl">Enter Document</label>
|
68 |
-
<Input type='file' onChange={handleFileChange}/>
|
69 |
<p className="mt-1 text-sm text-gray-500 dark:text-gray-300" id="file_input_help">TXT, DOCX, PPTX, JPG, PNG, HTML or PDF</p>
|
70 |
</div>
|
71 |
<div>
|
|
|
6 |
import { Input } from "@/components/ui/input";
|
7 |
import { client } from "@gradio/client";
|
8 |
import axios from "axios";
|
9 |
+
import React from "react";
|
10 |
export default function Home() {
|
11 |
+
const inputFileRef = React.createRef();
|
12 |
const [file,setFile] = useState(null);
|
13 |
const [result,setResult] = useState('');
|
14 |
const [query,setQuery] = useState('');
|
15 |
const [collection,setCollection] = useState('');
|
16 |
+
const formData = new FormData();
|
17 |
const handleFileChange = (event:any) => {
|
18 |
+
// console.log(event.target.files[0])
|
19 |
+
setFile(event.target.files[0]);
|
20 |
+
// const inputFile:any = inputFileRef.current;
|
21 |
+
// const exampleFile = inputFile.files[0];
|
22 |
+
// formData.append("pdfFile", exampleFile);
|
23 |
+
// console.log(formData)
|
24 |
+
|
25 |
}
|
26 |
const SendFile = async() => {
|
27 |
console.log("File Recieved: ",file)
|
28 |
console.log("Query Recieved: ",query)
|
29 |
console.log("Collection Recieved: ",collection)
|
30 |
+
formData.append('query', query);
|
31 |
+
formData.append('pdf_file', file);
|
32 |
+
formData.append('collection_name', collection);
|
33 |
+
console.log("FORM",formData)
|
34 |
try{
|
35 |
+
// const url = 'https://teamtonic-herechatbackend.hf.space/--replicas/djdp8/';
|
36 |
+
// const data = {
|
37 |
+
// data: [query, formData, collection]
|
38 |
+
// };
|
39 |
+
// const response = await axios.post(url, data.data, {
|
40 |
+
// headers: {
|
41 |
+
// 'Content-Type': 'application/json'
|
42 |
+
// }
|
43 |
+
// })
|
44 |
+
const response = await axios.post('https://teamtonic-herechatbackend.hf.space/--replicas/djdp8/combined_interface', formData, {
|
45 |
headers: {
|
46 |
+
'Content-Type': 'multipart/form-data',
|
47 |
+
},
|
48 |
+
});
|
49 |
+
const responseData = response.data;
|
50 |
console.log(response)
|
51 |
}catch(error){
|
52 |
console.error('Error:', error);
|
|
|
82 |
</div>
|
83 |
<div>
|
84 |
<label htmlFor="" className="font-bold text-3xl">Enter Document</label>
|
85 |
+
<Input type='file' ref={inputFileRef} onChange={handleFileChange}/>
|
86 |
<p className="mt-1 text-sm text-gray-500 dark:text-gray-300" id="file_input_help">TXT, DOCX, PPTX, JPG, PNG, HTML or PDF</p>
|
87 |
</div>
|
88 |
<div>
|