Skip to content

Commit

Permalink
Merge pull request #244 from dvonthenen/fix-missing-values-after-audit
Browse files Browse the repository at this point in the history
Fix Missing Values After Audit
  • Loading branch information
davidvonthenen authored Jan 4, 2024
2 parents 38b57b5 + 8363a5c commit 66b8e4a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 29 deletions.
32 changes: 11 additions & 21 deletions deepgram/clients/prerecorded/v1/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def __getitem__(self, key):

@dataclass_json
@dataclass
class SummaryV2:
class SummaryV1:
summary: Optional[str] = ""
start_word: Optional[float] = 0
end_word: Optional[float] = 0
Expand All @@ -92,19 +92,13 @@ def __getitem__(self, key):

@dataclass_json
@dataclass
class Summaries(SummaryV2): # internal reference to old name
summary: Optional[str] = ""
start_word: Optional[float] = 0
end_word: Optional[float] = 0

def __getitem__(self, key):
_dict = self.to_dict()
return _dict[key]
class Summaries(SummaryV1): # internal reference to old name
pass


@dataclass_json
@dataclass
class Summary:
class SummaryV2:
result: Optional[str] = ""
short: Optional[str] = ""

Expand All @@ -115,13 +109,8 @@ def __getitem__(self, key):

@dataclass_json
@dataclass
class Summary(Summary): # internal reference to old name
result: Optional[str] = ""
short: Optional[str] = ""

def __getitem__(self, key):
_dict = self.to_dict()
return _dict[key]
class Summary(SummaryV2): # internal reference to old name
pass


@dataclass_json
Expand Down Expand Up @@ -305,7 +294,7 @@ class Alternative:
transcript: Optional[str] = ""
confidence: Optional[float] = 0
words: Optional[List[Word]] = None
summaries: Optional[List[SummaryV2]] = None
summaries: Optional[List[SummaryV1]] = None
paragraphs: Optional[Paragraphs] = None
entities: Optional[List[Entity]] = None
translations: Optional[List[Translation]] = None
Expand All @@ -319,7 +308,7 @@ def __getitem__(self, key):
]
if _dict["summaries"] is not None:
_dict["summaries"] = [
SummaryV2.from_dict(summaries)
SummaryV1.from_dict(summaries)
for _, summaries in _dict["summaries"].items()
]
if _dict["paragraphs"] is not None:
Expand All @@ -346,6 +335,7 @@ class Channel:
search: Optional[List[Search]] = None
alternatives: Optional[List[Alternative]] = None
detected_language: Optional[str] = ""
language_confidence: Optional[float] = 0

def __getitem__(self, key):
_dict = self.to_dict()
Expand All @@ -366,7 +356,7 @@ def __getitem__(self, key):
class Result:
channels: Optional[List[Channel]] = None
utterances: Optional[List[Utterance]] = None
summary: Optional[Summary] = None
summary: Optional[SummaryV2] = None

def __getitem__(self, key):
_dict = self.to_dict()
Expand All @@ -380,7 +370,7 @@ def __getitem__(self, key):
for _, utterances in _dict["utterances"].items()
]
if _dict["summary"] is not None:
_dict["summary"] = Summary.from_dict(_dict["summary"])
_dict["summary"] = SummaryV2.from_dict(_dict["summary"])
return _dict[key]


Expand Down
2 changes: 1 addition & 1 deletion examples/prerecorded/async_url/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async def transcribe_url():
async def main():
try:
response = await transcribe_url()
print(response)
print(response.to_json(indent=4))
except Exception as e:
print(f"Exception: {e}")

Expand Down
8 changes: 3 additions & 5 deletions examples/prerecorded/file/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

AUDIO_FILE = "preamble.wav"


def main():
try:
# STEP 1 Create a Deepgram client using the API key in the environment variables
Expand All @@ -41,11 +42,8 @@ def main():
punctuate=True,
diarize=True,
)
file_response = deepgram.listen.prerecorded.v("1").transcribe_file(payload, options)

print(f"\n\n{file_response}\n\n")
json = file_response.to_json()
print(f"{json}\n")
response = deepgram.listen.prerecorded.v("1").transcribe_file(payload, options)
print(response.to_json(indent=4))

except Exception as e:
print(f"Exception: {e}")
Expand Down
5 changes: 3 additions & 2 deletions examples/prerecorded/url/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"url": "https://static.deepgram.com/examples/Bueller-Life-moves-pretty-fast.wav"
}


def main():
try:
# STEP 1 Create a Deepgram client using the API key from environment variables
Expand All @@ -25,8 +26,8 @@ def main():
smart_format=True,
summarize="v2",
)
url_response = deepgram.listen.prerecorded.v("1").transcribe_url(AUDIO_URL, options)
print(url_response)
response = deepgram.listen.prerecorded.v("1").transcribe_url(AUDIO_URL, options)
print(response.to_json(indent=4))

except Exception as e:
print(f"Exception: {e}")
Expand Down

0 comments on commit 66b8e4a

Please sign in to comment.