Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,37 +1,26 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import os
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
-
|
|
|
|
| 7 |
|
| 8 |
-
print(
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 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="
|
| 31 |
-
style="border:
|
| 32 |
-
|
| 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()
|