Natthathida commited on
Commit
b267797
·
verified ·
1 Parent(s): 73cb49c
Files changed (1) hide show
  1. frontend/src/App.js +8 -8
frontend/src/App.js CHANGED
@@ -1,23 +1,24 @@
1
  import './App.css';
2
  import React, { useState } from 'react';
3
  import axios from 'axios';
 
4
 
5
  const App = () => {
6
- // const [image, setImage] = useState();
7
  const [generatedCaption, setGeneratedCaption] = useState('');
8
  const [audioUrl, setAudioUrl] = useState('');
9
 
10
- // const handleImageUpload = (e) => {
11
- // setImage(e.target.files[0]);
12
- // }
13
-
14
  const handleImageGenerate = async (event) => {
15
  const file = event.target.files[0];
16
  const formData = new FormData();
17
  formData.append('image', file);
18
 
19
  try {
20
- const response = await axios.post('http://5000/upload', formData);
 
 
 
 
 
21
  setGeneratedCaption(response.data.generated_caption);
22
  setAudioUrl(response.data.audio_url);
23
  } catch (error) {
@@ -35,13 +36,12 @@ const App = () => {
35
  <input type="file" id="fileInput" onChange={handleImageGenerate} accept="image/jpeg, image/png" />
36
  <span>Upload</span>
37
  </label>
38
- {/* <input type="file" placeholder="๊Upload" onChange={handleImageGenerate} accept="image/jpeg, image/png" /> */}
39
- {/* <button onClick={handleImageGenerate}>Upload</button> */}
40
  {generatedCaption && <p>Generated Caption: {generatedCaption}</p>}
41
  {audioUrl && <audio controls src={audioUrl} />}
42
  </div>
43
  </div>
44
  </div>
 
45
  </>
46
  );
47
  };
 
1
  import './App.css';
2
  import React, { useState } from 'react';
3
  import axios from 'axios';
4
+ import FileList from './FileList/FileList';
5
 
6
  const App = () => {
 
7
  const [generatedCaption, setGeneratedCaption] = useState('');
8
  const [audioUrl, setAudioUrl] = useState('');
9
 
 
 
 
 
10
  const handleImageGenerate = async (event) => {
11
  const file = event.target.files[0];
12
  const formData = new FormData();
13
  formData.append('image', file);
14
 
15
  try {
16
+ const response = await axios.post('http://5000/upload', formData, {
17
+ headers: {
18
+ 'Content-Type': 'multipart/form-data',
19
+ },
20
+ });
21
+
22
  setGeneratedCaption(response.data.generated_caption);
23
  setAudioUrl(response.data.audio_url);
24
  } catch (error) {
 
36
  <input type="file" id="fileInput" onChange={handleImageGenerate} accept="image/jpeg, image/png" />
37
  <span>Upload</span>
38
  </label>
 
 
39
  {generatedCaption && <p>Generated Caption: {generatedCaption}</p>}
40
  {audioUrl && <audio controls src={audioUrl} />}
41
  </div>
42
  </div>
43
  </div>
44
+ // <FileList />
45
  </>
46
  );
47
  };