Endpoint to make predictions using the Magma model
(request: ImagePromptRequest)
| 151 | |
| 152 | @app.post("/predict", response_model=MagmaResponse) |
| 153 | async def predict(request: ImagePromptRequest): |
| 154 | """Endpoint to make predictions using the Magma model""" |
| 155 | if model is None: |
| 156 | raise HTTPException(status_code=503, detail="Model not loaded yet") |
| 157 | |
| 158 | try: |
| 159 | # Decode the base64 image |
| 160 | image_data = base64.b64decode(request.image) |
| 161 | image = Image.open(io.BytesIO(image_data)).convert("RGB") |
| 162 | |
| 163 | # Generate the response |
| 164 | normalized_actions, delta_values, text_response = generate_response( |
| 165 | image, request.prompt |
| 166 | ) |
| 167 | |
| 168 | return { |
| 169 | "text_response": text_response, |
| 170 | "normalized_actions": normalized_actions, |
| 171 | "delta_values": delta_values, |
| 172 | } |
| 173 | except Exception as e: |
| 174 | raise HTTPException( |
| 175 | status_code=500, detail=f"Error processing request: {str(e)}" |
| 176 | ) |
| 177 | |
| 178 | |
| 179 | @app.post("/predict_from_file", response_model=MagmaResponse) |
nothing calls this directly
no test coverage detected