LiuZichen commited on
Commit
8e80fc8
·
verified ·
1 Parent(s): b3dfb1d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -7
app.py CHANGED
@@ -37,10 +37,19 @@ BACKEND_URL = "LiuZichen/MagicQuillV2"
37
  SAM_URL = "LiuZichen/MagicQuillHelper"
38
 
39
  print(f"Connecting to backend at: {BACKEND_URL}")
40
- backend_client = Client(BACKEND_URL, hf_token=hf_token)
 
 
 
 
 
41
 
42
  print(f"Connecting to SAM client at: {SAM_URL}")
43
- sam_client = Client(SAM_URL, hf_token=hf_token)
 
 
 
 
44
 
45
  # --- Helper Functions ---
46
 
@@ -93,6 +102,7 @@ def generate_image_handler(x, negative_prompt, fine_edge, fix_perspective, grow_
93
  return x
94
 
95
  # --- Gradio UI ---
 
96
  with gr.Blocks(title="MagicQuill V2") as demo:
97
  with gr.Row():
98
  ms = MagicQuillV2()
@@ -303,9 +313,5 @@ async def segmentation(request: Request):
303
  print(f"Error in segmentation: {e}")
304
  return {"error": str(e)}
305
 
306
- # Mount the Gradio app
307
- app = gr.mount_gradio_app(app, demo, path="/")
308
-
309
  if __name__ == "__main__":
310
- uvicorn.run(app, host="0.0.0.0", port=7860)
311
-
 
37
  SAM_URL = "LiuZichen/MagicQuillHelper"
38
 
39
  print(f"Connecting to backend at: {BACKEND_URL}")
40
+
41
+ try:
42
+ backend_client = Client(BACKEND_URL, hf_token=hf_token)
43
+ except Exception as e:
44
+ print(f"Failed to connect to backend: {e}")
45
+ backend_client = None
46
 
47
  print(f"Connecting to SAM client at: {SAM_URL}")
48
+ try:
49
+ sam_client = Client(SAM_URL, hf_token=hf_token)
50
+ except Exception as e:
51
+ print(f"Failed to connect to SAM client: {e}")
52
+ sam_client = None
53
 
54
  # --- Helper Functions ---
55
 
 
102
  return x
103
 
104
  # --- Gradio UI ---
105
+
106
  with gr.Blocks(title="MagicQuill V2") as demo:
107
  with gr.Row():
108
  ms = MagicQuillV2()
 
313
  print(f"Error in segmentation: {e}")
314
  return {"error": str(e)}
315
 
 
 
 
316
  if __name__ == "__main__":
317
+ uvicorn.run(app, host="0.0.0.0", port=7860)