Saravutw commited on
Commit
28fcd37
·
verified ·
1 Parent(s): a50cb3d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -29
app.py CHANGED
@@ -1,37 +1,26 @@
1
  import gradio as gr
2
- import os
3
 
4
- # ชื Space ต้
5
- source_space = "selfit-camera/omni-image-editor"
6
- src_url = f"https://huggingface.co/spaces/{source_space}"
 
7
 
8
- print(f"=== กำลังพยยามเชือมต่อกับ {source_space} ===")
9
 
10
- # ดึง HF Token จาก Settings (ถ้ามี) เพื่อช่วยในการ Wake up space
11
- hf_token = os.getenv("HF_TOKEN")
12
-
13
- try:
14
- # วิธีที่ 1: พยายามโหลดแบบ Native API (ดีที่สุด)
15
- # ใส่ hf_token เพื่อช่วยปลุก Space ที่หลับอยู่ได้ดีขึ้น
16
- demo = gr.load(name=source_space, src="spaces", hf_token=hf_token)
17
- print("=== เชื่อมต่อ API สำเร็จ! ===")
18
-
19
- except Exception as e:
20
- # วิธีที่ 2: ถ้า API พัง หรือ Space หลับ (เจอ JSONDecodeError) -> ใช้ Iframe แทน
21
- print(f"=== ไม่สามารถโหลด API ได้ ({e}) ===")
22
- print("=== กำลังสลับไปใช้โหมด Iframe เพื่อแสดงผลหน้าเว็บโดยตรง ===")
23
-
24
- with gr.Blocks() as demo:
25
- gr.Markdown(f"### ⚠️ เชื่อมต่อ API โดยตรงไม่ได้ (Space ต้นทางอาจกำลังหลับ) \nระบบสลับมาใช้โหมดแสดงผลหน้าเว็บแทน คุณยังสามารถใช้งานได้ตามปกติ")
26
- # ฝังหน้าเว็บต้นทางลงไปเลย (วิธีนี้ไม่มีวัน Error)
27
- gr.HTML(f"""
28
- <iframe src="{src_url}"
29
  width="100%"
30
- height="800px"
31
- style="border:none;">
32
- </iframe>
33
- """)
 
 
34
 
35
- # รันแอปพลิเคชัน
36
  if __name__ == "__main__":
37
  demo.launch()
 
1
  import gradio as gr
 
2
 
3
+ # เปลียน URL เป็เวอร์ชัน "embed" (สำคัญมก)
4
+ # จากเดิม: https://huggingface.co/spaces/selfit-camera/omni-image-editor
5
+ # เป็น: https://selfit-camera-omni-image-editor.hf.space (Direct Link)
6
+ source_space_url = "https://selfit-camera-omni-image-editor.hf.space"
7
 
8
+ print("=== กำลังโหลดหน้ Interface ผาน Direct Embed Link ===")
9
 
10
+ with gr.Blocks(fill_height=True) as demo:
11
+ # ใช้ Iframe ชี้ไปที่ Direct Link ของ Space นั้นๆ
12
+ # วิธีนี้จะไม่โดนปฏิเสธการเชื่อมต่อ (Refused to connect)
13
+ gr.HTML(f"""
14
+ <iframe
15
+ src="{source_space_url}"
16
+ frameborder="0"
 
 
 
 
 
 
 
 
 
 
 
 
17
  width="100%"
18
+ height="100%"
19
+ style="min-height: 800px; border-radius: 8px;"
20
+ allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; getattr"
21
+ allowfullscreen>
22
+ </iframe>
23
+ """)
24
 
 
25
  if __name__ == "__main__":
26
  demo.launch()