Skip to content

Instantly share code, notes, and snippets.

@SamuelAlgheriniAI
Last active July 2, 2021 08:13
Show Gist options
  • Save SamuelAlgheriniAI/9c49bfac30eabf01da56c5a97b79649b to your computer and use it in GitHub Desktop.
Save SamuelAlgheriniAI/9c49bfac30eabf01da56c5a97b79649b to your computer and use it in GitHub Desktop.
NLU analysis with expert.ai
#NLU Analysis
def text_analysis(transcript, language, audio_report, file, length):
#Keyphrase extraction
print("NLU analysis of " + file + " started.")
client = ExpertAiClient()
output = client.specific_resource_analysis(body={"document": {"text": transcript}},
params={'language': language, 'resource': 'relevants'})
today = date.today()
report = f"REPORT\nFile name: {file}\nDate: {today}" \
f"\nLength: {datetime.timedelta(seconds=round(length,0))}" \
f"\nFile stored at: {os.path.join(audio_report, file)}.txt"
report += "\n\nMAIN LEMMAS:\n"
for lemma in output.main_lemmas:
report += lemma.value + "\n"
report += "\nMAIN PHRASES:\n"
for lemma in output.main_phrases:
report += lemma.value + "\n"
report += '\nMAIN TOPICS:\n'
for n,topic in enumerate(output.topics):
if topic.winner:
report += '#' + topic.label + '\n'
#Write the report to a text file
filepath = os.path.join(audio_report,file)
text = open(filepath + ".txt","w")
text.write(report)
text.close()
print("\nReport stored at " + filepath + ".txt")
return report
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment