Update TextGen/router.py
Browse files- TextGen/router.py +11 -1
TextGen/router.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import os
|
2 |
import time
|
|
|
3 |
from langchain_core.pydantic_v1 import BaseModel, Field
|
4 |
from fastapi import FastAPI, HTTPException, Query, Request
|
5 |
from fastapi.responses import StreamingResponse,Response
|
@@ -235,5 +236,14 @@ async def generate_song():
|
|
235 |
|
236 |
@app.post('/generate_image')
|
237 |
def Imagen(image:ImageGen=None):
|
238 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
239 |
return Response(content=image_bytes, media_type="image/png")
|
|
|
1 |
import os
|
2 |
import time
|
3 |
+
from io import BytesIO
|
4 |
from langchain_core.pydantic_v1 import BaseModel, Field
|
5 |
from fastapi import FastAPI, HTTPException, Query, Request
|
6 |
from fastapi.responses import StreamingResponse,Response
|
|
|
236 |
|
237 |
@app.post('/generate_image')
|
238 |
def Imagen(image:ImageGen=None):
|
239 |
+
pil_image =generate_image(image.prompt)
|
240 |
+
|
241 |
+
|
242 |
+
# Convert the PIL Image to bytes
|
243 |
+
img_byte_arr = BytesIO()
|
244 |
+
pil_image.save(img_byte_arr, format='PNG')
|
245 |
+
img_byte_arr = img_byte_arr.getvalue()
|
246 |
+
|
247 |
+
# Return the image as a PNG response
|
248 |
+
return Response(content=img_byte_arr, media_type="image/png")
|
249 |
return Response(content=image_bytes, media_type="image/png")
|