| 6 | const API_URL = `https://vision.googleapis.com/v1/images:annotate?key=${API_KEY}`; |
| 7 | |
| 8 | async function callGoogleVisionAsync(image) { |
| 9 | const body = { |
| 10 | requests: [ |
| 11 | { |
| 12 | image: { |
| 13 | content: image, |
| 14 | }, |
| 15 | features: [ |
| 16 | { |
| 17 | type: "LABEL_DETECTION", |
| 18 | maxResults: 1, |
| 19 | }, |
| 20 | ], |
| 21 | }, |
| 22 | ], |
| 23 | }; |
| 24 | |
| 25 | const response = await fetch(API_URL, { |
| 26 | method: "POST", |
| 27 | headers: { |
| 28 | Accept: "application/json", |
| 29 | "Content-Type": "application/json", |
| 30 | }, |
| 31 | body: JSON.stringify(body), |
| 32 | }); |
| 33 | const parsed = await response.json(); |
| 34 | |
| 35 | console.log("Result:", parsed); |
| 36 | |
| 37 | if (parsed.error) { |
| 38 | console.log("Google Vision API Error:", parsed.error); |
| 39 | throw new Error(parsed.error.message); |
| 40 | } |
| 41 | |
| 42 | return parsed.responses[0].labelAnnotations[0].description; |
| 43 | } |
| 44 | |
| 45 | function VisionScreen() { |
| 46 | const [image, setImage] = useState(null); |