Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
CHANGED
|
@@ -475,25 +475,39 @@ def create_interface():
|
|
| 475 |
if __name__ == "__main__":
|
| 476 |
app = create_interface()
|
| 477 |
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
s.bind(('', 0))
|
| 481 |
-
s.listen(1)
|
| 482 |
-
port = s.getsockname()[1]
|
| 483 |
-
return port
|
| 484 |
|
| 485 |
-
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
|
| 490 |
-
|
| 491 |
-
|
| 492 |
-
|
| 493 |
-
|
| 494 |
-
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
|
| 498 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 499 |
|
|
|
|
| 475 |
if __name__ == "__main__":
|
| 476 |
app = create_interface()
|
| 477 |
|
| 478 |
+
# Check if running on Hugging Face Spaces
|
| 479 |
+
is_huggingface = os.getenv("SPACE_ID") is not None
|
|
|
|
|
|
|
|
|
|
|
|
|
| 480 |
|
| 481 |
+
if is_huggingface:
|
| 482 |
+
# Hugging Face Spaces configuration
|
| 483 |
+
print(f"π Launching Python to C++ Code Optimizer on Hugging Face Spaces")
|
| 484 |
+
print(f"π Password protection enabled")
|
| 485 |
+
|
| 486 |
+
app.launch(
|
| 487 |
+
auth=("user", APP_PASSWORD),
|
| 488 |
+
auth_message="π Enter credentials to access the Python to C++ Code Optimizer"
|
| 489 |
+
)
|
| 490 |
+
else:
|
| 491 |
+
# Local development configuration
|
| 492 |
+
def find_free_port():
|
| 493 |
+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
| 494 |
+
s.bind(('', 0))
|
| 495 |
+
s.listen(1)
|
| 496 |
+
port = s.getsockname()[1]
|
| 497 |
+
return port
|
| 498 |
+
|
| 499 |
+
free_port = find_free_port()
|
| 500 |
+
print(f"π Launching Python to C++ Code Optimizer on port: {free_port}")
|
| 501 |
+
print(f"π Password protection enabled")
|
| 502 |
+
|
| 503 |
+
# Launch with authentication
|
| 504 |
+
app.launch(
|
| 505 |
+
inbrowser=True,
|
| 506 |
+
share=False,
|
| 507 |
+
server_name="127.0.0.1",
|
| 508 |
+
server_port=free_port,
|
| 509 |
+
show_error=True,
|
| 510 |
+
auth=("user", APP_PASSWORD),
|
| 511 |
+
auth_message="π Enter credentials to access the Python to C++ Code Optimizer"
|
| 512 |
+
)
|
| 513 |
|