Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -42,24 +42,32 @@ def transcribe(audio_file):
|
|
| 42 |
def generate_text(prompt):
|
| 43 |
# formatted_prompt = format_prompt(prompt) # Removed
|
| 44 |
# response = client.text_generation(formatted_prompt, max_new_tokens=250, temperature=0.7, top_p=0.95) # Removed
|
|
|
|
| 45 |
result = llm_client.predict(query=prompt, api_name="/chat") # Added
|
|
|
|
| 46 |
return result.strip() # Modified to return the result from the Gradio Client
|
| 47 |
|
| 48 |
# TTS Function
|
| 49 |
def text_to_speech(text):
|
|
|
|
| 50 |
lang = detect(text)
|
| 51 |
wav_path = "./output.wav"
|
| 52 |
if lang == "sw":
|
| 53 |
swahili_tts.synthesis(text, wav_path=wav_path)
|
| 54 |
else:
|
| 55 |
english_tts.synthesis(text, wav_path=wav_path)
|
|
|
|
| 56 |
return wav_path
|
| 57 |
|
| 58 |
# Combined Processing Function
|
| 59 |
def process_audio(audio):
|
|
|
|
| 60 |
transcription = transcribe(audio)
|
|
|
|
| 61 |
generated_text = generate_text(transcription)
|
|
|
|
| 62 |
speech = text_to_speech(generated_text)
|
|
|
|
| 63 |
return transcription, generated_text, speech
|
| 64 |
|
| 65 |
# Gradio Interface
|
|
|
|
| 42 |
def generate_text(prompt):
|
| 43 |
# formatted_prompt = format_prompt(prompt) # Removed
|
| 44 |
# response = client.text_generation(formatted_prompt, max_new_tokens=250, temperature=0.7, top_p=0.95) # Removed
|
| 45 |
+
print(f"Generating text for prompt (type: {type(prompt)}): {prompt}") # Debug print
|
| 46 |
result = llm_client.predict(query=prompt, api_name="/chat") # Added
|
| 47 |
+
print(f"Generated text result (type: {type(result)}): {result}") # Debug print
|
| 48 |
return result.strip() # Modified to return the result from the Gradio Client
|
| 49 |
|
| 50 |
# TTS Function
|
| 51 |
def text_to_speech(text):
|
| 52 |
+
print(f"Converting text to speech (type: {type(text)}): {text}") # Debug print
|
| 53 |
lang = detect(text)
|
| 54 |
wav_path = "./output.wav"
|
| 55 |
if lang == "sw":
|
| 56 |
swahili_tts.synthesis(text, wav_path=wav_path)
|
| 57 |
else:
|
| 58 |
english_tts.synthesis(text, wav_path=wav_path)
|
| 59 |
+
print(f"TTS output path (type: {type(wav_path)}): {wav_path}") # Debug print
|
| 60 |
return wav_path
|
| 61 |
|
| 62 |
# Combined Processing Function
|
| 63 |
def process_audio(audio):
|
| 64 |
+
print(f"Processing audio file (type: {type(audio)}): {audio}") # Debug print
|
| 65 |
transcription = transcribe(audio)
|
| 66 |
+
print(f"Transcription result (type: {type(transcription)}): {transcription}") # Debug print
|
| 67 |
generated_text = generate_text(transcription)
|
| 68 |
+
print(f"Generated text after function call (type: {type(generated_text)}): {generated_text}") # Debug print
|
| 69 |
speech = text_to_speech(generated_text)
|
| 70 |
+
print(f"Speech output after function call (type: {type(speech)}): {speech}") # Debug print
|
| 71 |
return transcription, generated_text, speech
|
| 72 |
|
| 73 |
# Gradio Interface
|