Spaces:
Running
Running
Update Gradio app with multiple files
Browse files
app.py
CHANGED
|
@@ -23,7 +23,7 @@ def verify_pro_status(token: Optional[Union[gr.OAuthToken, str]]) -> bool:
|
|
| 23 |
elif isinstance(token, str):
|
| 24 |
token_str = token
|
| 25 |
else:
|
| 26 |
-
return False
|
| 27 |
|
| 28 |
try:
|
| 29 |
user_info = whoami(token=token_str)
|
|
@@ -153,7 +153,7 @@ def generate_image_to_video(
|
|
| 153 |
|
| 154 |
def generate_with_pro_auth(
|
| 155 |
prompt: str,
|
| 156 |
-
oauth_token: Optional[gr.OAuthToken] = None
|
| 157 |
) -> Tuple[Optional[str], str]:
|
| 158 |
"""
|
| 159 |
Wrapper function that checks if user is PRO before generating text-to-video.
|
|
@@ -179,7 +179,7 @@ def generate_with_pro_auth(
|
|
| 179 |
def generate_image_to_video_with_pro_auth(
|
| 180 |
image_path: str,
|
| 181 |
prompt: str,
|
| 182 |
-
oauth_token: Optional[gr.OAuthToken] = None
|
| 183 |
) -> Tuple[Optional[str], str]:
|
| 184 |
"""
|
| 185 |
Wrapper function that checks if user is PRO before generating image-to-video.
|
|
@@ -271,7 +271,6 @@ def create_ui():
|
|
| 271 |
</div>
|
| 272 |
""")
|
| 273 |
|
| 274 |
-
# Changed gr.TabbedInterface to gr.Tabs as per Gradio API for inline tab content
|
| 275 |
with gr.Tabs() as tab_selector:
|
| 276 |
with gr.TabItem("Text-to-Video", id=0):
|
| 277 |
with gr.Row():
|
|
@@ -321,14 +320,14 @@ def create_ui():
|
|
| 321 |
# Event handler for generation with queue disabled
|
| 322 |
generate_btn_text.click(
|
| 323 |
fn=generate_with_pro_auth,
|
| 324 |
-
inputs=[prompt_input_text
|
| 325 |
outputs=[video_output_text, status_output_text],
|
| 326 |
queue=False,
|
| 327 |
api_name=False,
|
| 328 |
show_api=False,
|
| 329 |
)
|
| 330 |
|
| 331 |
-
with gr.TabItem("Image-to-Video", id=1):
|
| 332 |
with gr.Row():
|
| 333 |
with gr.Column(scale=1):
|
| 334 |
image_input = gr.Image(
|
|
@@ -374,7 +373,7 @@ def create_ui():
|
|
| 374 |
|
| 375 |
generate_btn_image.click(
|
| 376 |
fn=generate_image_to_video_with_pro_auth,
|
| 377 |
-
inputs=[image_input, prompt_input_image
|
| 378 |
outputs=[video_output_image, status_output_image],
|
| 379 |
queue=False,
|
| 380 |
api_name=False,
|
|
@@ -389,7 +388,9 @@ def create_ui():
|
|
| 389 |
""")
|
| 390 |
|
| 391 |
def control_access(profile: Optional[gr.OAuthProfile] = None, oauth_token: Optional[gr.OAuthToken] = None):
|
| 392 |
-
"""Control interface visibility based on PRO status.
|
|
|
|
|
|
|
| 393 |
if not profile:
|
| 394 |
# User not logged in
|
| 395 |
return gr.update(visible=False), gr.update(visible=False)
|
|
@@ -439,10 +440,11 @@ def create_ui():
|
|
| 439 |
return gr.update(visible=False), gr.update(visible=True, value=message)
|
| 440 |
|
| 441 |
# Check access on load
|
| 442 |
-
# gr.OAuthProfile and gr.OAuthToken are
|
|
|
|
| 443 |
demo.load(
|
| 444 |
control_access,
|
| 445 |
-
inputs=
|
| 446 |
outputs=[main_interface, pro_message]
|
| 447 |
)
|
| 448 |
|
|
|
|
| 23 |
elif isinstance(token, str):
|
| 24 |
token_str = token
|
| 25 |
else:
|
| 26 |
+
return False # Should not happen with correct type hints, but for safety
|
| 27 |
|
| 28 |
try:
|
| 29 |
user_info = whoami(token=token_str)
|
|
|
|
| 153 |
|
| 154 |
def generate_with_pro_auth(
|
| 155 |
prompt: str,
|
| 156 |
+
oauth_token: Optional[gr.OAuthToken] = None # Gradio will auto-inject this based on type hint
|
| 157 |
) -> Tuple[Optional[str], str]:
|
| 158 |
"""
|
| 159 |
Wrapper function that checks if user is PRO before generating text-to-video.
|
|
|
|
| 179 |
def generate_image_to_video_with_pro_auth(
|
| 180 |
image_path: str,
|
| 181 |
prompt: str,
|
| 182 |
+
oauth_token: Optional[gr.OAuthToken] = None # Gradio will auto-inject this based on type hint
|
| 183 |
) -> Tuple[Optional[str], str]:
|
| 184 |
"""
|
| 185 |
Wrapper function that checks if user is PRO before generating image-to-video.
|
|
|
|
| 271 |
</div>
|
| 272 |
""")
|
| 273 |
|
|
|
|
| 274 |
with gr.Tabs() as tab_selector:
|
| 275 |
with gr.TabItem("Text-to-Video", id=0):
|
| 276 |
with gr.Row():
|
|
|
|
| 320 |
# Event handler for generation with queue disabled
|
| 321 |
generate_btn_text.click(
|
| 322 |
fn=generate_with_pro_auth,
|
| 323 |
+
inputs=[prompt_input_text], # OAuth token is auto-injected by type hint
|
| 324 |
outputs=[video_output_text, status_output_text],
|
| 325 |
queue=False,
|
| 326 |
api_name=False,
|
| 327 |
show_api=False,
|
| 328 |
)
|
| 329 |
|
| 330 |
+
with gr.TabItem("Image-to-Video", id=1):
|
| 331 |
with gr.Row():
|
| 332 |
with gr.Column(scale=1):
|
| 333 |
image_input = gr.Image(
|
|
|
|
| 373 |
|
| 374 |
generate_btn_image.click(
|
| 375 |
fn=generate_image_to_video_with_pro_auth,
|
| 376 |
+
inputs=[image_input, prompt_input_image], # OAuth token is auto-injected by type hint
|
| 377 |
outputs=[video_output_image, status_output_image],
|
| 378 |
queue=False,
|
| 379 |
api_name=False,
|
|
|
|
| 388 |
""")
|
| 389 |
|
| 390 |
def control_access(profile: Optional[gr.OAuthProfile] = None, oauth_token: Optional[gr.OAuthToken] = None):
|
| 391 |
+
"""Control interface visibility based on PRO status.
|
| 392 |
+
Gradio automatically injects gr.OAuthProfile and gr.OAuthToken based on type hints
|
| 393 |
+
when OAuth is enabled for the Space."""
|
| 394 |
if not profile:
|
| 395 |
# User not logged in
|
| 396 |
return gr.update(visible=False), gr.update(visible=False)
|
|
|
|
| 440 |
return gr.update(visible=False), gr.update(visible=True, value=message)
|
| 441 |
|
| 442 |
# Check access on load
|
| 443 |
+
# No explicit inputs are needed here as gr.OAuthProfile and gr.OAuthToken are
|
| 444 |
+
# provided automatically by Gradio to the function based on type hints.
|
| 445 |
demo.load(
|
| 446 |
control_access,
|
| 447 |
+
inputs=None, # Removed explicit instantiation of OAuthProfile and OAuthToken
|
| 448 |
outputs=[main_interface, pro_message]
|
| 449 |
)
|
| 450 |
|