Spaces:
Runtime error
Runtime error
Update upload image
Browse files- frontend/src/App.js +23 -8
frontend/src/App.js
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
|
|
| 1 |
import React, { useState } from 'react';
|
| 2 |
import axios from 'axios';
|
| 3 |
|
| 4 |
const App = () => {
|
| 5 |
-
// const [image, setImage] = useState(
|
| 6 |
const [generatedCaption, setGeneratedCaption] = useState('');
|
| 7 |
const [audioUrl, setAudioUrl] = useState('');
|
| 8 |
|
| 9 |
-
const handleImageUpload =
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
const file = event.target.files[0];
|
| 11 |
const formData = new FormData();
|
| 12 |
formData.append('image', file);
|
|
@@ -21,13 +26,23 @@ const App = () => {
|
|
| 21 |
};
|
| 22 |
|
| 23 |
return (
|
| 24 |
-
|
| 25 |
-
<div className="
|
| 26 |
-
<
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
</div>
|
| 30 |
-
|
| 31 |
);
|
| 32 |
};
|
| 33 |
|
|
|
|
| 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);
|
|
|
|
| 26 |
};
|
| 27 |
|
| 28 |
return (
|
| 29 |
+
<>
|
| 30 |
+
<div className="App">
|
| 31 |
+
<p className="title">Image Captioning</p>
|
| 32 |
+
<div className="file-card">
|
| 33 |
+
<div className="file-inputs">
|
| 34 |
+
<label htmlFor="fileInput">
|
| 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 |
};
|
| 48 |
|