| from fastapi import FastAPI, HTTPException |
| from pydantic import BaseModel |
| from gradio_client import Client, handle_file |
| import uvicorn |
|
|
| app = FastAPI(title="Omni Editor API") |
|
|
| |
| SOURCE_SPACE = "selfit-camera/omni-image-editor" |
|
|
| try: |
| |
| client = Client(SOURCE_SPACE) |
| except Exception as e: |
| print(f"Connection Failed: {e}") |
|
|
| class ImageEditRequest(BaseModel): |
| imageUrl: str |
| prompt: str = "enhance" |
|
|
| @app.get("/") |
| def health_check(): |
| return {"status": "Live", "author": "Xalman"} |
|
|
| @app.post("/predict") |
| async def predict(request: ImageEditRequest): |
| try: |
| |
| |
| result = client.predict( |
| image=handle_file(request.imageUrl), |
| edit_command=request.prompt, |
| api_name="/predict" |
| ) |
| |
| |
| return { |
| "status": "success", |
| "result_url": result |
| } |
| except Exception as e: |
| print(f"Detailed Server Error: {e}") |
| raise HTTPException(status_code=500, detail=str(e)) |
|
|
| if __name__ == "__main__": |
| uvicorn.run(app, host="0.0.0.0", port=7860) |
| |