Spaces:
Sleeping
Sleeping
Update app.py
#1
by keertan2610 - opened
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")
|