czq0719 commited on
Commit
accfea4
·
1 Parent(s): 30d9c02

Add CritiFusion gradio app

Browse files
Files changed (2) hide show
  1. app.py +10 -4
  2. requirements.txt +1 -0
app.py CHANGED
@@ -7,7 +7,7 @@
7
  import os, re, io, json, time, base64, asyncio, inspect, traceback
8
  from pathlib import Path
9
  from typing import List, Dict, Optional, Tuple, Iterable, Set
10
-
11
  import torch
12
  from PIL import Image
13
  import nest_asyncio
@@ -808,7 +808,13 @@ def ui_run_full(
808
  return base_img, final_img, enhanced_77, meta_json
809
  except Exception:
810
  return None, None, "", traceback.format_exc()
 
 
 
811
 
 
 
 
812
  # =========================
813
  # 10) Gradio UI (matches your reference fixes)
814
  # =========================
@@ -863,7 +869,7 @@ with gr.Blocks(title="CritiFusion (SDXL) Demo", theme=gr.themes.Soft()) as demo:
863
  meta_json = gr.Code(label="Meta / Debug (JSON)", language="json")
864
 
865
  run_btn.click(
866
- fn=ui_run_once,
867
  inputs=[user_prompt, seed, H, W, preset, total_steps_refine, last_k, guidance, enabled_variants, save_outputs, out_dir],
868
  outputs=[gallery, meta_json],
869
  api_name=False,
@@ -905,7 +911,7 @@ with gr.Blocks(title="CritiFusion (SDXL) Demo", theme=gr.themes.Soft()) as demo:
905
  meta2 = gr.Code(label="Meta / Debug (JSON)", language="json")
906
 
907
  run2.click(
908
- fn=ui_run_full,
909
  inputs=[p2, seed2, H2, W2, preset2, align_mode, align_score, save2, out2],
910
  outputs=[base_img, final_img, enhanced, meta2],
911
  api_name=False,
@@ -913,4 +919,4 @@ with gr.Blocks(title="CritiFusion (SDXL) Demo", theme=gr.themes.Soft()) as demo:
913
  )
914
 
915
  # IMPORTANT: share=True fixes "localhost not accessible"
916
- demo.queue().launch(debug=True, share=True, max_threads=1, show_api=False)
 
7
  import os, re, io, json, time, base64, asyncio, inspect, traceback
8
  from pathlib import Path
9
  from typing import List, Dict, Optional, Tuple, Iterable, Set
10
+ import spaces
11
  import torch
12
  from PIL import Image
13
  import nest_asyncio
 
808
  return base_img, final_img, enhanced_77, meta_json
809
  except Exception:
810
  return None, None, "", traceback.format_exc()
811
+ @spaces.GPU
812
+ def ui_run_once_gpu(*args, **kwargs):
813
+ return ui_run_once(*args, **kwargs)
814
 
815
+ @spaces.GPU
816
+ def ui_run_full_gpu(*args, **kwargs):
817
+ return ui_run_full(*args, **kwargs)
818
  # =========================
819
  # 10) Gradio UI (matches your reference fixes)
820
  # =========================
 
869
  meta_json = gr.Code(label="Meta / Debug (JSON)", language="json")
870
 
871
  run_btn.click(
872
+ fn=ui_run_once_gpu,
873
  inputs=[user_prompt, seed, H, W, preset, total_steps_refine, last_k, guidance, enabled_variants, save_outputs, out_dir],
874
  outputs=[gallery, meta_json],
875
  api_name=False,
 
911
  meta2 = gr.Code(label="Meta / Debug (JSON)", language="json")
912
 
913
  run2.click(
914
+ fn=ui_run_full_gpu,
915
  inputs=[p2, seed2, H2, W2, preset2, align_mode, align_score, save2, out2],
916
  outputs=[base_img, final_img, enhanced, meta2],
917
  api_name=False,
 
919
  )
920
 
921
  # IMPORTANT: share=True fixes "localhost not accessible"
922
+ demo.queue().launch(debug=True, show_api=False)
requirements.txt CHANGED
@@ -9,3 +9,4 @@ pillow
9
  numpy
10
  together
11
  nest_asyncio
 
 
9
  numpy
10
  together
11
  nest_asyncio
12
+ spaces