Natthathida commited on
Commit
3fefa68
·
verified ·
1 Parent(s): 7be5d5e

Update react fe

Browse files
Files changed (1) hide show
  1. frontend/src/App.js +29 -14
frontend/src/App.js CHANGED
@@ -1,20 +1,35 @@
1
- import logo from './logo.svg';
2
- import './App.css';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
- function App() {
5
  return (
6
- <div className="App">
7
- <p className="title">Upload File</p>
8
- <div className="file-card">
9
- <div className="file-inpues">
10
- <input type="files"/>
11
- <button>Upload</button>
12
- </div>
13
- <p className="main">Support files</p>
14
- <p className="info">PDF, JPG, PNG</p>
15
  </div>
16
- </div>
17
  );
18
- }
19
 
20
  export default App;
 
 
1
+ import React, { useState } from 'react';
2
+ import axios from 'axios';
3
+
4
+ const App = () => {
5
+ // const [image, setImage] = useState(null);
6
+ const [generatedCaption, setGeneratedCaption] = useState('');
7
+ const [audioUrl, setAudioUrl] = useState('');
8
+
9
+ const handleImageUpload = async (event) => {
10
+ const file = event.target.files[0];
11
+ const formData = new FormData();
12
+ formData.append('image', file);
13
+
14
+ try {
15
+ const response = await axios.post('http://5000/upload', formData);
16
+ setGeneratedCaption(response.data.generated_caption);
17
+ setAudioUrl(response.data.audio_url);
18
+ } catch (error) {
19
+ console.error('Error uploading image:', error);
20
+ }
21
+ };
22
 
 
23
  return (
24
+ <div className="file-card">
25
+ <div className="file-inputs">
26
+ <input type="file" onChange={handleImageUpload} accept="image/*" />
27
+ {generatedCaption && <p>Generated Caption: {generatedCaption}</p>}
28
+ {audioUrl && <audio controls src={audioUrl} />}
 
 
 
 
29
  </div>
30
+ </div>
31
  );
32
+ };
33
 
34
  export default App;
35
+