Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -19,27 +19,6 @@ model.eval() # Set the model to evaluation mode
|
|
19 |
# Initialize the inference client (if needed for other API-based tasks)
|
20 |
client = InferenceClient(token=access_token)
|
21 |
|
22 |
-
|
23 |
-
# Import required modules for E2-F5-TTS
|
24 |
-
from huggingface_hub import Client
|
25 |
-
|
26 |
-
# Initialize the E2-F5-TTS client
|
27 |
-
client_tts = Client("mrfakename/E2-F5-TTS")
|
28 |
-
|
29 |
-
def text_to_speech(text, sample):
|
30 |
-
result = client_tts.predict(
|
31 |
-
ref_audio_input=handle_file(f'input/{sample}.mp3'),
|
32 |
-
ref_text_input="",
|
33 |
-
gen_text_input=text,
|
34 |
-
remove_silence=False,
|
35 |
-
cross_fade_duration_slider=0.15,
|
36 |
-
speed_slider=1,
|
37 |
-
api_name="/basic_tts"
|
38 |
-
)
|
39 |
-
audio_file = open(result[0], "rb")
|
40 |
-
audio_bytes = audio_file.read()
|
41 |
-
return audio_bytes
|
42 |
-
|
43 |
def conversation_predict(input_text):
|
44 |
"""Generate a response for single-turn input using the model."""
|
45 |
# Tokenize the input text
|
@@ -49,12 +28,7 @@ def conversation_predict(input_text):
|
|
49 |
outputs = model.generate(input_ids, max_new_tokens=2048)
|
50 |
|
51 |
# Decode and return the generated response
|
52 |
-
|
53 |
-
|
54 |
-
# Convert the text response to speech using E2-F5-TTS
|
55 |
-
audio_bytes = text_to_speech(response, sample="input")
|
56 |
-
|
57 |
-
return response, audio_bytes
|
58 |
|
59 |
def respond(
|
60 |
message: str,
|
|
|
19 |
# Initialize the inference client (if needed for other API-based tasks)
|
20 |
client = InferenceClient(token=access_token)
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
def conversation_predict(input_text):
|
23 |
"""Generate a response for single-turn input using the model."""
|
24 |
# Tokenize the input text
|
|
|
28 |
outputs = model.generate(input_ids, max_new_tokens=2048)
|
29 |
|
30 |
# Decode and return the generated response
|
31 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
def respond(
|
34 |
message: str,
|