Spaces:
Sleeping
Sleeping
udbhav
commited on
Commit
·
d69f126
1
Parent(s):
fac7e31
added trame reqs
Browse files
app.py
CHANGED
|
@@ -62,12 +62,23 @@ def download_private_repo(cache_dir, repo_id, hf_token):
|
|
| 62 |
|
| 63 |
def load_private_app(repo_path):
|
| 64 |
sys.path.insert(0, str(repo_path))
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
def main():
|
| 73 |
hf_token = os.environ.get("HF_TOKEN")
|
|
@@ -83,14 +94,28 @@ def main():
|
|
| 83 |
repo_path = download_private_repo(cache_dir, repo_id, hf_token)
|
| 84 |
demo = load_private_app(repo_path)
|
| 85 |
|
| 86 |
-
|
| 87 |
-
demo.
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
|
| 96 |
if __name__ == "__main__":
|
|
|
|
| 62 |
|
| 63 |
def load_private_app(repo_path):
|
| 64 |
sys.path.insert(0, str(repo_path))
|
| 65 |
+
try:
|
| 66 |
+
import app as private_app
|
| 67 |
+
# Check for app or demo attribute
|
| 68 |
+
if hasattr(private_app, "app"):
|
| 69 |
+
return private_app.app
|
| 70 |
+
elif hasattr(private_app, "demo"):
|
| 71 |
+
return private_app.demo
|
| 72 |
+
# Check if PFMDemo class exists and instantiate it
|
| 73 |
+
elif hasattr(private_app, "PFMDemo"):
|
| 74 |
+
app_instance = private_app.PFMDemo()
|
| 75 |
+
app_instance.server.controller.add("decimate_again", app_instance.decimate_again)
|
| 76 |
+
app_instance.server.controller.add("reset_mesh", app_instance.reset_mesh)
|
| 77 |
+
return app_instance
|
| 78 |
+
raise RuntimeError("No demo/app found in private repo")
|
| 79 |
+
except Exception as e:
|
| 80 |
+
traceback.print_exc()
|
| 81 |
+
raise RuntimeError(f"Failed to load app from private repo: {e}")
|
| 82 |
|
| 83 |
def main():
|
| 84 |
hf_token = os.environ.get("HF_TOKEN")
|
|
|
|
| 94 |
repo_path = download_private_repo(cache_dir, repo_id, hf_token)
|
| 95 |
demo = load_private_app(repo_path)
|
| 96 |
|
| 97 |
+
# Check if it's a Trame app (has server.start method) or Gradio app (has launch method)
|
| 98 |
+
if hasattr(demo, 'server') and hasattr(demo.server, 'start'):
|
| 99 |
+
# Trame app
|
| 100 |
+
port = int(os.environ.get("PORT", "7860"))
|
| 101 |
+
demo.server.start(
|
| 102 |
+
port=port,
|
| 103 |
+
open_browser=False,
|
| 104 |
+
show_connection_info=True,
|
| 105 |
+
backend="aiohttp",
|
| 106 |
+
exec_mode="main",
|
| 107 |
+
)
|
| 108 |
+
elif hasattr(demo, 'launch'):
|
| 109 |
+
# Gradio app
|
| 110 |
+
demo.launch(
|
| 111 |
+
server_name="0.0.0.0",
|
| 112 |
+
server_port=7860,
|
| 113 |
+
share=False,
|
| 114 |
+
show_error=True,
|
| 115 |
+
allowed_paths=[str(repo_path), DATA_DIR]
|
| 116 |
+
)
|
| 117 |
+
else:
|
| 118 |
+
raise RuntimeError("App does not have launch() or server.start() method")
|
| 119 |
|
| 120 |
|
| 121 |
if __name__ == "__main__":
|