| import React, { useState } from 'react'; | |
| import axios from 'axios'; | |
| function App() { | |
| const [file, setFile] = useState(null); | |
| const [result, setResult] = useState(null); | |
| const handleFileChange = (e) => { | |
| setFile(e.target.files[0]); | |
| }; | |
| const handleSubmit = async () => { | |
| const formData = new FormData(); | |
| formData.append('file', file); | |
| try { | |
| const response = await axios.post('http://localhost:8000/predict/', formData); | |
| setResult(response.data); | |
| } catch (error) { | |
| console.error(error); | |
| } | |
| }; | |
| return ( | |
| <div> | |
| <h1>Vision Transformer Image Classifier</h1> | |
| <input type="file" onChange={handleFileChange} /> | |
| <button onClick={handleSubmit}>Upload and Predict</button> | |
| {result && ( | |
| <div> | |
| <h2>Result:</h2> | |
| <p>Class: {result.predicted_class}</p> | |
| <p>Confidence: {result.confidence}</p> | |
| </div> | |
| )} | |
| </div> | |
| ); | |
| } | |
| export default App; | |