akhaliq HF Staff commited on
Commit
5cf4958
Β·
verified Β·
1 Parent(s): 353ba55

Update Gradio app with multiple files

Browse files
Files changed (2) hide show
  1. app.py +43 -7
  2. requirements.txt +14 -0
app.py CHANGED
@@ -12,9 +12,12 @@ client = InferenceClient(
12
  bill_to="huggingface",
13
  )
14
 
15
- def text_to_video(prompt, duration=5, aspect_ratio="16:9", resolution="720p"):
16
  """Generate video from text prompt"""
17
  try:
 
 
 
18
  if not prompt or prompt.strip() == "":
19
  return None, "Please enter a text prompt"
20
 
@@ -34,9 +37,12 @@ def text_to_video(prompt, duration=5, aspect_ratio="16:9", resolution="720p"):
34
  except Exception as e:
35
  return None, f"❌ Error generating video: {str(e)}"
36
 
37
- def image_to_video(image, prompt, duration=5, aspect_ratio="16:9", resolution="720p"):
38
  """Generate video from image and prompt"""
39
  try:
 
 
 
40
  if image is None:
41
  return None, "Please upload an image"
42
 
@@ -109,6 +115,15 @@ custom_css = """
109
  border-radius: 5px;
110
  margin-top: 10px;
111
  }
 
 
 
 
 
 
 
 
 
112
  """
113
 
114
  # Create the Gradio interface
@@ -121,6 +136,17 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Soft(), title="AI Video Generator
121
  """
122
  )
123
 
 
 
 
 
 
 
 
 
 
 
 
124
  with gr.Tabs() as tabs:
125
  # Text-to-Video Tab
126
  with gr.Tab("πŸ“ Text to Video", id=0):
@@ -292,26 +318,34 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Soft(), title="AI Video Generator
292
  fn=text_to_video,
293
  inputs=[text_prompt, text_duration, text_aspect_ratio, text_resolution],
294
  outputs=[text_video_output, text_status],
295
- show_progress="full"
 
 
 
296
  )
297
 
298
  text_clear_btn.click(
299
  fn=clear_text_tab,
300
  inputs=[],
301
- outputs=[text_prompt, text_video_output, text_status]
 
302
  )
303
 
304
  image_generate_btn.click(
305
  fn=image_to_video,
306
  inputs=[image_input, image_prompt, image_duration, image_aspect_ratio, image_resolution],
307
  outputs=[image_video_output, image_status],
308
- show_progress="full"
 
 
 
309
  )
310
 
311
  image_clear_btn.click(
312
  fn=clear_image_tab,
313
  inputs=[],
314
- outputs=[image_input, image_prompt, image_video_output, image_status]
 
315
  )
316
 
317
  # Launch the app
@@ -319,5 +353,7 @@ if __name__ == "__main__":
319
  demo.launch(
320
  show_api=False,
321
  share=False,
322
- show_error=True
 
 
323
  )
 
12
  bill_to="huggingface",
13
  )
14
 
15
+ def text_to_video(prompt, duration=5, aspect_ratio="16:9", resolution="720p", profile: gr.OAuthProfile | None = None):
16
  """Generate video from text prompt"""
17
  try:
18
+ if profile is None:
19
+ return None, "❌ Click Sign in with Hugging Face button to use this app for free"
20
+
21
  if not prompt or prompt.strip() == "":
22
  return None, "Please enter a text prompt"
23
 
 
37
  except Exception as e:
38
  return None, f"❌ Error generating video: {str(e)}"
39
 
40
+ def image_to_video(image, prompt, duration=5, aspect_ratio="16:9", resolution="720p", profile: gr.OAuthProfile | None = None):
41
  """Generate video from image and prompt"""
42
  try:
43
+ if profile is None:
44
+ return None, "❌ Click Sign in with Hugging Face button to use this app for free"
45
+
46
  if image is None:
47
  return None, "Please upload an image"
48
 
 
115
  border-radius: 5px;
116
  margin-top: 10px;
117
  }
118
+ .auth-warning {
119
+ color: #ff6b00;
120
+ font-weight: bold;
121
+ text-align: center;
122
+ margin: 1em 0;
123
+ padding: 1em;
124
+ background-color: #fff3e0;
125
+ border-radius: 5px;
126
+ }
127
  """
128
 
129
  # Create the Gradio interface
 
136
  """
137
  )
138
 
139
+ gr.HTML(
140
+ """
141
+ <div class="auth-warning">
142
+ ⚠️ You must Sign in with Hugging Face using the button below to use this app.
143
+ </div>
144
+ """
145
+ )
146
+
147
+ # Add login button - required for OAuth
148
+ gr.LoginButton()
149
+
150
  with gr.Tabs() as tabs:
151
  # Text-to-Video Tab
152
  with gr.Tab("πŸ“ Text to Video", id=0):
 
318
  fn=text_to_video,
319
  inputs=[text_prompt, text_duration, text_aspect_ratio, text_resolution],
320
  outputs=[text_video_output, text_status],
321
+ show_progress="full",
322
+ queue=False,
323
+ api_name=False,
324
+ show_api=False
325
  )
326
 
327
  text_clear_btn.click(
328
  fn=clear_text_tab,
329
  inputs=[],
330
+ outputs=[text_prompt, text_video_output, text_status],
331
+ queue=False
332
  )
333
 
334
  image_generate_btn.click(
335
  fn=image_to_video,
336
  inputs=[image_input, image_prompt, image_duration, image_aspect_ratio, image_resolution],
337
  outputs=[image_video_output, image_status],
338
+ show_progress="full",
339
+ queue=False,
340
+ api_name=False,
341
+ show_api=False
342
  )
343
 
344
  image_clear_btn.click(
345
  fn=clear_image_tab,
346
  inputs=[],
347
+ outputs=[image_input, image_prompt, image_video_output, image_status],
348
+ queue=False
349
  )
350
 
351
  # Launch the app
 
353
  demo.launch(
354
  show_api=False,
355
  share=False,
356
+ show_error=True,
357
+ enable_monitoring=False,
358
+ quiet=True
359
  )
requirements.txt ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ huggingface-hub
2
+ Pillow
3
+ gradio
4
+ requests
5
+ numpy
6
+ torch
7
+ torchvision
8
+ torchaudio
9
+ accelerate
10
+ tokenizers
11
+ datasets
12
+ sentencepiece
13
+ git+https://github.com/huggingface/transformers
14
+ git+https://github.com/huggingface/diffusers