Amitai Getzler commited on
Commit
9ef8061
1 Parent(s): ec28284

:heavy_plus_sign: Add

Browse files
Files changed (1) hide show
  1. app.py +16 -1
app.py CHANGED
@@ -1,4 +1,4 @@
1
- from fastapi import FastAPI, HTTPException
2
  from pydantic import BaseModel
3
  from typing import List, Dict, Any, Union
4
  from base64 import b64decode
@@ -158,5 +158,20 @@ def embedd(request: EmbeddRequest):
158
  except Exception as e:
159
  raise HTTPException(status_code=500, detail=str(e))
160
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161
  if __name__ == "__main__":
162
  uvicorn.run(app, host="0.0.0.0", port=8000)
 
1
+ from fastapi import FastAPI, HTTPException, Request
2
  from pydantic import BaseModel
3
  from typing import List, Dict, Any, Union
4
  from base64 import b64decode
 
158
  except Exception as e:
159
  raise HTTPException(status_code=500, detail=str(e))
160
 
161
+ @app.post("/process")
162
+ async def process(request: Request):
163
+ try:
164
+ data = await request.json()
165
+ if "candidates" in data and "image" in data:
166
+ classify_request = ClassifyRequest(**data)
167
+ return classify(classify_request)
168
+ elif "batch" in data:
169
+ embedd_request = EmbeddRequest(**data)
170
+ return embedd(embedd_request)
171
+ else:
172
+ raise HTTPException(status_code=400, detail="Invalid request format.")
173
+ except Exception as e:
174
+ raise HTTPException(status_code=500, detail=str(e))
175
+
176
  if __name__ == "__main__":
177
  uvicorn.run(app, host="0.0.0.0", port=8000)