Kia09 keertan2610 commited on
Commit
e34bebd
·
verified ·
1 Parent(s): ec4b540

Update app.py (#1)

Browse files

- Update app.py (df845522f44990e23aa5938eb5b05c08752338b7)


Co-authored-by: Keertan Balaji <keertan2610@users.noreply.huggingface.co>

Files changed (1) hide show
  1. app.py +21 -0
app.py CHANGED
@@ -5,3 +5,24 @@ app = FastAPI()
5
  @app.get("/")
6
  def greet_json():
7
  return {"Hello": "World!"}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  @app.get("/")
6
  def greet_json():
7
  return {"Hello": "World!"}
8
+
9
+
10
+ @app.post("/generate-image")
11
+ async def generate_image(text: str = Form(...)):
12
+ # Create a blank image
13
+ image = Image.new('RGB', (512, 256), color=(73, 109, 137))
14
+ draw = ImageDraw.Draw(image)
15
+
16
+ # Use a default font
17
+ try:
18
+ font = ImageFont.truetype("arial.ttf", 30)
19
+ except:
20
+ font = ImageFont.load_default()
21
+
22
+ draw.text((10, 100), text, fill=(255, 255, 255), font=font)
23
+
24
+ # Convert image to bytes
25
+ buf = io.BytesIO()
26
+ image.save(buf, format="PNG")
27
+ buf.seek(0)
28
+ return StreamingResponse(buf, media_type="image/png")