jujutech commited on
Commit
01c0e26
·
verified ·
1 Parent(s): 59f0d90

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -0
app.py CHANGED
@@ -1,4 +1,5 @@
1
  import gradio as gr
 
2
  from transformers import Wav2Vec2Processor, Wav2Vec2ForCTC
3
  import torch
4
  import librosa
@@ -8,6 +9,8 @@ processor = Wav2Vec2Processor.from_pretrained("facebook/wav2vec2-large-960h")
8
  model = Wav2Vec2ForCTC.from_pretrained("facebook/wav2vec2-large-960h")
9
 
10
  def transcribe_speech(audio_path):
 
 
11
  speech, _ = librosa.load(audio_path, sr=16000)
12
  input_values = processor(speech, return_tensors="pt", padding="longest").input_values
13
  with torch.no_grad():
@@ -17,6 +20,8 @@ def transcribe_speech(audio_path):
17
  return transcription[0]
18
 
19
  def get_dreamtalk(image_in, speech):
 
 
20
  try:
21
  client = Client("https://fffiloni-dreamtalk.hf.space/")
22
  result = client.predict(
@@ -31,6 +36,8 @@ def get_dreamtalk(image_in, speech):
31
  raise gr.Error(f"Error in get_dreamtalk: {str(e)}")
32
 
33
  def pipe(text, voice, image_in):
 
 
34
  try:
35
  speech = transcribe_speech(voice)
36
  video = get_dreamtalk(image_in, speech)
 
1
  import gradio as gr
2
+ from gradio_client import Client
3
  from transformers import Wav2Vec2Processor, Wav2Vec2ForCTC
4
  import torch
5
  import librosa
 
9
  model = Wav2Vec2ForCTC.from_pretrained("facebook/wav2vec2-large-960h")
10
 
11
  def transcribe_speech(audio_path):
12
+ if audio_path is None:
13
+ raise gr.Error("No audio file provided.")
14
  speech, _ = librosa.load(audio_path, sr=16000)
15
  input_values = processor(speech, return_tensors="pt", padding="longest").input_values
16
  with torch.no_grad():
 
20
  return transcription[0]
21
 
22
  def get_dreamtalk(image_in, speech):
23
+ if image_in is None or speech is None:
24
+ raise gr.Error("Image or speech input is missing.")
25
  try:
26
  client = Client("https://fffiloni-dreamtalk.hf.space/")
27
  result = client.predict(
 
36
  raise gr.Error(f"Error in get_dreamtalk: {str(e)}")
37
 
38
  def pipe(text, voice, image_in):
39
+ if text is None or voice is None or image_in is None:
40
+ raise gr.Error("All inputs (text, voice, image) are required.")
41
  try:
42
  speech = transcribe_speech(voice)
43
  video = get_dreamtalk(image_in, speech)