Update Gradio app with multiple files
Browse files
app.py
CHANGED
|
@@ -123,15 +123,29 @@ def simple_generate(prompt: str) -> Optional[str]:
|
|
| 123 |
|
| 124 |
return video_path
|
| 125 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
# Build the Gradio interface
|
| 127 |
with gr.Blocks(title="Sora-2 Text-to-Video Generator", theme=gr.themes.Soft()) as demo:
|
| 128 |
gr.HTML("""
|
| 129 |
<div style="text-align: center; margin-bottom: 2rem;">
|
| 130 |
<h1>🎬 Sora-2 Text-to-Video Generator</h1>
|
|
|
|
| 131 |
<p><a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank">Built with anycoder</a></p>
|
| 132 |
</div>
|
| 133 |
""")
|
| 134 |
|
|
|
|
|
|
|
|
|
|
| 135 |
prompt_input = gr.Textbox(
|
| 136 |
label="Enter your prompt",
|
| 137 |
placeholder="Describe the video you want to create...",
|
|
@@ -142,18 +156,22 @@ with gr.Blocks(title="Sora-2 Text-to-Video Generator", theme=gr.themes.Soft()) a
|
|
| 142 |
|
| 143 |
video_output = gr.Video(label="Generated Video")
|
| 144 |
|
| 145 |
-
# Event handler
|
| 146 |
generate_btn.click(
|
| 147 |
-
fn=
|
| 148 |
-
inputs=prompt_input,
|
| 149 |
-
outputs=video_output
|
|
|
|
|
|
|
|
|
|
| 150 |
)
|
| 151 |
|
| 152 |
# Launch the application
|
| 153 |
if __name__ == "__main__":
|
|
|
|
|
|
|
| 154 |
demo.launch(
|
| 155 |
-
show_api=
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
server_port=7860
|
| 159 |
)
|
|
|
|
| 123 |
|
| 124 |
return video_path
|
| 125 |
|
| 126 |
+
def generate_with_auth(prompt: str, profile: gr.OAuthProfile | None) -> Optional[str]:
|
| 127 |
+
"""
|
| 128 |
+
Wrapper function that checks if user is logged in before generating video.
|
| 129 |
+
"""
|
| 130 |
+
if profile is None:
|
| 131 |
+
raise gr.Error("Click Sign in with Hugging Face button to use this app for free")
|
| 132 |
+
|
| 133 |
+
# User is logged in, proceed with video generation
|
| 134 |
+
return simple_generate(prompt)
|
| 135 |
+
|
| 136 |
# Build the Gradio interface
|
| 137 |
with gr.Blocks(title="Sora-2 Text-to-Video Generator", theme=gr.themes.Soft()) as demo:
|
| 138 |
gr.HTML("""
|
| 139 |
<div style="text-align: center; margin-bottom: 2rem;">
|
| 140 |
<h1>🎬 Sora-2 Text-to-Video Generator</h1>
|
| 141 |
+
<p style='color: orange;'>⚠️ You must Sign in with Hugging Face using the button to use this app.</p>
|
| 142 |
<p><a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank">Built with anycoder</a></p>
|
| 143 |
</div>
|
| 144 |
""")
|
| 145 |
|
| 146 |
+
# Add login button - required for OAuth
|
| 147 |
+
gr.LoginButton()
|
| 148 |
+
|
| 149 |
prompt_input = gr.Textbox(
|
| 150 |
label="Enter your prompt",
|
| 151 |
placeholder="Describe the video you want to create...",
|
|
|
|
| 156 |
|
| 157 |
video_output = gr.Video(label="Generated Video")
|
| 158 |
|
| 159 |
+
# Event handler - note the function now takes OAuthProfile
|
| 160 |
generate_btn.click(
|
| 161 |
+
fn=generate_with_auth,
|
| 162 |
+
inputs=[prompt_input],
|
| 163 |
+
outputs=video_output,
|
| 164 |
+
queue=False,
|
| 165 |
+
api_name=False,
|
| 166 |
+
show_api=False,
|
| 167 |
)
|
| 168 |
|
| 169 |
# Launch the application
|
| 170 |
if __name__ == "__main__":
|
| 171 |
+
# Launch without special auth parameters
|
| 172 |
+
# OAuth is enabled via Space metadata (hf_oauth: true in README.md)
|
| 173 |
demo.launch(
|
| 174 |
+
show_api=False,
|
| 175 |
+
enable_monitoring=False,
|
| 176 |
+
quiet=True,
|
|
|
|
| 177 |
)
|