Make the result different at each run

#12
Files changed (1) hide show
  1. app.py +5 -0
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import torch
2
  import torchaudio
 
3
  from einops import rearrange
4
  import gradio as gr
5
  import spaces
@@ -20,6 +21,10 @@ def load_model():
20
  # Function to set up, generate, and process the audio
21
  @spaces.GPU(duration=120) # Allocate GPU only when this function is called
22
  def generate_audio(prompt, seconds_total=30, steps=100, cfg_scale=7):
 
 
 
 
23
  print(f"Prompt received: {prompt}")
24
  print(f"Settings: Duration={seconds_total}s, Steps={steps}, CFG Scale={cfg_scale}")
25
 
 
1
  import torch
2
  import torchaudio
3
+ import random
4
  from einops import rearrange
5
  import gradio as gr
6
  import spaces
 
21
  # Function to set up, generate, and process the audio
22
  @spaces.GPU(duration=120) # Allocate GPU only when this function is called
23
  def generate_audio(prompt, seconds_total=30, steps=100, cfg_scale=7):
24
+ seed = random.randint(0, 2**63 - 1)
25
+ random.seed(seed)
26
+ torch.manual_seed(seed)
27
+
28
  print(f"Prompt received: {prompt}")
29
  print(f"Settings: Duration={seconds_total}s, Steps={steps}, CFG Scale={cfg_scale}")
30