Spaces:
Sleeping
Sleeping
gradio version check 3
Browse files- app.py +15 -28
- gradio_app.py +13 -3
- requirements.txt +2 -2
app.py
CHANGED
|
@@ -11,38 +11,25 @@ def main():
|
|
| 11 |
try:
|
| 12 |
demo = create_gradio_interface()
|
| 13 |
|
| 14 |
-
# For Hugging Face Spaces deployment
|
| 15 |
import os
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
os.getenv("SPACE_ID") is not None or
|
| 20 |
-
os.getenv("SYSTEM") == "spaces" or
|
| 21 |
-
os.getenv("SPACE_AUTHOR_NAME") is not None or
|
| 22 |
-
os.getenv("SPACE_REPO_NAME") is not None or
|
| 23 |
-
"hf.space" in os.getenv("SPACE_HOST", "") or
|
| 24 |
-
os.path.exists("/home/user") # HF Spaces user directory
|
| 25 |
-
)
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
demo.launch()
|
| 31 |
-
else:
|
| 32 |
-
# Running locally
|
| 33 |
-
print("π Running in local environment")
|
| 34 |
-
try:
|
| 35 |
-
demo.launch(
|
| 36 |
-
server_name="0.0.0.0",
|
| 37 |
-
server_port=7860,
|
| 38 |
-
share=False
|
| 39 |
-
)
|
| 40 |
-
except ValueError as e:
|
| 41 |
-
if "shareable link must be created" in str(e):
|
| 42 |
-
print("Localhost not accessible, creating shareable link...")
|
| 43 |
-
demo.launch(share=True)
|
| 44 |
-
else:
|
| 45 |
-
raise e
|
| 46 |
except Exception as e:
|
| 47 |
print(f"Error launching app: {e}")
|
| 48 |
import traceback
|
|
|
|
| 11 |
try:
|
| 12 |
demo = create_gradio_interface()
|
| 13 |
|
| 14 |
+
# For Hugging Face Spaces deployment - always use share=True for safety
|
| 15 |
import os
|
| 16 |
|
| 17 |
+
print("π Launching PupilSense...")
|
| 18 |
+
print(f"Environment variables: SPACE_ID={os.getenv('SPACE_ID')}, SYSTEM={os.getenv('SYSTEM')}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
+
# Always use share=True for HF Spaces compatibility
|
| 21 |
+
try:
|
| 22 |
+
demo.launch(
|
| 23 |
+
server_name="0.0.0.0",
|
| 24 |
+
server_port=7860,
|
| 25 |
+
share=True,
|
| 26 |
+
show_error=True,
|
| 27 |
+
quiet=False
|
| 28 |
+
)
|
| 29 |
+
except Exception as launch_error:
|
| 30 |
+
print(f"Launch failed with share=True, trying basic launch: {launch_error}")
|
| 31 |
+
# Fallback to most basic launch
|
| 32 |
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
except Exception as e:
|
| 34 |
print(f"Error launching app: {e}")
|
| 35 |
import traceback
|
gradio_app.py
CHANGED
|
@@ -276,8 +276,11 @@ def process_media_unified(media_input, pupil_selection, tv_model, blink_detectio
|
|
| 276 |
def create_gradio_interface():
|
| 277 |
"""Create and configure the Gradio interface with proper API support."""
|
| 278 |
|
| 279 |
-
|
| 280 |
-
|
|
|
|
|
|
|
|
|
|
| 281 |
gr.Markdown("# ποΈ PupilSense - Pupil Diameter Analysis")
|
| 282 |
gr.Markdown("Upload an image or video to estimate pupil diameter using deep learning models.")
|
| 283 |
|
|
@@ -366,7 +369,14 @@ def create_gradio_interface():
|
|
| 366 |
outputs=[api_output, api_text_output]
|
| 367 |
)
|
| 368 |
|
| 369 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 370 |
|
| 371 |
|
| 372 |
def process_image_simple(image, pupil_selection, tv_model, blink_detection):
|
|
|
|
| 276 |
def create_gradio_interface():
|
| 277 |
"""Create and configure the Gradio interface with proper API support."""
|
| 278 |
|
| 279 |
+
print("π§ Creating Gradio interface...")
|
| 280 |
+
|
| 281 |
+
try:
|
| 282 |
+
# Create a unified interface that can handle both images and videos
|
| 283 |
+
with gr.Blocks(title="ποΈ PupilSense ποΈπ΅οΈββοΈ") as demo:
|
| 284 |
gr.Markdown("# ποΈ PupilSense - Pupil Diameter Analysis")
|
| 285 |
gr.Markdown("Upload an image or video to estimate pupil diameter using deep learning models.")
|
| 286 |
|
|
|
|
| 369 |
outputs=[api_output, api_text_output]
|
| 370 |
)
|
| 371 |
|
| 372 |
+
print("β
Gradio interface created successfully")
|
| 373 |
+
return demo
|
| 374 |
+
|
| 375 |
+
except Exception as e:
|
| 376 |
+
print(f"β Error creating Gradio interface: {e}")
|
| 377 |
+
import traceback
|
| 378 |
+
traceback.print_exc()
|
| 379 |
+
raise e
|
| 380 |
|
| 381 |
|
| 382 |
def process_image_simple(image, pupil_selection, tv_model, blink_detection):
|
requirements.txt
CHANGED
|
@@ -28,5 +28,5 @@ torchvision>=0.12.0
|
|
| 28 |
torchcam
|
| 29 |
|
| 30 |
gradio==4.44.0
|
| 31 |
-
gradio-client==1.
|
| 32 |
-
pydantic
|
|
|
|
| 28 |
torchcam
|
| 29 |
|
| 30 |
gradio==4.44.0
|
| 31 |
+
gradio-client==1.4.0
|
| 32 |
+
pydantic>=2.0.0,<3.0.0
|