|
|
from fastapi import FastAPI, Query |
|
|
import subprocess |
|
|
import json |
|
|
|
|
|
app = FastAPI() |
|
|
|
|
|
@app.get("/generate") |
|
|
async def generate( |
|
|
prompt: str, |
|
|
image_url: str, |
|
|
format: str = "landscape", |
|
|
numberofimages: int = 1 |
|
|
): |
|
|
|
|
|
if numberofimages > 5: |
|
|
numberofimages = 5 |
|
|
|
|
|
|
|
|
command = f'python flux1.py --prompt "{prompt}" --image_url "{image_url}" --format {format} --numberofimages {numberofimages}' |
|
|
result = subprocess.run(command, shell=True, capture_output=True, text=True) |
|
|
|
|
|
|
|
|
urls = [line.split(": ")[1].strip() for line in result.stdout.split("\n") if "Generated Image" in line] |
|
|
|
|
|
return {"urls": urls} |