Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,29 +1,25 @@
|
|
| 1 |
-
from fastapi import FastAPI
|
| 2 |
-
|
|
|
|
| 3 |
|
| 4 |
app = FastAPI()
|
| 5 |
|
| 6 |
-
@app.
|
| 7 |
-
async def
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
# The result is a tuple containing:
|
| 26 |
-
# [0] filepath (str): the generated image path,
|
| 27 |
-
# [1] used seed (str): the seed value used,
|
| 28 |
-
# [2] output gallery (list of dicts): additional output information.
|
| 29 |
-
return {"result": result}
|
|
|
|
| 1 |
+
from fastapi import FastAPI, Query
|
| 2 |
+
import subprocess
|
| 3 |
+
import json
|
| 4 |
|
| 5 |
app = FastAPI()
|
| 6 |
|
| 7 |
+
@app.get("/generate")
|
| 8 |
+
async def generate(
|
| 9 |
+
prompt: str,
|
| 10 |
+
image_url: str,
|
| 11 |
+
format: str = "landscape",
|
| 12 |
+
numberofimages: int = 1
|
| 13 |
+
):
|
| 14 |
+
# Ensure number of images doesn't exceed the limit
|
| 15 |
+
if numberofimages > 5:
|
| 16 |
+
numberofimages = 5
|
| 17 |
+
|
| 18 |
+
# Run the Python script
|
| 19 |
+
command = f'python flux1.py --prompt "{prompt}" --image_url "{image_url}" --format {format} --numberofimages {numberofimages}'
|
| 20 |
+
result = subprocess.run(command, shell=True, capture_output=True, text=True)
|
| 21 |
+
|
| 22 |
+
# Extract URLs from the output
|
| 23 |
+
urls = [line.split(": ")[1].strip() for line in result.stdout.split("\n") if "Generated Image" in line]
|
| 24 |
+
|
| 25 |
+
return {"urls": urls}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|