Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,8 @@ import httpx
|
|
| 3 |
from fastapi.responses import JSONResponse
|
| 4 |
from io import BytesIO
|
| 5 |
import fal_client
|
|
|
|
|
|
|
| 6 |
|
| 7 |
app = FastAPI()
|
| 8 |
|
|
@@ -11,25 +13,31 @@ def greet_json():
|
|
| 11 |
return {"Hello": "World!"}
|
| 12 |
|
| 13 |
|
| 14 |
-
@app.get("/
|
| 15 |
-
def
|
| 16 |
-
|
|
|
|
|
|
|
| 17 |
|
|
|
|
| 18 |
# Replace with your target external API URL
|
| 19 |
EXTERNAL_API_URL = "https://external-api.example.com/process"
|
| 20 |
|
| 21 |
-
@app.post("/
|
| 22 |
-
async def
|
| 23 |
# Read image data
|
| 24 |
image_bytes = await image.read()
|
| 25 |
|
| 26 |
# Optional: prepare image payload for external API
|
| 27 |
files = {"file": (image.filename, BytesIO(image_bytes), image.content_type)}
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
| 29 |
f.write(image_bytes)
|
| 30 |
|
| 31 |
#Upload the file to FAL
|
| 32 |
-
url = fal_client.upload_file(
|
| 33 |
|
| 34 |
# Call external API
|
| 35 |
handler = fal_client.submit(
|
|
@@ -41,6 +49,7 @@ async def send_image(image: UploadFile = File(...)):
|
|
| 41 |
"num_images": 2,
|
| 42 |
},
|
| 43 |
)
|
| 44 |
-
|
|
|
|
| 45 |
request_id = handler.request_id
|
| 46 |
return(f"check request id: {request_id}")
|
|
|
|
| 3 |
from fastapi.responses import JSONResponse
|
| 4 |
from io import BytesIO
|
| 5 |
import fal_client
|
| 6 |
+
import os
|
| 7 |
+
|
| 8 |
|
| 9 |
app = FastAPI()
|
| 10 |
|
|
|
|
| 13 |
return {"Hello": "World!"}
|
| 14 |
|
| 15 |
|
| 16 |
+
@app.get("/versionStatus")
|
| 17 |
+
def versionStatus(request_id: str):
|
| 18 |
+
status = fal_client.status("fal-ai/instant-character", request_id, with_logs=True)
|
| 19 |
+
return(status)
|
| 20 |
+
|
| 21 |
|
| 22 |
+
|
| 23 |
# Replace with your target external API URL
|
| 24 |
EXTERNAL_API_URL = "https://external-api.example.com/process"
|
| 25 |
|
| 26 |
+
@app.post("/makeVersions")
|
| 27 |
+
async def make_versions(image: UploadFile = File(...)):
|
| 28 |
# Read image data
|
| 29 |
image_bytes = await image.read()
|
| 30 |
|
| 31 |
# Optional: prepare image payload for external API
|
| 32 |
files = {"file": (image.filename, BytesIO(image_bytes), image.content_type)}
|
| 33 |
+
|
| 34 |
+
#Save the uploaded file tempoarily
|
| 35 |
+
file_path = f"/tmp/{image.filename}"
|
| 36 |
+
with open(filepath, "wb") as f:
|
| 37 |
f.write(image_bytes)
|
| 38 |
|
| 39 |
#Upload the file to FAL
|
| 40 |
+
url = fal_client.upload_file(filepath)
|
| 41 |
|
| 42 |
# Call external API
|
| 43 |
handler = fal_client.submit(
|
|
|
|
| 49 |
"num_images": 2,
|
| 50 |
},
|
| 51 |
)
|
| 52 |
+
# Clean up file
|
| 53 |
+
os.remove(file_path)
|
| 54 |
request_id = handler.request_id
|
| 55 |
return(f"check request id: {request_id}")
|