add remote server ip
Browse files- app.py +3 -0
- src/sharp/web/app.py +11 -1
app.py
CHANGED
|
@@ -8,6 +8,9 @@ SRC = ROOT / "src"
|
|
| 8 |
if str(SRC) not in sys.path:
|
| 9 |
sys.path.insert(0, str(SRC))
|
| 10 |
|
|
|
|
|
|
|
|
|
|
| 11 |
# Import the existing Gradio Blocks demo from src/sharp/web/app.py
|
| 12 |
from sharp.web.app import demo as _demo # type: ignore
|
| 13 |
|
|
|
|
| 8 |
if str(SRC) not in sys.path:
|
| 9 |
sys.path.insert(0, str(SRC))
|
| 10 |
|
| 11 |
+
# Configure backend API base URL for Spaces if not set
|
| 12 |
+
os.environ.setdefault("API_BASE_URL", "http://134.199.133.78:80")
|
| 13 |
+
|
| 14 |
# Import the existing Gradio Blocks demo from src/sharp/web/app.py
|
| 15 |
from sharp.web.app import demo as _demo # type: ignore
|
| 16 |
|
src/sharp/web/app.py
CHANGED
|
@@ -11,7 +11,11 @@ import gradio as gr
|
|
| 11 |
# Front-end Gradio app that calls the backend FastAPI service hosted on GPU cloud.
|
| 12 |
# Configure the backend base URL through environment variable on Hugging Face Spaces.
|
| 13 |
# Example: API_BASE_URL = "https://your-api.example.com"
|
| 14 |
-
API_BASE_URL = os.getenv("API_BASE_URL"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
|
| 17 |
def _files_payload(images):
|
|
@@ -42,6 +46,9 @@ def predict_single(image):
|
|
| 42 |
if not files:
|
| 43 |
return None, "Invalid image input."
|
| 44 |
|
|
|
|
|
|
|
|
|
|
| 45 |
try:
|
| 46 |
resp = requests.post(f"{API_BASE_URL}/predict", files=files, timeout=120)
|
| 47 |
resp.raise_for_status()
|
|
@@ -74,6 +81,9 @@ def predict_batch(images):
|
|
| 74 |
if not files:
|
| 75 |
return None, "Invalid inputs."
|
| 76 |
|
|
|
|
|
|
|
|
|
|
| 77 |
try:
|
| 78 |
resp = requests.post(f"{API_BASE_URL}/predict", files=files, timeout=300)
|
| 79 |
resp.raise_for_status()
|
|
|
|
| 11 |
# Front-end Gradio app that calls the backend FastAPI service hosted on GPU cloud.
|
| 12 |
# Configure the backend base URL through environment variable on Hugging Face Spaces.
|
| 13 |
# Example: API_BASE_URL = "https://your-api.example.com"
|
| 14 |
+
API_BASE_URL = os.getenv("API_BASE_URL")
|
| 15 |
+
MISSING_BACKEND_MSG = (
|
| 16 |
+
"Backend API is not configured. Set API_BASE_URL in Spaces Secrets "
|
| 17 |
+
"(e.g., http://134.199.133.78:80)"
|
| 18 |
+
)
|
| 19 |
|
| 20 |
|
| 21 |
def _files_payload(images):
|
|
|
|
| 46 |
if not files:
|
| 47 |
return None, "Invalid image input."
|
| 48 |
|
| 49 |
+
if not API_BASE_URL:
|
| 50 |
+
return None, MISSING_BACKEND_MSG
|
| 51 |
+
|
| 52 |
try:
|
| 53 |
resp = requests.post(f"{API_BASE_URL}/predict", files=files, timeout=120)
|
| 54 |
resp.raise_for_status()
|
|
|
|
| 81 |
if not files:
|
| 82 |
return None, "Invalid inputs."
|
| 83 |
|
| 84 |
+
if not API_BASE_URL:
|
| 85 |
+
return None, MISSING_BACKEND_MSG
|
| 86 |
+
|
| 87 |
try:
|
| 88 |
resp = requests.post(f"{API_BASE_URL}/predict", files=files, timeout=300)
|
| 89 |
resp.raise_for_status()
|