Spaces:
Runtime error
Runtime error
Create react.js
Browse files
react.js
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// src/App.js
|
2 |
+
import React, { useState } from 'react';
|
3 |
+
import axios from 'axios';
|
4 |
+
|
5 |
+
function App() {
|
6 |
+
const [generatedCaption, setGeneratedCaption] = useState('');
|
7 |
+
const [audioPath, setAudioPath] = useState('');
|
8 |
+
|
9 |
+
const handleImageUpload = async (event) => {
|
10 |
+
const formData = new FormData();
|
11 |
+
formData.append('image', event.target.files[0]);
|
12 |
+
|
13 |
+
try {
|
14 |
+
const response = await axios.post('http://localhost:5000/generate_caption', formData);
|
15 |
+
setGeneratedCaption(response.data.generated_caption);
|
16 |
+
setAudioPath(response.data.audio_path);
|
17 |
+
} catch (error) {
|
18 |
+
console.error('Error uploading image:', error);
|
19 |
+
}
|
20 |
+
};
|
21 |
+
|
22 |
+
return (
|
23 |
+
<div>
|
24 |
+
<input type="file" onChange={handleImageUpload} />
|
25 |
+
<p>Generated Caption: {generatedCaption}</p>
|
26 |
+
<audio controls src={`http://localhost:5000/${audioPath}`} />
|
27 |
+
</div>
|
28 |
+
);
|
29 |
+
}
|
30 |
+
|
31 |
+
export default App;
|