Dash-inc commited on
Commit
857b344
·
verified ·
1 Parent(s): 9abdb46

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +11 -10
main.py CHANGED
@@ -195,22 +195,23 @@ class UpscaleRequest(BaseModel):
195
  image_url: str
196
 
197
 
 
 
 
 
 
 
 
 
198
  @app.post("/upscale-image", response_model=dict)
199
  async def upscale_image(request: UpscaleRequest, background_tasks: BackgroundTasks):
200
- def process_image():
201
- response = requests.get(request.image_url)
202
- img = Image.open(BytesIO(response.content))
203
- upscaled_image = aura_sr.upscale_4x_overlapped(img)
204
- filename = f"upscaled_{uuid.uuid4()}.png"
205
- filepath = save_image_locally(upscaled_image, filename)
206
- return filepath
207
-
208
- task = executor.submit(process_image)
209
- background_tasks.add_task(task)
210
  return {"status": "Processing"}
211
 
212
 
213
 
 
214
  @app.get("/")
215
  async def root():
216
  return {"message": "API is up and running!"}
 
195
  image_url: str
196
 
197
 
198
+ def process_image(image_url):
199
+ response = requests.get(image_url)
200
+ img = Image.open(BytesIO(response.content))
201
+ upscaled_image = aura_sr.upscale_4x_overlapped(img)
202
+ filename = f"upscaled_{uuid.uuid4()}.png"
203
+ filepath = save_image_locally(upscaled_image, filename)
204
+ return filepath
205
+
206
  @app.post("/upscale-image", response_model=dict)
207
  async def upscale_image(request: UpscaleRequest, background_tasks: BackgroundTasks):
208
+ # Add the task directly to the background
209
+ background_tasks.add_task(process_image, request.image_url)
 
 
 
 
 
 
 
 
210
  return {"status": "Processing"}
211
 
212
 
213
 
214
+
215
  @app.get("/")
216
  async def root():
217
  return {"message": "API is up and running!"}