import React, { useState } from 'react'; const BACK_END_URL = 'http://localhost:5000' const ImageProcessor = (): JSX.Element => { const [file, setFile] = useState(null); const [downloadUrl, setDownloadUrl] = useState(''); const handleFileChange = (event: React.ChangeEvent): void => { if (event.target.files) { setFile(event.target.files[0]); } }; const processImage = async (operation: 'edge_detection' | 'color_inversion'): Promise => { if (!file) { alert('Please select a file first!'); return; } const formData = new FormData(); formData.append('image', file); formData.append('operation', operation); try { const response = await fetch(`${BACK_END_URL}/upload`, { method: 'POST', body: formData, }); const data = await response.json(); if (response.ok) { setDownloadUrl(`${data.processed_file}`); console.log(data.processed_file) alert('File processed successfully!'); } else { alert(data.error || 'Failed to process the file'); } } catch (error) { alert('Error connecting to the server'); } }; const downloadImage = (): void => { if (!downloadUrl) { alert('No processed image available for download!'); return; } window.open(downloadUrl); }; return (

Image Processing

); }; export default ImageProcessor;