deepgram / deepgram-python-sdk

Official Python SDK for Deepgram's automated speech recognition APIs.
https://developers.deepgram.com
MIT License
179 stars 48 forks source link

[Playground] detect_topics not working with transcribe_file #280

Closed SantiDianaClibrain closed 4 months ago

SantiDianaClibrain commented 5 months ago

The flag detect_topics is set to True in PrerecordedOptions but it is not found in alternatives.

with open(filepath, 'rb') as file:
    content = file.read()

payload: FileSource = {
    "buffer": content,
}
try:
        deepgram = DeepgramClient(api_key=DEEPGRAM_API_KEY)

        # STEP 2: Call the transcribe_url method on the prerecorded class
        options = PrerecordedOptions(
            smart_format=True,
            model="nova-2",
            diarize=False,
            language="en",
            punctuate=True,
            detect_entities=True,
            detect_topics=True,
            topics=True,
            summarize=True,
        )
        result = deepgram.listen.prerecorded.v("1").transcribe_file(payload, options)

To be able to detect topics:

topics = result.results.channels[0].alternatives[0].topics[0].topics

Python SDK

dvonthenen commented 5 months ago

Hi @SantiDianaClibrain

You can find topics are off the result object: https://github.com/deepgram/deepgram-python-sdk/blob/main/deepgram/clients/prerecorded/v1/response.py#L533-L534

and metadata object: https://github.com/deepgram/deepgram-python-sdk/blob/main/deepgram/clients/prerecorded/v1/response.py#L109-L111

dvonthenen commented 4 months ago

@SantiDianaClibrain were you able to get this working?

dvonthenen commented 4 months ago

Closing issue since not getting a response. Please reopen if you want to revisit the issue.

roperi commented 4 months ago

Still not working when detect_topics=True.

Why do you say topics are off, @dvonthenen ? Do we need to manually edit the metadata.py and response.py to make it work ?

dvonthenen commented 4 months ago

No, there shouldn't be any need to to manually edit anything.

Can you verify this works for you? https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/prerecorded/topic/main.py

After you run this, can you take note of where the topics are in the result. They are located at: topics = result.results.topics

roperi commented 4 months ago

No, there shouldn't be any need to to manually edit anything.

Can you verify this works for you? https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/prerecorded/topic/main.py

After you run this, can you take note of where the topics are in the result. They are located at: topics = result.results.topics

No, I haven't. But i just had a quick glance. The option is topics=True. In the Deepgram documentation it says it should be detect_topics=True. Maybe this is the problem. I'll check now.

roperi commented 4 months ago

That was it. It works now. But to clarify: It wasn't in the docs where I saw detect_topics=True but in the Playground's Python snippet. There you have the following:

# https://playground.deepgram.com/?summarize=v2&detect_topics=true&smart_format=true&diarize=true&language=en&model=nova-2&file=FILE
def main(): 
  try: 
    deepgram = DeepgramClient(DEEPGRAM_API_KEY) 

    options = PrerecordedOptions(
      model="nova-2", 
      language="en", 
      summarize="v2", 
      detect_topics=True, 
      smart_format=True, 
      diarize=True, 
    ) 

As you can see @SantiDianaClibrain also used the detect_topics=True flag.

dvonthenen commented 4 months ago

yea, that shouldn't be there. will remove that. thanks for point that out.

dvonthenen commented 4 months ago

This update has been submitted for review.

dvonthenen commented 4 months ago

Looks like there is another effort to fix this in the playground. Closing this issue out for now.