File size: 1,513 Bytes
f7725ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import axios from 'axios'

const BASE_URL = import.meta.env.VITE_API_URL || 'http://localhost:7860'

const api = axios.create({ baseURL: BASE_URL, timeout: 600000 })

api.interceptors.response.use(
  (res) => res,
  (err) => {
    const message = err.response?.data?.detail || err.message || 'Error desconocido'
    return Promise.reject(new Error(message))
  }
)

export const uploadFile = (file, onProgress) => {
  const formData = new FormData()
  formData.append('file', file)
  return api.post('/upload', formData, {
    headers: { 'Content-Type': 'multipart/form-data' },
    onUploadProgress: (e) => {
      if (e.total && onProgress) onProgress(Math.round((e.loaded * 100) / e.total))
    },
  })
}

export const extractVideoFrames = (videoId) =>
  api.post(`/extract-video-frames?video_id=${videoId}`)

export const runDetection = (imageIds, modelName, assetType, confThreshold = 0.45, engineerNotes = '') =>
  api.post('/detect', {
    image_ids: imageIds,
    model_name: modelName,
    asset_type: assetType,
    conf_threshold: confThreshold,
    engineer_notes: engineerNotes,
  })

export const generateReport = (inspectionId, engineerNotes) =>
  api.post('/generate-report', { inspection_id: inspectionId, engineer_notes: engineerNotes })

export const getModels = () => api.get('/models')
export const getInspections = () => api.get('/inspections')
export const getInspection = (id) => api.get(`/inspection/${id}`)
export const getDownloadUrl = (path) => `${BASE_URL}${path}`

export default api