ar0551 commited on
Commit
526c091
ยท
verified ยท
1 Parent(s): bb04a18

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -29
app.py CHANGED
@@ -6,10 +6,6 @@ import cv2
6
  from PIL import Image
7
  import spaces
8
 
9
- from fastapi import FastAPI, UploadFile, Form
10
- from fastapi.responses import StreamingResponse
11
- import io
12
-
13
 
14
  # ๐ŸŒŸ Auto-detect device (CPU/GPU)
15
  device = "cuda"
@@ -133,30 +129,6 @@ with gr.Blocks() as demo:
133
  inputs=[prompt, strength, guidance],
134
  outputs=[edge_output, result_output]
135
  )
136
-
137
- # Define your own FastAPI app for external access
138
- external_api = FastAPI()
139
-
140
- # Add your custom POST route (for Rhino/Grasshopper)
141
- @external_api.post("/run_external")
142
- async def run_external(prompt: str = Form(...), image: UploadFile = Form(...)):
143
- contents = await image.read()
144
- img = Image.open(io.BytesIO(contents)).convert("RGB")
145
- # Use your generate_image function (you already have it)
146
- _, result = generate_image(prompt, img, 100, 150, 0.7, 7.5, 0.5)
147
-
148
- # Return image as PNG stream
149
- buf = io.BytesIO()
150
- result.save(buf, format="PNG")
151
- buf.seek(0)
152
- return StreamingResponse(buf, media_type="image/png")
153
-
154
- # ๐Ÿ” Mount Gradio under the FastAPI app
155
- external_api.mount("/", demo) # Gradio stays at root (/) in the browser
156
-
157
- # This is the app Hugging Face expects
158
- app = external_api
159
-
160
 
161
  # ๐Ÿš€ Launch the app
162
- #demo.launch()
 
6
  from PIL import Image
7
  import spaces
8
 
 
 
 
 
9
 
10
  # ๐ŸŒŸ Auto-detect device (CPU/GPU)
11
  device = "cuda"
 
129
  inputs=[prompt, strength, guidance],
130
  outputs=[edge_output, result_output]
131
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
 
133
  # ๐Ÿš€ Launch the app
134
+ demo.launch()