Spaces:
Runtime error
Runtime error
File size: 1,329 Bytes
2e2e8c1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
import React, { useState } from "react";
import axios from "axios";
function App() {
const [image, setImage] = useState(null);
const [caption, setCaption] = useState(null);
const handleImageChange = (event) => {
const file = event.target.files[0];
const reader = new FileReader();
reader.onload = () => {
setImage(reader.result);
};
reader.readAsDataURL(file);
};
const handleSubmit = () => {
const formData = new FormData();
formData.append("image", image);
axios.post("/caption", formData)
.then((response) => response.data)
.then((data) => {
setCaption(data.caption);
});
};
return (
<div>
<h1>Image Captioning with BLIP</h1>
<p>ระบบนี้ใช้ BLIP เพื่อสร้างคำอธิบายภาพ</p>
<form onSubmit={handleSubmit}>
<input type="file" name="image" id="image" onChange={handleImageChange} />
<label for="image">เลือกภาพ</label>
<input type="submit" value="สร้างคำอธิบาย" />
</form>
{caption && <p>{caption}</p>}
</div>
);
};
export default App;
|