jbilcke-hf HF Staff commited on
Commit
ef838a8
·
1 Parent(s): 4204ea9
Files changed (1) hide show
  1. app.py +15 -14
app.py CHANGED
@@ -14,15 +14,13 @@ logger = logging.getLogger(__name__)
14
  # Constants
15
  DEFAULT_CONFIG_PATH = "configs/inference.yaml"
16
  DEFAULT_INPUT_FILE = "examples/infer_samples.txt"
17
- OUTPUT_DIR = Path("demo_out/gradio_outputs")
18
- OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
19
 
20
  def generate_avatar_video(
21
  reference_image,
22
  audio_file,
23
  text_prompt,
24
  seed=42,
25
- num_steps=50,
26
  guidance_scale=4.5,
27
  audio_scale=None,
28
  overlap_frames=13,
@@ -152,15 +150,18 @@ def generate_avatar_video(
152
  # Get the most recent video
153
  latest_video = max(generated_videos, key=lambda p: p.stat().st_mtime)
154
 
155
- # Copy to output directory with unique name
156
- output_filename = f"avatar_video_{os.getpid()}_{torch.randint(1000, 9999, (1,)).item()}.mp4"
157
- output_path = OUTPUT_DIR / output_filename
 
 
 
158
  shutil.copy(latest_video, output_path)
159
 
160
  progress(1.0, desc="Generation complete")
161
- logger.info(f"Video saved to: {output_path}")
162
 
163
- return str(output_path)
164
 
165
  except Exception as e:
166
  logger.error(f"Error generating video: {str(e)}")
@@ -201,25 +202,25 @@ with gr.Blocks(title="OmniAvatar - Lipsynced Avatar Video Generation") as app:
201
  with gr.Row():
202
  seed = gr.Slider(
203
  label="Seed",
204
- minimum=0,
205
  maximum=2147483647,
206
  step=1,
207
- value=42
208
  )
209
 
210
  resolution = gr.Radio(
211
  label="Resolution",
212
  choices=["480p", "720p"],
213
- value="720p"
214
  )
215
 
216
  with gr.Row():
217
  num_steps = gr.Slider(
218
  label="Inference Steps",
219
  minimum=10,
220
- maximum=100,
221
- step=5,
222
- value=50
223
  )
224
 
225
  guidance_scale = gr.Slider(
 
14
  # Constants
15
  DEFAULT_CONFIG_PATH = "configs/inference.yaml"
16
  DEFAULT_INPUT_FILE = "examples/infer_samples.txt"
 
 
17
 
18
  def generate_avatar_video(
19
  reference_image,
20
  audio_file,
21
  text_prompt,
22
  seed=42,
23
+ num_steps=15,
24
  guidance_scale=4.5,
25
  audio_scale=None,
26
  overlap_frames=13,
 
150
  # Get the most recent video
151
  latest_video = max(generated_videos, key=lambda p: p.stat().st_mtime)
152
 
153
+ # Create a temporary file for the output video
154
+ # This file will persist beyond the context manager since we're using delete=False
155
+ with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as tmp_output:
156
+ output_path = tmp_output.name
157
+
158
+ # Copy the generated video to the temporary file
159
  shutil.copy(latest_video, output_path)
160
 
161
  progress(1.0, desc="Generation complete")
162
+ logger.info(f"Video saved to temporary path: {output_path}")
163
 
164
+ return output_path
165
 
166
  except Exception as e:
167
  logger.error(f"Error generating video: {str(e)}")
 
202
  with gr.Row():
203
  seed = gr.Slider(
204
  label="Seed",
205
+ minimum=-1,
206
  maximum=2147483647,
207
  step=1,
208
+ value=-1
209
  )
210
 
211
  resolution = gr.Radio(
212
  label="Resolution",
213
  choices=["480p", "720p"],
214
+ value="480p"
215
  )
216
 
217
  with gr.Row():
218
  num_steps = gr.Slider(
219
  label="Inference Steps",
220
  minimum=10,
221
+ maximum=50,
222
+ step=1,
223
+ value=15
224
  )
225
 
226
  guidance_scale = gr.Slider(