(request: Request)
| 14 | app = FastAPI() |
| 15 | @app.post('/') |
| 16 | async def visual_glm(request: Request): |
| 17 | json_post_raw = await request.json() |
| 18 | print("Start to process request") |
| 19 | |
| 20 | json_post = json.dumps(json_post_raw) |
| 21 | request_data = json.loads(json_post) |
| 22 | |
| 23 | history = request_data.get("history") |
| 24 | image_encoded = request_data.get("image") |
| 25 | query = request_data.get("text") |
| 26 | image_path = process_image(image_encoded) |
| 27 | |
| 28 | with torch.no_grad(): |
| 29 | result = model.stream_chat(tokenizer, image_path, query, history=history) |
| 30 | last_result = None |
| 31 | for value in result: |
| 32 | last_result = value |
| 33 | answer = last_result[0] |
| 34 | |
| 35 | if os.path.isfile(image_path): |
| 36 | os.remove(image_path) |
| 37 | now = datetime.datetime.now() |
| 38 | time = now.strftime("%Y-%m-%d %H:%M:%S") |
| 39 | response = { |
| 40 | "result": answer, |
| 41 | "history": history, |
| 42 | "status": 200, |
| 43 | "time": time |
| 44 | } |
| 45 | return response |
| 46 | |
| 47 | |
| 48 | if __name__ == "__main__": |
nothing calls this directly
no test coverage detected