// In production set VITE_API_BASE to your HF Space URL in the Vercel dashboard. // Locally it falls back to the uvicorn dev server. const API_BASE = import.meta.env.VITE_API_BASE || 'http://127.0.0.1:8000'; export const parseDocument = async (file) => { const formData = new FormData(); formData.append('file', file); const res = await fetch(`${API_BASE}/parse-document`, { method: 'POST', body: formData, }); if (!res.ok) throw new Error('Failed to parse document'); return res.json(); }; export const generateQuiz = async (payload) => { const res = await fetch(`${API_BASE}/generate-quiz`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload), }); if (!res.ok) throw new Error('Failed to generate quiz'); return res.json(); }; export const submitQuiz = async (quizId, answers) => { const res = await fetch(`${API_BASE}/submit-quiz`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ quiz_id: quizId, answers }), }); if (res.status === 404) throw new Error('Quiz expired'); if (!res.ok) throw new Error('Submission failed'); return res.json(); };