akhaliq HF Staff commited on
Commit
f5b1bad
·
verified ·
1 Parent(s): e539341

Update Gradio app with multiple files

Browse files
Files changed (1) hide show
  1. app.py +40 -15
app.py CHANGED
@@ -11,18 +11,22 @@ client = InferenceClient(
11
  bill_to="huggingface",
12
  )
13
 
14
- def generate_video(image, prompt, progress=gr.Progress()):
15
  """
16
- Generate a video from an image using the Ovi model.
17
 
18
  Args:
19
  image: Input image (PIL Image or file path)
20
  prompt: Text prompt describing the desired motion/animation
 
21
  progress: Gradio progress tracker
22
 
23
  Returns:
24
  Path to the generated video file
25
  """
 
 
 
26
  if image is None:
27
  raise gr.Error("Please upload an image first!")
28
 
@@ -106,8 +110,14 @@ with gr.Blocks(
106
  margin: 1em 0;
107
  border-radius: 4px;
108
  }
 
 
 
 
 
 
109
  """,
110
- title="Image to Video Generator",
111
  ) as demo:
112
 
113
  gr.HTML(
@@ -130,6 +140,17 @@ with gr.Blocks(
130
  """
131
  )
132
 
 
 
 
 
 
 
 
 
 
 
 
133
  gr.HTML(
134
  """
135
  <div class="info-box">
@@ -171,13 +192,9 @@ with gr.Blocks(
171
 
172
  prompt_input = gr.Textbox(
173
  label="✍️ Text Prompt",
174
- placeholder="Describe the motion or animation you want to see. Use <S>text<E> for speech and <AUDCAP>description<ENDAUDCAP> for audio effects...",
175
  lines=3,
176
- value="The subject starts to move naturally",
177
  )
178
 
179
-
180
-
181
  generate_btn = gr.Button(
182
  "🎬 Generate Video",
183
  variant="primary",
@@ -214,18 +231,21 @@ with gr.Blocks(
214
  """
215
  )
216
 
217
- # Event handlers
218
  generate_btn.click(
219
- fn=generate_video,
220
  inputs=[image_input, prompt_input],
221
  outputs=[video_output],
222
- api_name="generate_video",
 
 
223
  )
224
 
225
  clear_btn.click(
226
- fn=lambda: (None, "The subject starts to move naturally", None),
227
  inputs=None,
228
  outputs=[image_input, prompt_input, video_output],
 
229
  )
230
 
231
  gr.Markdown(
@@ -234,9 +254,10 @@ with gr.Blocks(
234
 
235
  ### 🚀 How it works
236
 
237
- 1. **Upload** your image - any photo or illustration
238
- 2. **Describe** the motion you want to see in the prompt
239
- 3. **Generate** and watch your image come to life!
 
240
 
241
  ### ⚠️ Notes
242
 
@@ -257,4 +278,8 @@ with gr.Blocks(
257
 
258
  # Launch the app
259
  if __name__ == "__main__":
260
- demo.launch()
 
 
 
 
 
11
  bill_to="huggingface",
12
  )
13
 
14
+ def generate_video_with_auth(image, prompt, profile: gr.OAuthProfile | None, progress=gr.Progress()):
15
  """
16
+ Generate a video from an image using the Ovi model with authentication check.
17
 
18
  Args:
19
  image: Input image (PIL Image or file path)
20
  prompt: Text prompt describing the desired motion/animation
21
+ profile: OAuth profile for authentication
22
  progress: Gradio progress tracker
23
 
24
  Returns:
25
  Path to the generated video file
26
  """
27
+ if profile is None:
28
+ raise gr.Error("Click Sign in with Hugging Face button to use this app for free")
29
+
30
  if image is None:
31
  raise gr.Error("Please upload an image first!")
32
 
 
110
  margin: 1em 0;
111
  border-radius: 4px;
112
  }
113
+ .auth-warning {
114
+ color: #ff6b00;
115
+ font-weight: bold;
116
+ text-align: center;
117
+ margin: 1em 0;
118
+ }
119
  """,
120
+ title="Image to Video Generator with Ovi",
121
  ) as demo:
122
 
123
  gr.HTML(
 
140
  """
141
  )
142
 
143
+ gr.HTML(
144
+ """
145
+ <div class="auth-warning">
146
+ ⚠️ You must Sign in with Hugging Face using the button below to use this app.
147
+ </div>
148
+ """
149
+ )
150
+
151
+ # Add login button - required for OAuth
152
+ gr.LoginButton()
153
+
154
  gr.HTML(
155
  """
156
  <div class="info-box">
 
192
 
193
  prompt_input = gr.Textbox(
194
  label="✍️ Text Prompt",
 
195
  lines=3,
 
196
  )
197
 
 
 
198
  generate_btn = gr.Button(
199
  "🎬 Generate Video",
200
  variant="primary",
 
231
  """
232
  )
233
 
234
+ # Event handlers with authentication
235
  generate_btn.click(
236
+ fn=generate_video_with_auth,
237
  inputs=[image_input, prompt_input],
238
  outputs=[video_output],
239
+ queue=False,
240
+ api_name=False,
241
+ show_api=False,
242
  )
243
 
244
  clear_btn.click(
245
+ fn=lambda: (None, "", None),
246
  inputs=None,
247
  outputs=[image_input, prompt_input, video_output],
248
+ queue=False,
249
  )
250
 
251
  gr.Markdown(
 
254
 
255
  ### 🚀 How it works
256
 
257
+ 1. **Sign in** with your Hugging Face account
258
+ 2. **Upload** your image - any photo or illustration
259
+ 3. **Describe** the motion you want to see in the prompt
260
+ 4. **Generate** and watch your image come to life!
261
 
262
  ### ⚠️ Notes
263
 
 
278
 
279
  # Launch the app
280
  if __name__ == "__main__":
281
+ demo.launch(
282
+ show_api=False,
283
+ enable_monitoring=False,
284
+ quiet=True,
285
+ )