Spanicin commited on
Commit
061ce15
·
verified ·
1 Parent(s): 5d139d7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -30
app.py CHANGED
@@ -775,7 +775,6 @@ import spaces
775
  import logging
776
  import random
777
  import warnings
778
- #import gradio as gr
779
  import os
780
  import shutil
781
  import subprocess
@@ -792,6 +791,7 @@ from fastapi.responses import JSONResponse
792
  from fastapi.middleware.cors import CORSMiddleware
793
  from concurrent.futures import ThreadPoolExecutor
794
  import uvicorn
 
795
 
796
  # Configure logging
797
  logging.basicConfig(level=logging.INFO)
@@ -919,40 +919,15 @@ async def infer(input_image: UploadFile = File(...),
919
  contents = await input_image.read()
920
  image = Image.open(io.BytesIO(contents))
921
 
 
 
 
922
  # Run inference in a separate thread
923
- base64_image = await executor.submit(run_inference, image, upscale_factor, seed, num_inference_steps, controlnet_conditioning_scale)
924
 
925
  return JSONResponse(content={"base64_image": base64_image})
926
 
927
- # def run_gradio_app():
928
- # with gr.Blocks() as app:
929
- # gr.Markdown("## Image Upscaler using ControlNet")
930
-
931
- # # Define the inputs and outputs
932
- # input_image = gr.Image(type="pil", label="Input Image")
933
- # upscale_factor = gr.Slider(minimum=1, maximum=8, step=1, label="Upscale Factor")
934
- # seed = gr.Slider(minimum=0, maximum=100, step=1, label="Seed")
935
- # num_inference_steps = gr.Slider(minimum=1, maximum=100, step=1, label="Inference Steps")
936
- # controlnet_conditioning_scale = gr.Slider(minimum=0.0, maximum=1.0, step=0.1, label="ControlNet Conditioning Scale")
937
-
938
- # output_base64 = gr.Textbox(label="Base64 String", interactive=False)
939
-
940
- # # Create a button to trigger the processing
941
- # submit_button = gr.Button("Upscale Image")
942
-
943
- # # Define the function to run when the button is clicked
944
- # submit_button.click(run_inference,
945
- # inputs=[input_image, upscale_factor, seed, num_inference_steps, controlnet_conditioning_scale],
946
- # outputs=[output_base64])
947
-
948
- # app.launch()
949
-
950
  if __name__ == "__main__":
951
- # # Run Gradio app in a separate thread
952
- # import threading
953
- # gradio_thread = threading.Thread(target=run_gradio_app)
954
- # gradio_thread.start()
955
-
956
  # Start FastAPI server
957
  uvicorn.run(app, host="0.0.0.0", port=7860)
958
 
 
775
  import logging
776
  import random
777
  import warnings
 
778
  import os
779
  import shutil
780
  import subprocess
 
791
  from fastapi.middleware.cors import CORSMiddleware
792
  from concurrent.futures import ThreadPoolExecutor
793
  import uvicorn
794
+ import asyncio
795
 
796
  # Configure logging
797
  logging.basicConfig(level=logging.INFO)
 
919
  contents = await input_image.read()
920
  image = Image.open(io.BytesIO(contents))
921
 
922
+ # Get the current event loop
923
+ loop = asyncio.get_event_loop()
924
+
925
  # Run inference in a separate thread
926
+ base64_image = await loop.run_in_executor(executor, run_inference, image, upscale_factor, seed, num_inference_steps, controlnet_conditioning_scale)
927
 
928
  return JSONResponse(content={"base64_image": base64_image})
929
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
930
  if __name__ == "__main__":
 
 
 
 
 
931
  # Start FastAPI server
932
  uvicorn.run(app, host="0.0.0.0", port=7860)
933