Spaces:
Running
Running
Commit
·
78a8026
1
Parent(s):
7e5f9d1
Update app.py
Browse files
app.py
CHANGED
@@ -65,8 +65,26 @@ def process_text(uploaded_file):
|
|
65 |
)
|
66 |
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
# Convert summary to speech
|
69 |
-
speech = synthesiser(
|
70 |
audio_data = speech["audio"].squeeze()
|
71 |
normalized_audio_data = np.int16(audio_data / np.max(np.abs(audio_data)) * 32767)
|
72 |
|
@@ -74,7 +92,7 @@ def process_text(uploaded_file):
|
|
74 |
output_file = "temp_output.wav"
|
75 |
scipy.io.wavfile.write(output_file, rate=speech["sampling_rate"], data=normalized_audio_data)
|
76 |
|
77 |
-
return
|
78 |
except Exception as e:
|
79 |
logging.error(f"Error in summary generation or TTS conversion: {e}")
|
80 |
return "Error in summary or speech generation", None
|
@@ -88,4 +106,4 @@ iface = gr.Interface(
|
|
88 |
)
|
89 |
|
90 |
if __name__ == "__main__":
|
91 |
-
iface.launch()
|
|
|
65 |
)
|
66 |
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
67 |
|
68 |
+
# Post-process the summary
|
69 |
+
words = summary.split()
|
70 |
+
cleaned_summary = []
|
71 |
+
for i, word in enumerate(words):
|
72 |
+
if '-' in word and i < len(words) - 1:
|
73 |
+
word = word.replace('-', '') + words[i + 1]
|
74 |
+
words[i + 1] = ""
|
75 |
+
|
76 |
+
if '.' in word and i != len(words) - 1:
|
77 |
+
word = word.replace('.', '')
|
78 |
+
cleaned_summary.append(word + ' and')
|
79 |
+
else:
|
80 |
+
cleaned_summary.append(word)
|
81 |
+
|
82 |
+
final_summary = ' '.join(cleaned_summary)
|
83 |
+
final_summary = final_summary[0].upper() + final_summary[1:]
|
84 |
+
final_summary = ' '.join(w[0].lower() + w[1:] if w.lower() != 'and' else w for w in final_summary.split())
|
85 |
+
|
86 |
# Convert summary to speech
|
87 |
+
speech = synthesiser(final_summary, forward_params={"do_sample": True})
|
88 |
audio_data = speech["audio"].squeeze()
|
89 |
normalized_audio_data = np.int16(audio_data / np.max(np.abs(audio_data)) * 32767)
|
90 |
|
|
|
92 |
output_file = "temp_output.wav"
|
93 |
scipy.io.wavfile.write(output_file, rate=speech["sampling_rate"], data=normalized_audio_data)
|
94 |
|
95 |
+
return final_summary, output_file
|
96 |
except Exception as e:
|
97 |
logging.error(f"Error in summary generation or TTS conversion: {e}")
|
98 |
return "Error in summary or speech generation", None
|
|
|
106 |
)
|
107 |
|
108 |
if __name__ == "__main__":
|
109 |
+
iface.launch()
|