MCPcopy
hub / github.com/microsoft/Magma / predict_from_file

Function predict_from_file

server/main.py:180–203  ·  view source on GitHub ↗

Endpoint to make predictions using an uploaded file

(file: UploadFile = File(...), prompt: str = Form(...))

Source from the content-addressed store, hash-verified

178
179@app.post("/predict_from_file", response_model=MagmaResponse)
180async def predict_from_file(file: UploadFile = File(...), prompt: str = Form(...)):
181 """Endpoint to make predictions using an uploaded file"""
182 if model is None:
183 raise HTTPException(status_code=503, detail="Model not loaded yet")
184
185 try:
186 # Read the image file
187 image_data = await file.read()
188 image = Image.open(io.BytesIO(image_data)).convert("RGB")
189
190 # Generate the response
191 normalized_actions, delta_values, text_response = generate_response(
192 image, prompt
193 )
194
195 return {
196 "text_response": text_response,
197 "normalized_actions": normalized_actions,
198 "delta_values": delta_values,
199 }
200 except Exception as e:
201 raise HTTPException(
202 status_code=500, detail=f"Error processing request: {str(e)}"
203 )
204
205
206@app.get("/health")

Callers

nothing calls this directly

Calls 1

generate_responseFunction · 0.85

Tested by

no test coverage detected