Aei7n commited on
Commit
4b21b3d
·
verified ·
1 Parent(s): f36632c

requirements.txt

Browse files

gradio
huggingface_hub

Files changed (1) hide show
  1. app.py +16 -35
app.py CHANGED
@@ -1,55 +1,36 @@
1
  import gradio as gr
2
- import cv2
3
- import numpy as np
4
  import os
 
5
 
6
- os.makedirs("outputs", exist_ok=True)
7
-
8
- def motion_transfer(image, video):
9
-
10
- if image is None or video is None:
11
- return None
12
 
13
- img = cv2.imread(image)
14
- cap = cv2.VideoCapture(video)
15
-
16
- width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
17
- height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
18
- fps = cap.get(cv2.CAP_PROP_FPS)
19
 
20
- img = cv2.resize(img, (width, height))
21
 
22
  output_path = "outputs/result.mp4"
23
 
24
- fourcc = cv2.VideoWriter_fourcc(*'mp4v')
25
- out = cv2.VideoWriter(output_path, fourcc, fps, (width, height))
26
-
27
- while True:
28
-
29
- ret, frame = cap.read()
30
-
31
- if not ret:
32
- break
33
-
34
- blended = cv2.addWeighted(img, 0.7, frame, 0.3, 0)
35
-
36
- out.write(blended)
37
 
38
- cap.release()
39
- out.release()
40
 
41
  return output_path
42
 
43
 
44
  app = gr.Interface(
45
- fn=motion_transfer,
46
  inputs=[
47
  gr.Image(type="filepath", label="Upload Image"),
48
- gr.Video(label="Upload Motion Video")
49
  ],
50
- outputs=gr.Video(label="Generated Video"),
51
- title="Motion Control AI FREE",
52
- description="Upload image and motion video"
53
  )
54
 
55
  app.launch()
 
1
  import gradio as gr
 
 
2
  import os
3
+ from huggingface_hub import InferenceClient
4
 
5
+ client = InferenceClient("akhaliq/animate-anyone")
 
 
 
 
 
6
 
7
+ os.makedirs("outputs", exist_ok=True)
 
 
 
 
 
8
 
9
+ def animate(image, video):
10
 
11
  output_path = "outputs/result.mp4"
12
 
13
+ result = client.text_to_video(
14
+ prompt="person moving naturally",
15
+ image=image,
16
+ video=video
17
+ )
 
 
 
 
 
 
 
 
18
 
19
+ with open(output_path, "wb") as f:
20
+ f.write(result)
21
 
22
  return output_path
23
 
24
 
25
  app = gr.Interface(
26
+ fn=animate,
27
  inputs=[
28
  gr.Image(type="filepath", label="Upload Image"),
29
+ gr.Video(label="Upload Motion Reference Video")
30
  ],
31
+ outputs=gr.Video(label="Generated Motion Video"),
32
+ title="Motion Control AI",
33
+ description="Animate image using motion reference video"
34
  )
35
 
36
  app.launch()