high77 commited on
Commit
ba641e7
·
verified ·
1 Parent(s): 29a7548

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -14
app.py CHANGED
@@ -98,14 +98,8 @@ repo_id = "ai4Bharat/IndicF5"
98
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
99
  model = AutoModel.from_pretrained(repo_id, trust_remote_code=True).to(device)
100
 
101
- # ---------- PRE-FETCH EXAMPLES ----------
102
  EXAMPLES = [
103
- {
104
- "audio_name": "PAN_F (Happy)",
105
- "audio_url": "https://github.com/AI4Bharat/IndicF5/raw/refs/heads/main/prompts/PAN_F_HAPPY_00002.wav",
106
- "ref_text": "ਇੱਕ ਗ੍ਰਾਹਕ ਨੇ ਸਾਡੀ ਬੇਮਿਸਾਲ ਸੇਵਾ ਬਾਰੇ ਦਿਲੋਂਗਵਾਹੀ ਦਿੱਤੀ ਜਿਸ ਨਾਲ ਸਾਨੂੰ ਅਨੰਦ ਮਹਿਸੂਸ ਹੋਇਆ।",
107
- "synth_text": "ମୁଁ ଆପଣଙ୍କୁ ସ୍ୱାଗତ କରିବାକୁ ଚାହୁଁଛି, କେମିତି ଅଛନ୍ତି?"
108
- },
109
  {
110
  "audio_name": "ODIA_F (Neutral)",
111
  "audio_url": "https://github.com/AI4Bharat/IndicF5/raw/refs/heads/main/prompts/ORI_F_WIKI_00001.wav",
@@ -119,16 +113,23 @@ EXAMPLES = [
119
  "synth_text": "ମୁଁ ଆଜି ବହୁତ ଖୁସି ଅଛି କାରଣ ମୋର କାମ ସଫଳ ହୋଇଛି।"
120
  },
121
  {
122
- "audio_name": "TAM_F (Happy)",
123
- "audio_url": "https://github.com/AI4Bharat/IndicF5/raw/refs/heads/main/prompts/TAM_F_HAPPY_00001.wav",
124
- "ref_text": "நான் நெனச்ச மாதிரியே அமேசான்ல பெரிய தள்ளுபடி வந்திருக்கு. கம்மி காசுக்கே அந்தப் புது சேம்சங் மாடல வாங்கிடலாம்.",
125
- "synth_text": "நான் ஒரு புதிய படத்தை பார்த்தேன், அது மிகவும் சிறந்தது."
126
  },
127
  ]
128
 
129
  for ex in EXAMPLES:
130
  sr, data = load_audio_from_url(ex["audio_url"])
131
- ex["sample_rate"], ex["audio_data"] = sr, data
 
 
 
 
 
 
 
132
 
133
  # ---------- GRADIO UI ----------
134
  with gr.Blocks() as iface:
@@ -142,8 +143,8 @@ with gr.Blocks() as iface:
142
  with gr.Column():
143
  out_audio = gr.Audio(label="Generated Speech", type="numpy")
144
 
145
- examples = [[ex["synth_text"], (ex["sample_rate"], ex["audio_data"]), ex["ref_text"]] for ex in EXAMPLES]
146
- gr.Examples(examples=examples, inputs=[text, ref_audio, ref_text], label="Pick an example:")
147
 
148
  btn.click(synthesise_speech, inputs=[text, ref_audio, ref_text], outputs=[out_audio])
149
 
 
98
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
99
  model = AutoModel.from_pretrained(repo_id, trust_remote_code=True).to(device)
100
 
101
+ # ---------- PRE-FETCH EXAMPLES (SAFE FOR GRADIO 4) ----------
102
  EXAMPLES = [
 
 
 
 
 
 
103
  {
104
  "audio_name": "ODIA_F (Neutral)",
105
  "audio_url": "https://github.com/AI4Bharat/IndicF5/raw/refs/heads/main/prompts/ORI_F_WIKI_00001.wav",
 
113
  "synth_text": "ମୁଁ ଆଜି ବହୁତ ଖୁସି ଅଛି କାରଣ ମୋର କାମ ସଫଳ ହୋଇଛି।"
114
  },
115
  {
116
+ "audio_name": "PAN_F (Happy)",
117
+ "audio_url": "https://github.com/AI4Bharat/IndicF5/raw/refs/heads/main/prompts/PAN_F_HAPPY_00002.wav",
118
+ "ref_text": "ਇੱਕ ਗ੍ਰਾਹਕ ਨੇ ਸਾਡੀ ਬੇਮਿਸਾਲ ਸੇਵਾ ਬਾਰੇ ਦਿਲੋਂਗਵਾਹੀ ਦਿੱਤੀ ਜਿਸ ਨਾਲ ਸਾਨੂੰ ਅਨੰਦ ਮਹਿਸੂਸ ਹੋਇਆ।",
119
+ "synth_text": "ମୁଁ ଆପଣଙ୍କୁ ସ୍ୱାଗତ କରିବାକୁ ଚାହୁଁଛି, କେମିତି ଅଛନ୍ତି?"
120
  },
121
  ]
122
 
123
  for ex in EXAMPLES:
124
  sr, data = load_audio_from_url(ex["audio_url"])
125
+ ex["sample_rate"] = sr
126
+ ex["audio_data"] = data if data is not None else np.zeros((1,)) # never None
127
+
128
+ # build Gradio examples list (skip broken downloads)
129
+ examples = []
130
+ for ex in EXAMPLES:
131
+ if ex["audio_data"] is not None:
132
+ examples.append([ex["synth_text"], (ex["sample_rate"], ex["audio_data"]), ex["ref_text"]])
133
 
134
  # ---------- GRADIO UI ----------
135
  with gr.Blocks() as iface:
 
143
  with gr.Column():
144
  out_audio = gr.Audio(label="Generated Speech", type="numpy")
145
 
146
+ if examples: # only show if we have valid ones
147
+ gr.Examples(examples=examples, inputs=[text, ref_audio, ref_text], label="Pick an example:")
148
 
149
  btn.click(synthesise_speech, inputs=[text, ref_audio, ref_text], outputs=[out_audio])
150