SetuG commited on
Commit
7999d51
·
verified ·
1 Parent(s): 53017b5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -16
app.py CHANGED
@@ -8,6 +8,16 @@ from huggingface_hub import snapshot_download
8
  def get_source_image(image):
9
  return image
10
 
 
 
 
 
 
 
 
 
 
 
11
  try:
12
  import webui # in webui
13
  in_webui = True
@@ -50,12 +60,12 @@ def sadtalker_demo():
50
  <br/><b>Alternatively, try our GitHub <a href=https://github.com/Winfredy/SadTalker> code </a> on your own GPU. </b> <a style='display:inline-block' href="https://github.com/Winfredy/SadTalker"><img src="https://img.shields.io/github/stars/Winfredy/SadTalker?style=social"/></a> \
51
  """)
52
 
53
- with gr.Row(): #.style(equal_height=False):
54
  with gr.Column(variant='panel'):
55
  with gr.Tabs(elem_id="sadtalker_source_image"):
56
  with gr.TabItem('Source image'):
57
  with gr.Row():
58
- source_image = gr.Image(label="Source image", sources=["upload"], type="filepath", elem_id="img2img_image") # .style(width=512)
59
 
60
 
61
  with gr.Tabs(elem_id="sadtalker_driven_audio"):
@@ -63,22 +73,22 @@ def sadtalker_demo():
63
  gr.Markdown("Possible driving combinations: <br> 1. Audio only 2. Audio/IDLE Mode + Ref Video(pose, blink, pose+blink) 3. IDLE Mode only 4. Ref Video only (all) ")
64
 
65
  with gr.Row():
66
- driven_audio = gr.Audio(label="Input audio", sources=["upload"])
67
- driven_audio_no = gr.Audio(label="Use IDLE mode, no audio is required", sources=["upload"], visible=False)
68
 
69
  with gr.Column():
70
  use_idle_mode = gr.Checkbox(label="Use Idle Animation")
71
  length_of_audio = gr.Number(value=5, label="The length(seconds) of the generated video.")
72
- use_idle_mode.change(toggle_audio_file, inputs=use_idle_mode, outputs=[driven_audio, driven_audio_no]) # todo
73
 
74
  with gr.Row():
75
- ref_video = gr.Video(label="Reference Video", sources=["upload"], elem_id="vidref") # .style(width=512)
76
 
77
  with gr.Column():
78
  use_ref_video = gr.Checkbox(label="Use Reference Video")
79
  ref_info = gr.Radio(['pose', 'blink','pose+blink', 'all'], value='pose', label='Reference Video',info="How to borrow from reference Video?((fully transfer, aka, video driving mode))")
80
 
81
- ref_video.change(ref_video_fn, inputs=ref_video, outputs=[use_ref_video]) # todo
82
 
83
 
84
  with gr.Column(variant='panel'):
@@ -86,15 +96,13 @@ def sadtalker_demo():
86
  with gr.TabItem('Settings'):
87
  gr.Markdown("need help? please visit our [[best practice page](https://github.com/OpenTalker/SadTalker/blob/main/docs/best_practice.md)] for more detials")
88
  with gr.Column(variant='panel'):
89
- # width = gr.Slider(minimum=64, elem_id="img2img_width", maximum=2048, step=8, label="Manually Crop Width", value=512) # img2img_width
90
- # height = gr.Slider(minimum=64, elem_id="img2img_height", maximum=2048, step=8, label="Manually Crop Height", value=512) # img2img_width
91
  with gr.Row():
92
- pose_style = gr.Slider(minimum=0, maximum=45, step=1, label="Pose style", value=0) #
93
- exp_weight = gr.Slider(minimum=0, maximum=3, step=0.1, label="expression scale", value=1) #
94
  blink_every = gr.Checkbox(label="use eye blink", value=True)
95
 
96
  with gr.Row():
97
- size_of_image = gr.Radio([256, 512], value=256, label='face model resolution', info="use 256/512 model?") #
98
  preprocess_type = gr.Radio(['crop', 'resize','full', 'extcrop', 'extfull'], value='crop', label='preprocess', info="How to handle input image?")
99
 
100
  with gr.Row():
@@ -108,7 +116,7 @@ def sadtalker_demo():
108
  submit = gr.Button('Generate', elem_id="sadtalker_generate", variant='primary')
109
 
110
  with gr.Tabs(elem_id="sadtalker_genearted"):
111
- gen_video = gr.Video(label="Generated video", format="mp4", scale=1) # .style(width=256)
112
 
113
 
114
 
@@ -209,7 +217,7 @@ def sadtalker_demo():
209
  enhancer],
210
  outputs=[gen_video],
211
  fn=sad_talker.test,
212
- cache_examples=False) #
213
 
214
  return sadtalker_interface
215
 
@@ -217,5 +225,5 @@ def sadtalker_demo():
217
  if __name__ == "__main__":
218
 
219
  demo = sadtalker_demo()
220
- demo.queue(max_size=10)
221
- demo.launch(server_name="0.0.0.0", server_port=7860)
 
8
  def get_source_image(image):
9
  return image
10
 
11
+ def preprocess_audio(audio):
12
+ """Handle audio input - extract filepath if it's a tuple"""
13
+ if audio is None:
14
+ return None
15
+ if isinstance(audio, tuple):
16
+ # If it's a tuple (sample_rate, data), return None or handle differently
17
+ # For file upload, we need the actual file path
18
+ return audio[1] if len(audio) > 1 else audio[0]
19
+ return audio
20
+
21
  try:
22
  import webui # in webui
23
  in_webui = True
 
60
  <br/><b>Alternatively, try our GitHub <a href=https://github.com/Winfredy/SadTalker> code </a> on your own GPU. </b> <a style='display:inline-block' href="https://github.com/Winfredy/SadTalker"><img src="https://img.shields.io/github/stars/Winfredy/SadTalker?style=social"/></a> \
61
  """)
62
 
63
+ with gr.Row():
64
  with gr.Column(variant='panel'):
65
  with gr.Tabs(elem_id="sadtalker_source_image"):
66
  with gr.TabItem('Source image'):
67
  with gr.Row():
68
+ source_image = gr.Image(label="Source image", source="upload", type="filepath", elem_id="img2img_image")
69
 
70
 
71
  with gr.Tabs(elem_id="sadtalker_driven_audio"):
 
73
  gr.Markdown("Possible driving combinations: <br> 1. Audio only 2. Audio/IDLE Mode + Ref Video(pose, blink, pose+blink) 3. IDLE Mode only 4. Ref Video only (all) ")
74
 
75
  with gr.Row():
76
+ driven_audio = gr.Audio(label="Input audio", source="upload", type="filepath", format="wav")
77
+ driven_audio_no = gr.Audio(label="Use IDLE mode, no audio is required", source="upload", type="filepath", format="wav", visible=False)
78
 
79
  with gr.Column():
80
  use_idle_mode = gr.Checkbox(label="Use Idle Animation")
81
  length_of_audio = gr.Number(value=5, label="The length(seconds) of the generated video.")
82
+ use_idle_mode.change(toggle_audio_file, inputs=use_idle_mode, outputs=[driven_audio, driven_audio_no])
83
 
84
  with gr.Row():
85
+ ref_video = gr.Video(label="Reference Video", source="upload", type="filepath", elem_id="vidref")
86
 
87
  with gr.Column():
88
  use_ref_video = gr.Checkbox(label="Use Reference Video")
89
  ref_info = gr.Radio(['pose', 'blink','pose+blink', 'all'], value='pose', label='Reference Video',info="How to borrow from reference Video?((fully transfer, aka, video driving mode))")
90
 
91
+ ref_video.change(ref_video_fn, inputs=ref_video, outputs=[use_ref_video])
92
 
93
 
94
  with gr.Column(variant='panel'):
 
96
  with gr.TabItem('Settings'):
97
  gr.Markdown("need help? please visit our [[best practice page](https://github.com/OpenTalker/SadTalker/blob/main/docs/best_practice.md)] for more detials")
98
  with gr.Column(variant='panel'):
 
 
99
  with gr.Row():
100
+ pose_style = gr.Slider(minimum=0, maximum=45, step=1, label="Pose style", value=0)
101
+ exp_weight = gr.Slider(minimum=0, maximum=3, step=0.1, label="expression scale", value=1)
102
  blink_every = gr.Checkbox(label="use eye blink", value=True)
103
 
104
  with gr.Row():
105
+ size_of_image = gr.Radio([256, 512], value=256, label='face model resolution', info="use 256/512 model?")
106
  preprocess_type = gr.Radio(['crop', 'resize','full', 'extcrop', 'extfull'], value='crop', label='preprocess', info="How to handle input image?")
107
 
108
  with gr.Row():
 
116
  submit = gr.Button('Generate', elem_id="sadtalker_generate", variant='primary')
117
 
118
  with gr.Tabs(elem_id="sadtalker_genearted"):
119
+ gen_video = gr.Video(label="Generated video", format="mp4")
120
 
121
 
122
 
 
217
  enhancer],
218
  outputs=[gen_video],
219
  fn=sad_talker.test,
220
+ cache_examples=os.getenv('SYSTEM') == 'spaces')
221
 
222
  return sadtalker_interface
223
 
 
225
  if __name__ == "__main__":
226
 
227
  demo = sadtalker_demo()
228
+ demo.queue()
229
+ demo.launch()