Commit
Β·
360b135
1
Parent(s):
8eb16a3
Fix HF Spaces startup - use port 7860 and simplify startup logic
Browse files- app.py +16 -22
- backend/config.py +2 -2
app.py
CHANGED
|
@@ -148,36 +148,25 @@ if __name__ == "__main__":
|
|
| 148 |
signal.signal(signal.SIGINT, cleanup_handler)
|
| 149 |
signal.signal(signal.SIGTERM, cleanup_handler)
|
| 150 |
|
| 151 |
-
print("π Starting Edge LLM
|
| 152 |
|
| 153 |
-
#
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
if original_port == 0:
|
| 157 |
-
# Auto-assign a free port starting from 8000
|
| 158 |
-
original_port = find_free_port(8000)
|
| 159 |
-
print(f"π Auto-assigned port: {original_port}")
|
| 160 |
-
else:
|
| 161 |
-
kill_processes_on_port(original_port)
|
| 162 |
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
update_frontend_config(port)
|
| 170 |
|
| 171 |
# Auto-build frontend if needed
|
| 172 |
if should_rebuild_frontend():
|
| 173 |
print("π¨ Building frontend...")
|
| 174 |
build_frontend()
|
| 175 |
|
| 176 |
-
#
|
| 177 |
-
print(f"π Starting server on http://localhost:{port}")
|
| 178 |
-
print("π― Frontend and Backend integrated - ready to use!")
|
| 179 |
-
|
| 180 |
-
# Auto-open browser after a short delay
|
| 181 |
def open_browser():
|
| 182 |
time.sleep(2)
|
| 183 |
webbrowser.open(f'http://localhost:{port}')
|
|
@@ -186,6 +175,11 @@ if __name__ == "__main__":
|
|
| 186 |
browser_thread = threading.Thread(target=open_browser)
|
| 187 |
browser_thread.daemon = True
|
| 188 |
browser_thread.start()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
|
| 190 |
# Start the server
|
| 191 |
uvicorn.run(app, host="0.0.0.0", port=port)
|
|
|
|
| 148 |
signal.signal(signal.SIGINT, cleanup_handler)
|
| 149 |
signal.signal(signal.SIGTERM, cleanup_handler)
|
| 150 |
|
| 151 |
+
print("π Starting Edge LLM...")
|
| 152 |
|
| 153 |
+
# Use HF Spaces default port (7860) or environment variable
|
| 154 |
+
port = int(os.getenv("PORT", "7860"))
|
| 155 |
+
print(f"π‘ Using port: {port}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
|
| 157 |
+
# For Hugging Face Spaces, skip complex port logic and auto-build
|
| 158 |
+
is_hf_space = os.getenv("SPACE_ID") is not None
|
| 159 |
+
|
| 160 |
+
if not is_hf_space:
|
| 161 |
+
# Local development: kill existing processes and auto-build
|
| 162 |
+
kill_processes_on_port(port)
|
|
|
|
| 163 |
|
| 164 |
# Auto-build frontend if needed
|
| 165 |
if should_rebuild_frontend():
|
| 166 |
print("π¨ Building frontend...")
|
| 167 |
build_frontend()
|
| 168 |
|
| 169 |
+
# Auto-open browser for local development
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
def open_browser():
|
| 171 |
time.sleep(2)
|
| 172 |
webbrowser.open(f'http://localhost:{port}')
|
|
|
|
| 175 |
browser_thread = threading.Thread(target=open_browser)
|
| 176 |
browser_thread.daemon = True
|
| 177 |
browser_thread.start()
|
| 178 |
+
|
| 179 |
+
try:
|
| 180 |
+
# Start the backend server
|
| 181 |
+
print(f"π Starting server on http://{'0.0.0.0' if is_hf_space else 'localhost'}:{port}")
|
| 182 |
+
print("π― Frontend and Backend integrated - ready to use!")
|
| 183 |
|
| 184 |
# Start the server
|
| 185 |
uvicorn.run(app, host="0.0.0.0", port=port)
|
backend/config.py
CHANGED
|
@@ -59,6 +59,6 @@ CORS_ORIGINS = ["*"] # Allow all origins for HF Space
|
|
| 59 |
FRONTEND_DIST_DIR = "static"
|
| 60 |
ASSETS_DIR = "static/assets"
|
| 61 |
|
| 62 |
-
# Server settings
|
| 63 |
HOST = "0.0.0.0"
|
| 64 |
-
DEFAULT_PORT = int(os.getenv("PORT", "
|
|
|
|
| 59 |
FRONTEND_DIST_DIR = "static"
|
| 60 |
ASSETS_DIR = "static/assets"
|
| 61 |
|
| 62 |
+
# Server settings
|
| 63 |
HOST = "0.0.0.0"
|
| 64 |
+
DEFAULT_PORT = int(os.getenv("PORT", "7860")) # Use HF Spaces default port 7860
|