Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -133,29 +133,41 @@ def arabic_sentiment_analysis(text):
|
|
133 |
return "neutral"
|
134 |
|
135 |
def tts_interface(text_input, speaker_audio):
|
136 |
-
|
|
|
|
|
|
|
|
|
|
|
137 |
return "Error: TTS model failed to load. Check the logs."
|
138 |
if speaker_audio is None:
|
|
|
139 |
return "Error: Please upload a reference audio."
|
140 |
|
141 |
language = detect_language_safely(text_input)
|
142 |
emotion = "neutral"
|
143 |
audio_output_path = "output.wav"
|
|
|
144 |
|
145 |
if sentiment_analyzer is not None:
|
146 |
try:
|
|
|
147 |
if language == "en":
|
148 |
sentiment_result = sentiment_analyzer(text_input)[0]
|
149 |
emotion = map_sentiment_to_emotion(sentiment_result["label"])
|
|
|
150 |
else:
|
151 |
sentiment_result = arabic_sentiment_analysis(text_input)
|
152 |
emotion = map_sentiment_to_emotion(sentiment_result, language="ar")
|
|
|
153 |
except Exception as e:
|
154 |
print(f"Error during sentiment analysis: {e}")
|
155 |
pass
|
|
|
|
|
156 |
|
157 |
try:
|
158 |
-
|
159 |
model.tts_to_file(
|
160 |
text=text_input,
|
161 |
file_path=audio_output_path,
|
@@ -163,8 +175,10 @@ def tts_interface(text_input, speaker_audio):
|
|
163 |
speaker_wav=speaker_audio,
|
164 |
language=language
|
165 |
)
|
|
|
166 |
return audio_output_path
|
167 |
except Exception as e:
|
|
|
168 |
return f"Error during TTS: {e}"
|
169 |
|
170 |
iface = gr.Interface(
|
|
|
133 |
return "neutral"
|
134 |
|
135 |
def tts_interface(text_input, speaker_audio):
|
136 |
+
print("--- tts_interface function called ---")
|
137 |
+
print(f"Text Input: {text_input}")
|
138 |
+
print(f"Speaker Audio Path: {speaker_audio}")
|
139 |
+
|
140 |
+
if model is None:
|
141 |
+
print("Error: TTS model failed to load.")
|
142 |
return "Error: TTS model failed to load. Check the logs."
|
143 |
if speaker_audio is None:
|
144 |
+
print("Error: Please upload a reference audio.")
|
145 |
return "Error: Please upload a reference audio."
|
146 |
|
147 |
language = detect_language_safely(text_input)
|
148 |
emotion = "neutral"
|
149 |
audio_output_path = "output.wav"
|
150 |
+
print(f"Detected Language: {language}")
|
151 |
|
152 |
if sentiment_analyzer is not None:
|
153 |
try:
|
154 |
+
print("Performing sentiment analysis...")
|
155 |
if language == "en":
|
156 |
sentiment_result = sentiment_analyzer(text_input)[0]
|
157 |
emotion = map_sentiment_to_emotion(sentiment_result["label"])
|
158 |
+
print(f"English Sentiment: {sentiment_result}, Emotion: {emotion}")
|
159 |
else:
|
160 |
sentiment_result = arabic_sentiment_analysis(text_input)
|
161 |
emotion = map_sentiment_to_emotion(sentiment_result, language="ar")
|
162 |
+
print(f"Arabic Sentiment: {sentiment_result}, Emotion: {emotion}")
|
163 |
except Exception as e:
|
164 |
print(f"Error during sentiment analysis: {e}")
|
165 |
pass
|
166 |
+
else:
|
167 |
+
print("Sentiment analyzer not loaded.")
|
168 |
|
169 |
try:
|
170 |
+
print("Attempting to generate audio...")
|
171 |
model.tts_to_file(
|
172 |
text=text_input,
|
173 |
file_path=audio_output_path,
|
|
|
175 |
speaker_wav=speaker_audio,
|
176 |
language=language
|
177 |
)
|
178 |
+
print(f"Audio generated and saved to: {audio_output_path}")
|
179 |
return audio_output_path
|
180 |
except Exception as e:
|
181 |
+
print(f"Error during TTS: {e}")
|
182 |
return f"Error during TTS: {e}"
|
183 |
|
184 |
iface = gr.Interface(
|