Spaces:
Runtime error
Runtime error
API Bot commited on
Commit ·
a3fdeaa
1
Parent(s): f7a076c
Add hidden API components at root level to expose /api/predict endpoint
Browse files
app.py
CHANGED
|
@@ -871,9 +871,9 @@ with gr.Blocks(title="SAM2 Video (Transformers) - Interactive Segmentation", the
|
|
| 871 |
)
|
| 872 |
|
| 873 |
# ============================================================================
|
| 874 |
-
# COMBINED INTERFACE WITH
|
| 875 |
# ============================================================================
|
| 876 |
-
# Create
|
| 877 |
api_interface = gr.Interface(
|
| 878 |
fn=process_video_api,
|
| 879 |
inputs=[
|
|
@@ -905,16 +905,36 @@ api_interface = gr.Interface(
|
|
| 905 |
]
|
| 906 |
}
|
| 907 |
```
|
| 908 |
-
"""
|
| 909 |
-
api_name="predict" # This will create /api/predict endpoint
|
| 910 |
)
|
| 911 |
|
| 912 |
-
#
|
| 913 |
-
|
| 914 |
-
|
| 915 |
-
|
| 916 |
-
|
| 917 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 918 |
|
| 919 |
# Launch with API enabled
|
| 920 |
if __name__ == "__main__":
|
|
|
|
| 871 |
)
|
| 872 |
|
| 873 |
# ============================================================================
|
| 874 |
+
# COMBINED INTERFACE WITH EXPLICIT API ENDPOINT
|
| 875 |
# ============================================================================
|
| 876 |
+
# Create API interface with explicit endpoint
|
| 877 |
api_interface = gr.Interface(
|
| 878 |
fn=process_video_api,
|
| 879 |
inputs=[
|
|
|
|
| 905 |
]
|
| 906 |
}
|
| 907 |
```
|
| 908 |
+
"""
|
|
|
|
| 909 |
)
|
| 910 |
|
| 911 |
+
# Use gr.Blocks to combine both with proper API exposure
|
| 912 |
+
with gr.Blocks(title="SAM2 Video Tracking") as combined_demo:
|
| 913 |
+
gr.Markdown("# SAM2 Video Tracking")
|
| 914 |
+
|
| 915 |
+
with gr.Tabs():
|
| 916 |
+
with gr.TabItem("Interactive UI"):
|
| 917 |
+
demo.render()
|
| 918 |
+
|
| 919 |
+
with gr.TabItem("API"):
|
| 920 |
+
api_interface.render()
|
| 921 |
+
|
| 922 |
+
# Explicitly expose the API function at root level for external API calls
|
| 923 |
+
# This creates the /api/predict endpoint
|
| 924 |
+
api_video_input_hidden = gr.Video(visible=False)
|
| 925 |
+
api_annotations_input_hidden = gr.Textbox(visible=False)
|
| 926 |
+
api_checkpoint_input_hidden = gr.Radio(choices=["tiny", "small", "base_plus", "large"], visible=False)
|
| 927 |
+
api_remove_bg_input_hidden = gr.Checkbox(visible=False)
|
| 928 |
+
api_output_hidden = gr.Video(visible=False)
|
| 929 |
+
|
| 930 |
+
# This dummy component creates the external API endpoint
|
| 931 |
+
api_dummy_btn = gr.Button("API", visible=False)
|
| 932 |
+
api_dummy_btn.click(
|
| 933 |
+
fn=process_video_api,
|
| 934 |
+
inputs=[api_video_input_hidden, api_annotations_input_hidden, api_checkpoint_input_hidden, api_remove_bg_input_hidden],
|
| 935 |
+
outputs=api_output_hidden,
|
| 936 |
+
api_name="predict" # This creates /api/predict for external calls
|
| 937 |
+
)
|
| 938 |
|
| 939 |
# Launch with API enabled
|
| 940 |
if __name__ == "__main__":
|