Spaces:
Sleeping
Sleeping
Download frontend/src/api/client.ts from Sid-WC121/visual-notebook: direct link, hf CLI and curl.
- Browser
- Download file 2.66 kB
-
https://huggingface.co/spaces/Sid-WC121/visual-notebook/resolve/main/frontend/src/api/client.ts
- Command line
-
hf download hf://spaces/Sid-WC121/visual-notebook/frontend/src/api/client.ts
-
curl -L -o client.ts https://huggingface.co/spaces/Sid-WC121/visual-notebook/resolve/main/frontend/src/api/client.ts
2.66 kB
| import axios from 'axios'; | |
| const api = axios.create({ | |
| baseURL: import.meta.env.VITE_API_URL || '', | |
| withCredentials: true, | |
| headers: { 'Content-Type': 'application/json' }, | |
| }); | |
| api.interceptors.response.use( | |
| (response) => response, | |
| (error) => { | |
| const message = error.response?.data?.detail || error.message || 'An error occurred'; | |
| return Promise.reject(new Error(message)); | |
| }, | |
| ); | |
| export default api; | |
| export async function uploadCSV(file: File) { | |
| const formData = new FormData(); | |
| formData.append('file', file); | |
| const res = await api.post('/api/upload/csv', formData, { | |
| headers: { 'Content-Type': 'multipart/form-data' }, | |
| }); | |
| return res.data; | |
| } | |
| export async function getSchema() { | |
| const res = await api.get('/api/schema'); | |
| return res.data; | |
| } | |
| export async function getRows(offset = 0, limit = 50) { | |
| const res = await api.get('/api/rows', { params: { offset, limit } }); | |
| return res.data; | |
| } | |
| export async function listOperations() { | |
| const res = await api.get('/api/ops'); | |
| return res.data; | |
| } | |
| export async function applyOperation(opKey: string, params: Record<string, any>) { | |
| const res = await api.post(`/api/ops/${opKey}`, { params }); | |
| return res.data; | |
| } | |
| export async function undo() { | |
| const res = await api.post('/api/history/undo'); | |
| return res.data; | |
| } | |
| export async function redo() { | |
| const res = await api.post('/api/history/redo'); | |
| return res.data; | |
| } | |
| export async function getHistory() { | |
| const res = await api.get('/api/history'); | |
| return res.data; | |
| } | |
| export async function createChart(req: { chart_type: string; params: Record<string, any> }) { | |
| const res = await api.post('/api/viz/chart', req); | |
| return res.data; | |
| } | |
| export async function exportCSV() { | |
| const res = await api.get('/api/export/csv', { responseType: 'blob' }); | |
| return res.data; | |
| } | |
| export async function editCell(rowIndex: number, column: string, newValue: string) { | |
| const res = await api.put('/api/edit/cell', null, { params: { row_index: rowIndex, column, new_value: newValue } }); | |
| return res.data; | |
| } | |
| export async function exportNotebook() { | |
| const res = await api.post('/api/export/notebook'); | |
| return res.data; | |
| } | |
| export async function createCheckpoint() { | |
| const res = await api.post('/api/checkpoint'); | |
| return res.data; | |
| } | |
| export async function checkHealth() { | |
| const res = await api.get('/health'); | |
| return res.data; | |
| } | |
| export async function getDemo() { | |
| const res = await api.get('/api/demo'); | |
| return res.data as { available: boolean; filename?: string; row_count?: number; columns?: any[] }; | |
| } | |
| export async function loadDemo() { | |
| const res = await api.post('/api/demo/load'); | |
| return res.data; | |
| } | |