chore: remove old non-working code (#484)

This commit is contained in:
2025-07-16 07:47:42 -06:00
committed by GitHub
parent baf2822b81
commit aea8773057
50 changed files with 0 additions and 8448 deletions

View File

@@ -1,204 +0,0 @@
import re
from pathlib import Path
from typing import Any, List
from jiwer import wer
from Levenshtein import distance
from pydantic import BaseModel, Field, field_validator
from tqdm.auto import tqdm
from whisper.normalizers import EnglishTextNormalizer
class EvaluationResult(BaseModel):
"""
Result object of the model evaluation
"""
accuracy: float = Field(default=0.0)
total_test_samples: int = Field(default=0)
class EvaluationTestSample(BaseModel):
"""
Represents one test sample
"""
reference_text: str
predicted_text: str
def update(self, reference_text:str, predicted_text:str) -> None:
self.reference_text = reference_text
self.predicted_text = predicted_text
class TestDatasetLoader(BaseModel):
"""
Test samples loader
"""
test_dir: Path = Field(default=Path(__file__).parent)
total_samples: int = Field(default=0)
@field_validator("test_dir")
def validate_file_path(cls, path):
"""
Check the file path
"""
if not path.exists():
raise ValueError("Path does not exist")
return path
def _load_test_data(self) -> tuple[Path, Path]:
"""
Loader function to validate input files and generate samples
"""
PREDICTED_TEST_SAMPLES_DIR = self.test_dir / "predicted_texts"
REFERENCE_TEST_SAMPLES_DIR = self.test_dir / "reference_texts"
for filename in PREDICTED_TEST_SAMPLES_DIR.iterdir():
match = re.search(r"(\d+)\.txt$", filename.as_posix())
if match:
sample_id = match.group(1)
pred_file_path = PREDICTED_TEST_SAMPLES_DIR / filename
ref_file_name = "ref_sample_" + str(sample_id) + ".txt"
ref_file_path = REFERENCE_TEST_SAMPLES_DIR / ref_file_name
if ref_file_path.exists():
self.total_samples += 1
yield ref_file_path, pred_file_path
def __iter__(self) -> EvaluationTestSample:
"""
Iter method for the test loader
"""
for pred_file_path, ref_file_path in self._load_test_data():
with open(pred_file_path, "r", encoding="utf-8") as file:
pred_text = file.read()
with open(ref_file_path, "r", encoding="utf-8") as file:
ref_text = file.read()
yield EvaluationTestSample(reference_text=ref_text, predicted_text=pred_text)
class EvaluationConfig(BaseModel):
"""
Model for evaluation parameters
"""
insertion_penalty: int = Field(default=1)
substitution_penalty: int = Field(default=1)
deletion_penalty: int = Field(default=1)
normalizer: Any = Field(default=EnglishTextNormalizer())
test_directory: str = Field(default=str(Path(__file__).parent))
class ModelEvaluator:
"""
Class that comprises all model evaluation related processes and methods
"""
# The 2 popular methods of WER differ slightly. More dimensions of accuracy
# will be added. For now, the average of these 2 will serve as the metric.
WEIGHTED_WER_LEVENSHTEIN = 0.0
WER_LEVENSHTEIN = []
WEIGHTED_WER_JIWER = 0.0
WER_JIWER = []
evaluation_result = EvaluationResult()
test_dataset_loader = None
evaluation_config = None
def __init__(self, **kwargs):
self.evaluation_config = EvaluationConfig(**kwargs)
self.test_dataset_loader = TestDatasetLoader(test_dir=self.evaluation_config.test_directory)
def __repr__(self):
return f"ModelEvaluator({self.evaluation_config})"
def describe(self) -> dict:
"""
Returns the parameters defining the evaluator
"""
return self.evaluation_config.model_dump()
def _normalize(self, sample: EvaluationTestSample) -> None:
"""
Normalize both reference and predicted text
"""
sample.update(
self.evaluation_config.normalizer(sample.reference_text),
self.evaluation_config.normalizer(sample.predicted_text),
)
def _calculate_wer(self, sample: EvaluationTestSample) -> float:
"""
Based on weights for (insert, delete, substitute), calculate
the Word Error Rate
"""
levenshtein_distance = distance(
s1=sample.reference_text,
s2=sample.predicted_text,
weights=(
self.evaluation_config.insertion_penalty,
self.evaluation_config.deletion_penalty,
self.evaluation_config.substitution_penalty,
),
)
wer = levenshtein_distance / len(sample.reference_text)
return wer
def _calculate_wers(self) -> None:
"""
Compute WER
"""
for sample in tqdm(self.test_dataset_loader, desc="Evaluating"):
self._normalize(sample)
wer_item_l = {
"wer": self._calculate_wer(sample),
"no_of_words": len(sample.reference_text),
}
wer_item_j = {
"wer": wer(sample.reference_text, sample.predicted_text),
"no_of_words": len(sample.reference_text),
}
self.WER_LEVENSHTEIN.append(wer_item_l)
self.WER_JIWER.append(wer_item_j)
def _calculate_weighted_wer(self, wers: List[float]) -> float:
"""
Calculate the weighted WER from WER
"""
total_wer = 0.0
total_words = 0.0
for item in wers:
total_wer += item["no_of_words"] * item["wer"]
total_words += item["no_of_words"]
return total_wer / total_words
def _calculate_model_accuracy(self) -> None:
"""
Compute model accuracy
"""
self._calculate_wers()
weighted_wer_levenshtein = self._calculate_weighted_wer(self.WER_LEVENSHTEIN)
weighted_wer_jiwer = self._calculate_weighted_wer(self.WER_JIWER)
final_weighted_wer = (weighted_wer_levenshtein + weighted_wer_jiwer) / 2
self.evaluation_result.accuracy = (1 - final_weighted_wer) * 100
def evaluate(self, recalculate: bool = False) -> EvaluationResult:
"""
Triggers the model evaluation
"""
if not self.evaluation_result.accuracy or recalculate:
self._calculate_model_accuracy()
return EvaluationResult(
accuracy=self.evaluation_result.accuracy,
total_test_samples=self.test_dataset_loader.total_samples
)
eval_config = {"insertion_penalty": 1, "deletion_penalty": 2, "substitution_penalty": 1}
evaluator = ModelEvaluator(**eval_config)
evaluation = evaluator.evaluate()
print(evaluator)
print(evaluation)
print("Model accuracy : {:.2f} %".format(evaluation.accuracy))

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@@ -1,620 +0,0 @@
Technologies ticker symbol w-e-l-l on
the TSX recently reported its 2023 q1
results beating the streets consensus
estimate for revenue and adjusted ebitda
and in a report issued this week Raymond
James analyst said quote we're impressed
by Wells capacity to drive powerful
growth across its diverse business units
in the absence of M A joining me today
is CEO Hamed chabazi to look at what's
next for well health good to see you sir
how are you great to see you Richard
thanks very much for having me great to
have you uh congratulations on your 17th
consecutive quarter of record Revenue
can you share some insights into what's
Driven these results historically and in
the past quarter as well
yeah thank you we we're very excited
about our uh q1 2023 results and as you
mentioned uh we've had a long you know
successful uh string of of uh you know
continued growth and record growth
um we also had accelerating organic
growth and I think um a big part of the
success of our franchise here is the
incredibly sticky and predictable
Revenue that we have you know well over
90 of our business is either highly
reoccurring as in uh the you know highly
predictable uh results of our two-sided
network of patients and providers or
truly recurring as in scheduled or
subscribed revenues and this allows us
to essentially make sure that that uh
you know we're on track it obviously you
know like any other business things
happen uh and sometimes it's hard to
meet those results but what's really
being unique about our platform is we do
have exposure to all kinds of different
aspects of healthcare you know we have
Prime primary care and Specialized Care
on both sides of the Border in the US
and Canada so we have exposure to
different types of business models we
have exposure to the U.S payer Network
which has higher per unit economics than
Canada and of course the stability and
uh and and sort of higher Fidelity uh
kind of Collections and revenue cycle
process that Canada has over the United
States where you don't have to kind of
deal with all of that uh at that payment
noise so just a lot of I think strength
built into the platform because of the
diversity of different Healthcare
businesses that we support
and uh where do you see Well's future
growth coming from which part of the
business uh excites you the most right
now yeah well look the centrifugal force
of well is the healthcare provider and
we exist to uh Tech enable and
ameliorate the business of that of that
Tech of that healthcare provider uh and
and and that's what we're laser focused
on and and what we're seeing is
providers not wanting to run businesses
anymore it's very simple and so we have
a digital platform and providers can
either acquire what they want and need
from our digital platform and implement
it themselves
or they can decide that they don't want
to run a business anymore they don't
want to configure and manage technology
which is becoming a bigger and bigger
part of their world every single day and
when we see what we've seen with that
Dynamic is that uh is that a lot of them
are now just wanting to work in a place
where where all the technology is
configured for them it's wrapped around
them and they have a competent operating
partner that is supporting the organ the
the practice uh and and taking care of
the front office in the back office so
that they can focus on providing care
this results in them seeing more
patients uh and and being happier
because you know they became doctors to
see patients not so they can manage uh
workers and and deal with HR issues and
deal with labs and all that kind of
stuff excellent and I know too that
Acquisitions have played a key role in
well can you share any insights into how
the Acquisitions fit into Wells growth
strategy
sure in in look in 2020 and 2021 we did
a lot of Acquisitions in 2022 we took a
bit of a breather and we've really
focused on integration and I think
that's one of the reasons why you saw
this accelerating organic growth we
really were able to demonstrate that we
could bring together the different
elements of our technology platform we
started to sell bundles we started to
really derive Synergy uh and activate uh
you know more sales as a result of
selling uh all the different products
and services with one voice with One
Vision uh so we made it easier for
providers to use their technology and I
think that was a big reason uh for our
growth now M A as you know where Capital
allocation company we're never far from
it and so we did continue to have you
know tuck-ins here and there and in fact
today uh we announced that we've
acquired uh the Alberta operations of uh
MCI one Health and other publicly traded
company uh who was looking to raise
funds to support their business we're
very pleased with with this acquisition
it just demonstrates our continued
discipline these are you know great
primary care clinics in in Canada right
in the greater Calgary area and uh uh
you know just allows us to grow our
footprint in Alberta which is an
important Province for us and it it's
it's if you look at the price if you
look at what we're getting uh you know
it's just demonstrative of our continued
uh discipline and just you know a few
days ago at our conference call I
mentioned uh that we had you know a
really strong lineup of Acquisitions uh
and you know they're starting to uh uh I
think uh come to fruition for us
a company on the grown-up question I you
recently announced a new AI investment
program last month what specific areas
of healthcare technology or AI are you
focusing on and what's the strategy when
it comes to AI
yes uh look AI as as I'm sure you're
aware is it's become you know really uh
an incredibly important topic in in all
aspects of of business and and you know
not just business socially as well
everyone's talking about uh this this
new breakthrough disruptive technology
the large language models and generative
AI
um I mean look AI uh has been about a 80
year old overnight success a lot of
people have been working on this for a
long time generative AI is just sort of
you know the culmination of a lot of
things coming together and working uh
but it is uncorked enormous uh
Innovation and and we think that um this
there's a very good news story about
this in healthcare particularly where we
were looking to look we were looking to
unlock uh the value of of the data that
that we all produce every single day
um as as humans and and so we've
established an AI investment program
because no one company can can tackle
all of these Innovations themselves and
what well has done too is it's taken a
very much an ecosystem approach by
establishing its apps.health Marketplace
and so we're very excited about not only
uh allocating Capital into promising
young AI companies that are focused on
digital health and solving Healthcare
problems but also giving them access to
um you know safely and securely to our
provider Network to our uh you know to
to our Outpatient Clinic Network which
is the largest owned and operated
Network in Canada by far uh so
um and and when these and it's it was
remarkable when we announced this
program we've had just in the in the
first uh week to 10 days we've had over
a hundred uh inbound prospects come in
uh that that wanted to you know
collaborate with us and again I don't
think that's necessarily for the money
you know we're saying we would invest a
minimum of a quarter of a million
dollars you know a lot of them will
likely be higher than a quarter of a
million dollars
so it's not life-changing money but but
our structural advantages and and and
the benefits that we have in the Well
Network those are extremely hard to come
by uh and I think and I think uh uh
you'll see us uh you know help some of
these companies uh succeed and they will
help us drive uh you know more
Innovation to that helps the provider
but speaking of this very interesting AI
I know your company just launched well
AI voice this is super interesting tell
me what it is and the impact it could
have on health care providers
yeah thanks for uh asking Richard our
providers uh are thrilled with this you
know we've we've had a number of of of
our own well providers testing this
technology and it it it really feels
like magic to them it's essentially an
ambient AI powered scribe so it's a it's
a service that with the consent of the
parties involved listens to the
conversation between a patient and
provider and then uh essentially
condenses that into a medically relevant
note for the chart files uh typically
that is a lengthy process a doctor has
to transcribe notes then review those
notes and make sure that uh a a a a
appropriate medically oriented and
structured node is is is uh prepared and
put into the chart and that could take
you know sometimes more than more time
than the actual consultation uh time and
so we believe that on average if it's
used regularly and consistently this can
give providers back at least a third of
their day
um and and it's it's just a game changer
uh and and uh we have now gone into
General release with this product it's
widely available in Canada uh it has
been integrated into our EMR which makes
it even more valuable tools like this
are going to start popping up but if
they're not integrated into your
practice management system then you have
to kind of have data in in more than one
place and and move that around a little
bit which which makes it a little bit
more difficult especially with HIPAA
requirements and and regulations so
again I think this is the first of many
types of different products and services
that allow doctors to place more
emphasis and focus on the patient
experience instead of having their head
in a laptop and looking at you once in a
while they'll be looking at you and
speaking to their practice management
system and I think this you know think
about it as Alexa for for our doctors uh
you know this this ability to speak uh
and and have you know uh you know Voice
driven AI assistant that does things
like this I think are going to be you
know incredibly helpful and valuable uh
for for healthcare providers
super fascinating I mean we're just
hearing you know more about AI maybe AI
for the first time but here you are with
a product already on the market in the
in the healthcare field that's going to
be pretty attractive to be out there uh
right ahead of many other people right
thank you Richard thanks for that
recognition that's been Our intention we
we want to demonstrate that we uh you
know that we're all in on ensuring that
technology that benefits providers uh is
is is accelerated and uh de-risked and
provided uh you know um in in a timely
way you know providers need this help we
we have a healthcare crisis in the
country that is generally characterized
as a as a lack of doctors and so imagine
if we can get our doctors to be 20 or 30
percent more productive through the use
of these types of tools well they're
going to just see more patience and and
that's going to help all of us and uh
and look if you step back Wells business
model is all about having exposure to
the success of doctors and doing our
best to help them be more successful
because we're in a revenue share
relationship with most of the doctors
that we work with and so this uh this is
good for the ecosystem it's great for
the provider and it's great for well as
well super fascinating I'm Ed shabazzi
CEO well Health Technologies ticker
w-e-l-l great to catch up again thank
you sir
thank you Richard appreciate you having
me
[Music]
thank you

View File

@@ -1,970 +0,0 @@
learning medicine is hard work osmosis
makes it easy it takes our lectures and
notes to create a personalized study
plan with exclusive videos practice
questions and flashcards and so much
more try it free today
in diabetes mellitus your body has
trouble moving glucose which is the type
of sugar from your blood into your cells
this leads to high levels of glucose in
your blood and not enough of it in your
cells and remember that your cells need
glucose as a source of energy so not
letting the glucose enter means that the
cells star for energy despite having
glucose right on their doorstep in
general the body controls how much
glucose is in the blood relative to how
much gets into the cells with two
hormones insulin and glucagon insulin is
used to reduce blood glucose levels and
glucagon is used to increase blood
glucose levels both of these hormones
are produced by clusters of cells in the
pancreas called islets of langerhans
insulin is secreted by beta cells in the
center of these islets and glucagon is
secreted by alpha cells in the periphery
of the islets insulin reduces the amount
of glucose in the blood by binding to
insulin receptors embedded in the cell
membrane of various insulin responsive
tissues like muscle cells in adipose
tissue when activated the insulin
receptors cause vesicles containing
glucose transporter that are inside the
cell to fuse with the cell membrane
allowing glucose to be transported into
the cell glucagon does exactly the
opposite it raises the blood glucose
levels by getting the liver to generate
new molecules of glucose from other
molecules and also break down glycogen
into glucose so that I can all get
dumped into the blood diabetes mellitus
is diagnosed when blood glucose levels
get too high and this is seen among 10
percent of the world population there
are two types of diabetes type 1 and
type 2 and the main difference between
them is the underlying mechanism that
causes the blood glucose levels to rise
about 10% of people with diabetes have
type 1 and the remaining 90% of people
with diabetes have type 2 let's start
with type 1 diabetes mellitus sometimes
just called type 1 diabetes in this
situation the body doesn't make enough
insulin the reason this happens is that
in type 1 diabetes there's a type 4
hypersensitivity response or a cell
mediated immune response where a
person's own T cells at
the pancreas as a quick review remember
that the immune system has T cells that
react to all sorts of antigens which are
usually small peptides polysaccharides
or lipids and that some of these
antigens are part of our own body cells
it doesn't make sense to allow T cells
that will attack our own cells to hang
around until there's this process to
eliminate them called self tolerance in
type 1 diabetes there's a genetic
abnormality that causes a loss of self
tolerance among T cells that
specifically target the beta cell
antigens losing self tolerance means
that these T cells are allowed to
recruit other immune cells and
coordinate an attack on these beta cells
losing beta cells means less insulin and
less insulin means that glucose piles up
in the blood because it can't enter the
body's cells one really important group
of genes involved in regulation of the
immune response is the human leukocyte
antigen system or HLA system even though
it's called a system it's basically this
group of genes on chromosome 6 that
encode the major histocompatibility
complex or MHC which is a protein that's
extremely important in helping the
immune system recognize foreign
molecules as well as maintaining self
tolerance MHC is like the serving
platter that antigens are presented to
the immune cells on interestingly people
with type 1 diabetes often have specific
HLA genes in common with each other one
called
HLA dr3 and another called HLA dr4 but
this is just a genetic clue right
because not everyone with HLA dr3 and
HLA dr4 develops diabetes in diabetes
mellitus type 1 destruction of beta
cells usually starts early in life but
sometimes up to 90% of the beta cells
are destroyed before symptoms crop up
for clinical symptoms of uncontrolled
diabetes that all sound similar our
polyphagia glycosuria polyuria and
polydipsia let's go through them one by
one even though there's a lot of glucose
in the blood it cannot get into the
cells which leaves cells starved for
energy so in response adipose tissue
starts breaking down fat called
lipolysis
and muscle tissue starts breaking down
proteins both of which results in weight
loss for someone with uncontrolled
diabetes this catabolic state leaves
people feeling hungry
also known as poly fascia Faiza means
eating and poly means a lot now with
high glucose levels that means that when
blood gets filtered through the kidneys
some of it starts to spill into the
urine called glycosuria glyco surfers to
glucose and urea the urine since glucose
is osmotically active water tends to
follow it resulting in an increase in
urination or polyuria poly again refers
to a lot and urea again refers to urine
finally because there's so much
urination people with uncontrolled
diabetes become dehydrated and thirsty
or polydipsia poly means a lot and dip
SIA means thirst even though people with
diabetes are not able to produce their
own insulin they can still respond to
insulin so treatment involves lifelong
insulin therapy to regulate their blood
glucose levels and basically enable
their cells to use glucose
one really serious complication with
type 1 diabetes is called diabetic
ketoacidosis or DKA to understand it
let's go back to the process of
lipolysis where fat is broken down into
free fatty acids after that happens the
liver turns the fatty acids into ketone
bodies like Osito acetic acid in beta
hydroxy butyrate acid a seed of acetic
acid is a keto acid because it has a
ketone group in a carboxylic acid group
beta hydroxy rhetoric acid on the other
hand even though it's still one of the
ketone bodies isn't technically a keto
acid since its ketone group has been
reduced to a hydroxyl group these ketone
bodies are important because they can be
used by cells for energy but they also
increase the acidity of the blood which
is why it's called ketoacidosis and the
blood becoming really acidic can have
major effects throughout the body
individuals can develop custom all
respiration which is a deep and labored
breathing as the body tries to move
carbon dioxide out of the blood in an
effort to reduce its acidity cells also
have a transporter that exchanges
hydrogen ions or protons for potassium
when the blood gets acidic it's by
definition loaded with protons that get
sent into cells while potassium gets
sent into the fluid outside cells
another thing to keep in mind is that in
addition to helping glucose enter cells
insulin stimulates the sodium potassium
ATPase --is which help potassium get
into the cells and so without insulin
more potassium stays in the fluid
outside cells both of these mechanisms
lead to increased potassium in the fluid
outside cells which quickly makes it
into the blood and causes hyperkalemia
the potassium is then excreted so over
time even though the blood potassium
levels remain high over all stores of
potassium in the body which include
potassium inside cells starts to run low
individuals will also have a high anion
gap which reflects a large difference in
the unmeasured negative and positive
ions in the serum largely due to the
build-up of ketoacids
diabetic ketoacidosis can happen even in
people who have already been diagnosed
with diabetes and currently have some
sort of insulin therapy
in states of stress like an infection
the body releases epinephrine which in
turn stimulates the release of glucagon
too much glucagon can tip the delicate
hormonal balance of glucagon and insulin
in favor of elevating blood sugars and
can lead to a cascade of events we just
described increased glucose in the blood
loss of glucose in the urine loss of
water dehydration and in parallel and
need for alternative energy generation
of ketone bodies and ketoacidosis
interestingly both ketone bodies break
down into acetone and escape as a gas by
getting breathed out the lungs which
gives us sweet fruity smell to a
person's breath in general though that's
the only sweet thing about this illness
which also causes nausea vomiting and if
severe mental status changes and acute
cerebral edema
treatment of a DKA episode involves
giving plenty of fluids which helps with
dehydration insulin which helps lower
blood glucose levels and replacement of
electrolytes like potassium all of which
help to reverse the acidosis now let's
switch gears and talk about type 2
diabetes which is where the body makes
insulin but the tissues don't respond as
well to it the exact reason why cells
don't respond isn't fully understood
essentially the body's providing the
normal amount of insulin but the cells
don't move their glucose transporters to
their membrane in response which
remember is needed for the glucose to
get into the cells these cells therefore
have insulin resistance some risk
factors for insulin resistance are
obesity lack of exercise and
hypertension the exact mechanisms are
still being explored for example in
excess of adipose tissue or fat is
thought to cause the release of free
fatty acids in so-called edible kinds
which are signaling molecules that can
cause inflammation which seems related
to insulin resistance
however many people that are obese are
not diabetic so genetic factors probably
play a major role as well we see this
when we look at twin studies as well
we're having a twin with type-2 diabetes
increases the risk of developing type 2
diabetes completely independently of
other environmental risk factors in type
2 diabetes since tissues don't respond
as well to normal levels of insulin the
body ends up producing more insulin in
order to get the same effect and move
glucose out of the blood
they do this through beta cell
hyperplasia an increased number of beta
cells and beta cell hypertrophy where
they actually grow in size all in this
attempt to pump out more insulin this
works for a while and by keeping insulin
levels higher than normal blood glucose
levels can be kept normal called normal
glycemia now along with insulin beta
cells also secrete islet amyloid
polypeptide or amylin so while beta
cells are cranking out insulin they also
secrete an increased amount of amylin
over time Emlyn builds up and aggregates
in the islets this beta cell
compensation though is not sustainable
and over time those maxed out beta cells
get exhausted and they become
dysfunctional and undergo hypo trophy
and get smaller as well as hypoplasia
and die off as beta cells are lost in
insulin levels decrease glucose levels
in the blood start to increase in
patients develop hyperglycemia which
leads to similar clinical signs that we
mentioned before like Paul aphasia
glycosuria polyuria polydipsia but
unlike type 1 diabetes there's generally
some circulating insulin in type 2
diabetes from the beta cells that are
trying to compensate for the insulin
resistance this means that the insulin
glucagon balances such that diabetic
ketoacidosis does not usually develop
having said that a complication called
hyperosmolar hyperglycemic state or HHS
is much more common in type 2 diabetes
than type 1 diabetes and it causes
increased plasma osmolarity due to
extreme dehydration and concentration of
the blood to help understand this
remember that glucose is a polar
molecule that cannot passively diffuse
across cell membranes which means that
it acts as a solute so when levels of
glucose are super high in the blood
meaning it's a hyperosmolar State water
starts to leave the body cells and enter
the blood vessels leaving the cells were
relatively dry in travailed rather than
plump and juicy blood vessels that are
full of water lead to increased
urination and total body dehydration and
this is a very serious situation because
the dehydration of the body's cells and
in particular the brain can cause a
number of symptoms including mental
status changes in HHS you can sometimes
see mild ketone emia and acidosis but
not to the extent that it's seen in DKA
and in DKA you can see some hyper
osmolarity so there's definitely overlap
between these two syndromes
besides type 1 and type 2 diabetes there
are also a couple other subtypes of
diabetes mellitus gestational diabetes
is when pregnant women have increased
blood glucose which is particularly
during the third trimester although
ultimately unknown the cause is thought
to be related to pregnancy hormones that
interfere with insulins action on
insulin receptors also sometimes people
can develop drug-induced diabetes which
is where medications have side effects
that tend to increase blood glucose
levels the mechanism for both of these
is thought to be related to insulin
resistance like type 2 diabetes rather
than an autoimmune destruction process
like in type 1 diabetes diagnosing type
1 or type 2 diabetes is done by getting
a sense for how much glucose is floating
around in the blood and has specific
standards that the World Health
Organization uses very commonly a
fasting glucose test is taken where the
person doesn't eat or drink except the
water that's okay for a total of eight
hours and then has their blood tested
for glucose levels levels of 100
milligrams per deciliter to 120
five milligrams per deciliter indicates
pre-diabetes and 126 milligrams per
deciliter or higher indicates diabetes a
non fasting a random glucose test can be
done at any time with 200 milligrams per
deciliter or higher being a red flag for
diabetes another test is called an oral
glucose tolerance test where person is
given glucose and then blood samples are
taken at time intervals to figure out
how well it's being cleared from the
blood the most important interval being
two hours later levels of 140 milligrams
per deciliter to 199 milligrams per
deciliter indicate pre-diabetes
and 200 or above indicates diabetes
another thing to know is that when blood
glucose levels get high the glucose can
also stick to proteins that are floating
around in the blood or in cells so that
brings us to another type of test that
can be done which is the hba1c test
which tests for the proportion of
hemoglobin in red blood cells that has
glucose stuck to it called glycated
hemoglobin hba1c levels of 5.7% 26.4%
indicate pre-diabetes
and 6.5 percent or higher indicates
diabetes this proportion of glycated
hemoglobin doesn't change day to day so
it gives a sense for whether the blood
glucose levels have been high over the
past two to three months finally we have
the c-peptide test which tests for
byproducts of insulin production if the
level of c-peptide is low or absent it
means the pancreas is no longer
producing enough insulin and the glucose
cannot enter the cells
for type one diabetes insulin is the
only treatment option for type 2
diabetes on the other hand lifestyle
changes like weight loss and exercise
along with a healthy diet and an oral
anti-diabetic medication like metformin
in several other classes can sometimes
be enough to reverse some of that
insulin resistance and keep blood sugar
levels in check however if oral
anti-diabetic medications fail type 2
diabetes can also be treated with
insulin something to bear in mind is
that insulin treatment comes with a risk
of hypoglycemia especially if insulin is
taken without a meal symptoms of
hypoglycemia can be mild like weakness
hunger and shaking but they can progress
to a loss of consciousness in seizures
in severe cases in mild cases drinking
juices or eating candy or sugar might be
enough to bring blood sugar up but in
severe cases intravenous glucose should
be given as soon as possible
the FDA has also recently approved
intranasal glucagon as a treatment for
severe hypoglycemia all right now over
time high glucose levels can cause
damage to tiny blood vessels while the
micro vasculature in arterioles a
process called hyaline
arteriolosclerosis is where the walls of
the arterioles develop hyaline deposits
which are deposits of proteins and these
make them hard and inflexible in
capillaries the basement membrane can
thicken and make it difficult for oxygen
to easily move from the capillary to the
tissues causing hypoxia
one of the most significant effects is
that diabetes increases the risk of
medium and large arterial wall damage
and subsequent atherosclerosis which can
lead to heart attacks and strokes which
are major causes of morbidity and
mortality for patients with diabetes in
the eyes diabetes can lead to
retinopathy and evidence of that can be
seen on a fundus copic exam that shows
cotton-wool spots or flare hemorrhages
and can eventually cause blindness in
the kidneys the a ferrant and efferent
arterioles as well as the glomerulus
itself can get damaged which can lead to
an F Radek syndrome that slowly
diminishes the kidneys ability to filter
blood over time and can ultimately lead
to dialysis diabetes can also affect the
function of nerves causing symptoms like
a decrease in sensation in the toes and
fingers sometimes called a stocking
glove distribution as well as causes the
autonomic nervous system to malfunction
and that system controls a number of
body functions
everything from sweating to passing gas
finally both the poor blood supply and
nerve damage can lead to ulcers
typically on the feet that don't heal
quickly and can get pretty severe and
need to be amputated these are some of
the complications of uncontrolled
diabetes which is why it's important to
diagnose and control diabetes through a
healthy lifestyle medications to reduce
insulin resistance and even insulin
therapy if beta cells have been
exhausted while type 1 diabetes cannot
be prevented type 2 diabetes can in fact
many people with diabetes can control
their blood sugar levels really
effectively and live a full and active
life without any of the complications
thanks for watching if you're interested
in a deeper dive on this topic take a
look at as Moses org where we have
flashcards questions and other awesome
tools to help you learn medicine
you

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@@ -1,34 +0,0 @@
import os
import subprocess
import sys
from loguru import logger
# Get the input file name from the command line argument
input_file = sys.argv[1]
# example use: python 0-reflector-local.py input.m4a agenda.txt
# Get the agenda file name from the command line argument if provided
if len(sys.argv) > 2:
agenda_file = sys.argv[2]
else:
agenda_file = "agenda.txt"
# example use: python 0-reflector-local.py input.m4a my_agenda.txt
# Check if the agenda file exists
if not os.path.exists(agenda_file):
logger.error("agenda_file is missing")
# Check if the input file is .m4a, if so convert to .mp4
if input_file.endswith(".m4a"):
subprocess.run(["ffmpeg", "-i", input_file, f"{input_file}.mp4"])
input_file = f"{input_file}.mp4"
# Run the first script to generate the transcript
subprocess.run(["python3", "1-transcript-generator.py", input_file, f"{input_file}_transcript.txt"])
# Run the second script to compare the transcript to the agenda
subprocess.run(["python3", "2-agenda-transcript-diff.py", agenda_file, f"{input_file}_transcript.txt"])
# Run the third script to summarize the transcript
subprocess.run(["python3", "3-transcript-summarizer.py", f"{input_file}_transcript.txt", f"{input_file}_summary.txt"])

View File

@@ -1,62 +0,0 @@
import argparse
import os
import moviepy.editor
import whisper
from loguru import logger
WHISPER_MODEL_SIZE = "base"
def init_argparse() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
usage="%(prog)s <LOCATION> <OUTPUT>",
description="Creates a transcript of a video or audio file using the OpenAI Whisper model"
)
parser.add_argument("location", help="Location of the media file")
parser.add_argument("output", help="Output file path")
return parser
def main():
import sys
sys.setrecursionlimit(10000)
parser = init_argparse()
args = parser.parse_args()
media_file = args.location
logger.info(f"Processing file: {media_file}")
# Check if the media file is a valid audio or video file
if os.path.isfile(media_file) and not media_file.endswith(
('.mp3', '.wav', '.ogg', '.flac', '.mp4', '.avi', '.flv')):
logger.error(f"Invalid file format: {media_file}")
return
# If the media file we just retrieved is an audio file then skip extraction step
audio_filename = media_file
logger.info(f"Found audio-only file, skipping audio extraction")
audio = moviepy.editor.AudioFileClip(audio_filename)
logger.info("Selected extracted audio")
# Transcribe the audio file using the OpenAI Whisper model
logger.info("Loading Whisper speech-to-text model")
whisper_model = whisper.load_model(WHISPER_MODEL_SIZE)
logger.info(f"Transcribing file: {media_file}")
whisper_result = whisper_model.transcribe(media_file)
logger.info("Finished transcribing file")
# Save the transcript to the specified file.
logger.info(f"Saving transcript to: {args.output}")
transcript_file = open(args.output, "w")
transcript_file.write(whisper_result["text"])
transcript_file.close()
if __name__ == "__main__":
main()

View File

@@ -1,68 +0,0 @@
import argparse
import spacy
from loguru import logger
# Define the paths for agenda and transcription files
def init_argparse() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
usage="%(prog)s <AGENDA> <TRANSCRIPTION>",
description="Compares the transcript of a video or audio file to an agenda using the SpaCy model"
)
parser.add_argument("agenda", help="Location of the agenda file")
parser.add_argument("transcription", help="Location of the transcription file")
return parser
args = init_argparse().parse_args()
agenda_path = args.agenda
transcription_path = args.transcription
# Load the spaCy model and add the sentencizer
spaCy_model = "en_core_web_md"
nlp = spacy.load(spaCy_model)
nlp.add_pipe('sentencizer')
logger.info("Loaded spaCy model " + spaCy_model)
# Load the agenda
with open(agenda_path, "r") as f:
agenda = [line.strip() for line in f.readlines() if line.strip()]
logger.info("Loaded agenda items")
# Load the transcription
with open(transcription_path, "r") as f:
transcription = f.read()
logger.info("Loaded transcription")
# Tokenize the transcription using spaCy
doc_transcription = nlp(transcription)
logger.info("Tokenized transcription")
# Find the items covered in the transcription
covered_items = {}
for item in agenda:
item_doc = nlp(item)
for sent in doc_transcription.sents:
if not sent or not all(token.has_vector for token in sent):
# Skip an empty span or one without any word vectors
continue
similarity = sent.similarity(item_doc)
similarity_threshold = 0.7
if similarity > similarity_threshold: # Set the threshold to determine what is considered a match
covered_items[item] = True
break
# Count the number of items covered and calculatre the percentage
num_covered_items = sum(covered_items.values())
percentage_covered = num_covered_items / len(agenda) * 100
# Print the results
print("💬 Agenda items covered in the transcription:")
for item in agenda:
if item in covered_items and covered_items[item]:
print("", item)
else:
print("", item)
print("📊 Coverage: {:.2f}%".format(percentage_covered))
logger.info("Finished comparing agenda to transcription with similarity threshold of " + str(similarity_threshold))

View File

@@ -1,94 +0,0 @@
import argparse
import nltk
nltk.download('stopwords')
from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize, sent_tokenize
from heapq import nlargest
from loguru import logger
# Function to initialize the argument parser
def init_argparse():
parser = argparse.ArgumentParser(
usage="%(prog)s <TRANSCRIPT> <SUMMARY>",
description="Summarization"
)
parser.add_argument("transcript", type=str, default="transcript.txt", help="Path to the input transcript file")
parser.add_argument("summary", type=str, default="summary.txt", help="Path to the output summary file")
parser.add_argument("--num_sentences", type=int, default=5, help="Number of sentences to include in the summary")
return parser
# Function to read the input transcript file
def read_transcript(file_path):
with open(file_path, "r") as file:
transcript = file.read()
return transcript
# Function to preprocess the text by removing stop words and special characters
def preprocess_text(text):
stop_words = set(stopwords.words('english'))
words = word_tokenize(text)
words = [w.lower() for w in words if w.isalpha() and w.lower() not in stop_words]
return words
# Function to score each sentence based on the frequency of its words and return the top sentences
def summarize_text(text, num_sentences):
# Tokenize the text into sentences
sentences = sent_tokenize(text)
# Preprocess the text by removing stop words and special characters
words = preprocess_text(text)
# Calculate the frequency of each word in the text
word_freq = nltk.FreqDist(words)
# Calculate the score for each sentence based on the frequency of its words
sentence_scores = {}
for i, sentence in enumerate(sentences):
sentence_words = preprocess_text(sentence)
for word in sentence_words:
if word in word_freq:
if i not in sentence_scores:
sentence_scores[i] = word_freq[word]
else:
sentence_scores[i] += word_freq[word]
# Select the top sentences based on their scores
top_sentences = nlargest(num_sentences, sentence_scores, key=sentence_scores.get)
# Sort the top sentences in the order they appeared in the original text
summary_sent = sorted(top_sentences)
summary = [sentences[i] for i in summary_sent]
return " ".join(summary)
def main():
# Initialize the argument parser and parse the arguments
parser = init_argparse()
args = parser.parse_args()
# Read the input transcript file
logger.info(f"Reading transcript from: {args.transcript}")
transcript = read_transcript(args.transcript)
# Summarize the transcript using the nltk library
logger.info("Summarizing transcript")
summary = summarize_text(transcript, args.num_sentences)
# Write the summary to the output file
logger.info(f"Writing summary to: {args.summary}")
with open(args.summary, "w") as f:
f.write("Summary of: " + args.transcript + "\n\n")
f.write(summary)
logger.info("Summarization completed")
if __name__ == "__main__":
main()

View File

@@ -1,4 +0,0 @@
# Deloitte HR @ NYS Cybersecurity Conference
- ways to retain and grow your workforce
- how to enable cybersecurity professionals to do their best work
- low-budget activities that can be implemented starting tomorrow

File diff suppressed because one or more lines are too long

View File

@@ -1,3 +0,0 @@
Summary of: 30min-CyberHR/30min-CyberHR.m4a.mp4_transcript.txt
Since the workforce is an organization's most valuable asset, investing in workforce experience activities, we've found has lead to more productive work, more efficient work, more innovative approaches to the work, and more engaged teams which ultimately results in better mission outcomes for your organization. And this one really focuses on not just pulsing a workforce once a year through an annual HR survey of, how do you really feel like, you know, what leadership considerations should we implement or, you know, how can we enhance the performance management process. We've just found that, you know, by investing in this and putting the workforce as, you know, the center part of what you invest in as an organization and leaders, it's not only about retention, talent, you know, the cyber workforce crisis, but people want to do work well and they're able to get more done and achieve more without you, you know, directly supervising and micromanaging or looking at everything because, you know, you know, you know, you're not going to be able to do anything. I hope there was a little bit of, you know, the landscape of the cyber workforce with some practical tips that you can take away for how to just think about, you know, improving the overall workforce experience and investing in your employees. So with this, you know, we know that all of you are in the trenches every day, you're facing this, you're living this, and we are just interested to hear from all of you, you know, just to start, like, what's one thing that has worked well in your organization in terms of enhancing or investing in the workforce experience?

File diff suppressed because one or more lines are too long

View File

@@ -1,47 +0,0 @@
AGENDA: Most important things to look for in a start up
TAM: Make sure the market is sufficiently large than once they win they can get rewarded
- Medium sized markets that should be winner take all can work
- TAM needs to be realistic of direct market size
Product market fit: Being in a good market with a product than can satisfy that market
- Solves a problem
- Builds a solution a customer wants to buy
- Either saves the customer something (time/money/pain) or gives them something (revenue/enjoyment)
Unit economics: Profit for delivering all-in cost must be attractive (% or $ amount)
- Revenue minus direct costs
- Raw input costs (materials, variable labour), direct cost of delivering and servicing the sale
- Attractive as a % of sales so it can contribute to fixed overhead
- Look for high incremental contribution margin
LTV CAC: Life-time value (revenue contribution) vs cost to acquire customer must be healthy
- LTV = Purchase value x number of purchases x customer lifespan
- CAC = All-in costs of sales + marketing over number of new customer additions
- Strong reputation leads to referrals leads to lower CAC. Want customers evangelizing product/service
- Rule of thumb higher than 3
Churn: Fits into LTV, low churn leads to higher LTV and helps keep future CAC down
- Selling to replenish revenue every year is hard
- Can run through entire customer base over time
- Low churn builds strong net dollar retention
Business: Must have sufficient barriers to entry to ward off copy-cats once established
- High switching costs (lock-in)
- Addictive
- Steep learning curve once adopted (form of switching cost)
- Two sided liquidity
- Patents, IP, Branding
- No hyper-scaler who can roll over you quickly
- Scale could be a barrier to entry but works against most start-ups, not for them
- Once developed, answer question: Could a well funded competitor starting up today easily duplicate this business or is it cheaper to buy the start up?
Founders: Must be religious about their product. Believe they will change the world against all odds.
- Just money in the bank is not enough to build a successful company. Just good tech not enough
to build a successful company
- Founders must be motivated to build something, not (all) about money. They would be doing
this for free because they believe in it. Not looking for quick score
- Founders must be persuasive. They will be asking others to sacrifice to make their dream come
to life. They will need to convince investors this company can work and deserves funding.
- Must understand who the customer is and what problem they are helping to solve.
- Founders arent expected to know all the preceding points in this document but have an understanding of most of this, and be able to offer a vision.

View File

@@ -1,8 +0,0 @@
AGENDA: Most important things to look for in a start up
TAM: Make sure the market is sufficiently large than once they win they can get rewarded
Product market fit: Being in a good market with a product than can satisfy that market
Unit economics: Profit for delivering all-in cost must be attractive (% or $ amount)
LTV CAC: Life-time value (revenue contribution) vs cost to acquire customer must be healthy
Churn: Fits into LTV, low churn leads to higher LTV and helps keep future CAC down
Business: Must have sufficient barriers to entry to ward off copy-cats once established
Founders: Must be religious about their product. Believe they will change the world against all odds.

View File

@@ -1,10 +0,0 @@
Summary of: recordings/42min-StartupsTechTalk.mp4
The speaker discusses their plan to launch an investment company, which will sit on a pool of cash raised from various partners and investors. They will take equity stakes in startups that they believe have the potential to scale and become successful. The speaker emphasizes the importance of investing in companies that have a large total addressable market (TAM) and good product-market fit. They also discuss the concept of unit economics and how it is important to ensure that the profit from selling a product or service outweighs the cost of producing it. The speaker encourages their team to keep an eye out for interesting startups and to send them their way if they come across any.
The conversation is about the importance of unit economics, incremental margin, lifetime value, customer acquisition costs, churn, and barriers to entry in evaluating businesses for investment. The speaker explains that companies with good unit economics and high incremental contribution margins are ideal for investment. Lifetime value measures how much a customer will spend on a business over their entire existence, while customer acquisition costs measure the cost of acquiring a new customer. Churn refers to the rate at which customers leave a business, and businesses with low churn tend to have high lifetime values. High barriers to entry, such as high switching costs, can make it difficult for competitors to enter the market and kill established businesses.
The speaker discusses various factors that can contribute to a company's success and create a competitive advantage. These include making the product addictive, having steep learning curves, creating two-sided liquidity for marketplaces, having patents or intellectual property, strong branding, and scale as a barrier to entry. The speaker also emphasizes the importance of founders having a plan to differentiate themselves from competitors and avoid being rolled over by larger companies. Additionally, the speaker mentions MasterCard and Visa as examples of companies that invented their markets, while Apple was able to build a strong brand despite starting with no developers or users.
The speaker discusses the importance of founders in building successful companies, emphasizing that they must be passionate and believe in their product. They should also be charismatic and able to persuade others to work towards their vision. The speaker cites examples of successful CEOs such as Zuckerberg, Steve Jobs, Elon Musk, Bill Gates, Jeff Bezos, Travis Kalanick, and emphasizes that luck is also a factor in success. The speaker encourages listeners to have a critical eye when evaluating startups and to look for those with a clear understanding of their customers and the problem they are solving.

File diff suppressed because one or more lines are too long

View File

@@ -1,3 +0,0 @@
Summary of: 42min-StartupsTechTalk/42min-StartupsTechTalk.mp4_transcript.txt
If you had perfect knowledge, and you need like one more piece of advertising, drove like 0.2 customers in each customer generates, like let's say you wanted to completely maximize, you'd make it say your contribution margin, on incremental sales, is just over what you're spending on ad revenue. Like if you're, I don't know, well, let's see, I got like you don't really want to advertise a ton in the huge and everywhere, and then getting to ubiquitous, because you grab it, damage your brands, but just like an economic textbook theory, and be like, it'd be that basic math. And the table's like exactly, we're going to be really cautious to like be able to move in a year if we need to, but Google's goal is going to be giving away foundational models, lock everyone in, make them use Google Cloud, make them use Google Tools, and it's going to be very hard to switch off. Like if you were starting to develop Figma, you might say, okay, well Adobe is just gonna eat my lunch, right, like right away. So when you see a startup or talk to a founder and he's saying these things in your head like, man, this isn't gonna work because of, you know, there's no tab or there's, you know, like Amazon's gonna roll these cuts over in like two days or whatever, you know, or the man, this is really interesting because not only they're not doing it and no one else is doing this, but like they're going after a big market.

File diff suppressed because one or more lines are too long

View File

@@ -1,4 +0,0 @@
GitHub
Requirements
Junior Developers
Riding Elephants

View File

@@ -1,4 +0,0 @@
Summary of: https://www.youtube.com/watch?v=DzRoYc2UGKI
Small Developer is a program that creates an entire project for you based on a prompt. It uses the JATGPT API to generate code and files, and it's easy to use. The program can be installed by cloning the GitHub repository and using modalcom. The program can create projects for various languages, including Python and Ruby. You can also create a prompt.md file to input your prompt instead of pasting it into the terminal. The program is useful for creating detailed specs that can be passed on to junior developers. Overall, Small Developer is a helpful tool for quickly generating code and projects.

File diff suppressed because one or more lines are too long

View File

@@ -1,11 +0,0 @@
# Record on Voice Memos on iPhone
# Airdrop to MacBook Air
# Run Reflector on .m4a Recording and Agenda
python 0-reflector-local.py voicememo.m4a agenda.txt
OR - using 30min-CyberHR example:
python 0-reflector-local.py 30min-CyberHR/30min-CyberHR.m4a 30min-CyberHR/30min-CyberHR-agenda.txt

View File

@@ -1,125 +0,0 @@
import argparse
import os
import tempfile
import moviepy.editor
import nltk
import whisper
from loguru import logger
from transformers import BartTokenizer, BartForConditionalGeneration
nltk.download('punkt', quiet=True)
WHISPER_MODEL_SIZE = "base"
def init_argparse() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
usage="%(prog)s [OPTIONS] <LOCATION> <OUTPUT>",
description="Creates a transcript of a video or audio file, then summarizes it using BART."
)
parser.add_argument("location", help="Location of the media file")
parser.add_argument("output", help="Output file path")
parser.add_argument(
"-t", "--transcript", help="Save a copy of the intermediary transcript file", type=str)
parser.add_argument(
"-l", "--language", help="Language that the summary should be written in",
type=str, default="english", choices=['english', 'spanish', 'french', 'german', 'romanian'])
parser.add_argument(
"-m", "--model_name", help="Name or path of the BART model",
type=str, default="facebook/bart-large-cnn")
return parser
# NLTK chunking function
def chunk_text(txt, max_chunk_length=500):
"Split text into smaller chunks."
sentences = nltk.sent_tokenize(txt)
chunks = []
current_chunk = ""
for sentence in sentences:
if len(current_chunk) + len(sentence) < max_chunk_length:
current_chunk += f" {sentence.strip()}"
else:
chunks.append(current_chunk.strip())
current_chunk = f"{sentence.strip()}"
chunks.append(current_chunk.strip())
return chunks
# BART summary function
def summarize_chunks(chunks, tokenizer, model):
summaries = []
for c in chunks:
input_ids = tokenizer.encode(c, return_tensors='pt')
summary_ids = model.generate(
input_ids, num_beams=4, length_penalty=2.0, max_length=1024, no_repeat_ngram_size=3)
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
summaries.append(summary)
return summaries
def main():
import sys
sys.setrecursionlimit(10000)
parser = init_argparse()
args = parser.parse_args()
media_file = args.location
logger.info(f"Processing file: {media_file}")
# If the media file we just retrieved is a video, extract its audio stream.
if os.path.isfile(media_file) and media_file.endswith(('.mp4', '.avi', '.flv')):
audio_filename = tempfile.NamedTemporaryFile(
suffix=".mp3", delete=False).name
logger.info(f"Extracting audio to: {audio_filename}")
video = moviepy.editor.VideoFileClip(media_file)
video.audio.write_audiofile(audio_filename, logger=None)
logger.info("Finished extracting audio")
media_file = audio_filename
# Transcribe the audio file using the OpenAI Whisper model
logger.info("Loading Whisper speech-to-text model")
whisper_model = whisper.load_model(WHISPER_MODEL_SIZE)
logger.info(f"Transcribing audio file: {media_file}")
whisper_result = whisper_model.transcribe(media_file)
logger.info("Finished transcribing file")
# If we got the transcript parameter on the command line, save the transcript to the specified file.
if args.transcript:
logger.info(f"Saving transcript to: {args.transcript}")
transcript_file = open(args.transcript, "w")
transcript_file.write(whisper_result["text"])
transcript_file.close()
# Summarize the generated transcript using the BART model
logger.info(f"Loading BART model: {args.model_name}")
tokenizer = BartTokenizer.from_pretrained(args.model_name)
model = BartForConditionalGeneration.from_pretrained(args.model_name)
logger.info("Breaking transcript into smaller chunks")
chunks = chunk_text(whisper_result['text'])
logger.info(
f"Transcript broken into {len(chunks)} chunks of at most 500 words") # TODO fix variable
logger.info(f"Writing summary text in {args.language} to: {args.output}")
with open(args.output, 'w') as f:
f.write('Summary of: ' + args.location + "\n\n")
summaries = summarize_chunks(chunks, tokenizer, model)
for summary in summaries:
f.write(summary.strip() + "\n\n")
logger.info("Summarization completed")
if __name__ == "__main__":
main()

View File

@@ -1,24 +0,0 @@
# Steps to prepare data and submit/check OpenAI finetuning
# import subprocess
# subprocess.run("openai tools fine_tunes.prepare_data -f " + "finetuning_dataset.jsonl")
# export OPENAI_API_KEY=
# openai api fine_tunes.create -t <TRAIN_FILE_ID_OR_PATH> -m <BASE_MODEL>
# openai api fine_tunes.list
import openai
# Use your OpenAI API Key
openai.api_key = ""
sample_chunks = ["You all just came off of your incredible Google Cloud next conference where you released a wide variety of functionality and features and new products across artisan television and also across the entire sort of cloud ecosystem . You want to just first by walking through , first start by walking through all the innovations that you sort of released and what you 're excited about when you come to Google Cloud ? Now our vision is super simple . If you look at what smartphones did for a consumer , you know they took a computer and internet browser , a communication device , and a camera , and made it so that it 's in everybody 's pocket , so it really brought computation to every person . We feel that , you know , our , what we 're trying to do is take all the technological innovation that Google 's doing , but make it super simple so that everyone can consume it . And so that includes our global data center footprint , all the new types of hardware and large-scale systems we work on , the software that we 're making available for people to do high-scale computation , tools for data processing , tools for cybersecurity , processing , tools for cyber security , tools for machine learning , but make it so simple that everyone can use it . And every step that we do to simplify things for people , we think adoption can grow . And so that 's a lot of what we 've done these last three , four years , and we made a number of announcements that next in machine learning and AI in particular , you know , we look at our work as four elements , how we take our large-scale compute systems that were building for AI and how we make that available to everybody . Second , what we 're doing with the software stacks and top of it , things like jacks and other things and how we 're making those available to everybody . Third is advances because different people have different levels of expertise . Some people say I need the hardware to build my own large language model or algorithm . Other people say , look , I really need to use a building block . You guys give me . So , 30s we 've done a lot with AutoML and we announce new capability for image , video , and translation to make it available to everybody . And then lastly , we 're also building completely packaged solutions for some areas and we announce some new stuff . -> ",
" We 're joined next by Thomas Curian , CEO of Google Cloud , and Alexander Wang , CEO and founder of Scale AI . Thomas joined Google in November 2018 as the CEO of Google Cloud . Prior to Google , Thomas spent 22 years at Oracle , where most recently he was president of product development . Before that , Thomas worked at McKinsey as a business analyst and engagement manager . His nearly 30 years of experience have given him a deep knowledge of engineering enterprise relationships and leadership of large organizations . Thomas 's degrees include an MBA in administration and management from Stanford University , as an RJ Miller scholar and a BSEE in electrical engineering and computer science from Princeton University , where he graduated suma cum laude . Thomas serves as a member of the Stanford graduate School of Business Advisory Council and Princeton University School of Engineering Advisory Council . Please welcome to the stage , Thomas Curian and Alexander Wang . This is a super exciting conversation . Thanks for being here , Thomas . - > "]
# Give your finetuned model name here
# "davinci:ft-personal-2023-07-14-10-43-51"
model_name = ""
response = openai.Completion.create(
model=model_name,
prompt=sample_chunks[0])
print(response)

View File

@@ -1,98 +0,0 @@
import json
import yt_dlp as youtube_dl
from whisper_jax import FlaxWhisperPipline
import jax.numpy as jnp
# Function to extract chapter information from a YouTube video URL
def get_youtube_chapters(video_id):
video_url = "https://www.youtube.com/watch?v=" + video_id
ydl_opts = {
'extract_flat': 'in_playlist',
'skip_download': True,
'quiet': True,
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
video_info = ydl.extract_info(video_url, download=False)
chapters = []
if 'chapters' in video_info:
for chapter in video_info['chapters']:
start_time = chapter['start_time']
end_time = chapter['end_time']
title = chapter['title']
chapters.append({
'start': start_time,
'end': end_time,
'title': title
})
return chapters
# Function to extract video transcription using yt_dlp
def get_youtube_transcription(video_id):
ydl_opts = {
'format': 'bestaudio/best',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}],
'outtmpl': './artefacts/audio', # Specify output file path and name
}
# Download the audio
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download(["https://www.youtube.com/watch?v=" + video_id])
media_file = "./artefacts/audio.mp3"
pipeline = FlaxWhisperPipline("openai/whisper-" + "tiny",
dtype=jnp.float16,
batch_size=16)
whisper_result = pipeline(media_file, return_timestamps=True)
return whisper_result["chunks"]
# Function to scrape YouTube video transcripts and chapter information
def scrape_youtube_data(video_id):
transcript_text = get_youtube_transcription(video_id)
chapters = get_youtube_chapters(video_id)
print("transcript_text", transcript_text)
print("chapters", chapters)
return transcript_text, chapters
# Function to generate fine-tuning dataset from YouTube data
def generate_finetuning_dataset(video_ids):
prompt_completion_pairs = []
for video_id in video_ids:
transcript_text, chapters = scrape_youtube_data(video_id)
if transcript_text is not None and chapters is not None:
for chapter in chapters:
start_time = chapter["start"]
end_time = chapter["end"]
chapter_text = chapter["title"]
prompt = ""
for transcript in transcript_text:
if transcript["timestamp"][0] >= start_time and transcript["timestamp"][1] < end_time:
prompt += transcript["text"]
if prompt is not None:
completion = chapter_text
prompt_completion_pairs.append({"prompt": prompt, "completion": completion})
return prompt_completion_pairs
# Add all the video ids here, the videos must have captions [chapters]
video_ids = ["yTnSEZIwnkU"]
dataset = generate_finetuning_dataset(video_ids)
with open("finetuning_dataset.jsonl", "w", encoding="utf-8") as file:
for example in dataset:
file.write(json.dumps(example) + "\n")

View File

@@ -1,188 +0,0 @@
import asyncio
import datetime
import io
import json
import threading
import uuid
import wave
from concurrent.futures import ThreadPoolExecutor
import jax.numpy as jnp
import requests
from aiohttp import web
from aiortc import MediaStreamTrack, RTCPeerConnection, RTCSessionDescription
from aiortc.contrib.media import MediaRelay
from av import AudioFifo
from sortedcontainers import SortedDict
from whisper_jax import FlaxWhisperPipline
from reflector.utils.log_utils import LOGGER
from reflector.utils.run_utils import CONFIG, Mutex
WHISPER_MODEL_SIZE = CONFIG['WHISPER']["WHISPER_REAL_TIME_MODEL_SIZE"]
pcs = set()
relay = MediaRelay()
data_channel = None
sorted_message_queue = SortedDict()
CHANNELS = 2
RATE = 44100
CHUNK_SIZE = 256
pipeline = FlaxWhisperPipline("openai/whisper-" + WHISPER_MODEL_SIZE,
dtype=jnp.float16,
batch_size=16)
start_time = datetime.datetime.now()
executor = ThreadPoolExecutor()
audio_buffer = AudioFifo()
frame_lock = Mutex(audio_buffer)
def channel_log(channel, t, message):
print("channel(%s) %s %s" % (channel.label, t, message))
def thread_queue_channel_send():
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
try:
least_time = sorted_message_queue.keys()[0]
message = sorted_message_queue[least_time]
if message:
del sorted_message_queue[least_time]
data_channel.send(message)
except Exception as e:
print("Exception", str(e))
pass
loop.run_forever()
def get_transcription():
while True:
with frame_lock.lock() as audio_buffer:
frames = audio_buffer.read_many(CHUNK_SIZE * 960, partial=False)
if not frames:
transcribe = False
else:
transcribe = True
if transcribe:
print("Transcribing..")
try:
sorted_message_queue[frames[0].time] = None
out_file = io.BytesIO()
wf = wave.open(out_file, "wb")
wf.setnchannels(CHANNELS)
wf.setframerate(RATE)
wf.setsampwidth(2)
for frame in frames:
wf.writeframes(b''.join(frame.to_ndarray()))
wf.close()
whisper_result = pipeline(out_file.getvalue())
item = {
'text': whisper_result["text"],
'start_time': str(frames[0].time),
'time': str(datetime.datetime.now())
}
sorted_message_queue[frames[0].time] = str(item)
start_messaging_thread()
except Exception as e:
print("Exception -> ", str(e))
class AudioStreamTrack(MediaStreamTrack):
"""
An audio stream track to send audio frames.
"""
kind = "audio"
def __init__(self, track):
super().__init__() # don't forget this!
self.track = track
async def recv(self):
frame = await self.track.recv()
audio_buffer.write(frame)
return frame
def start_messaging_thread():
message_thread = threading.Thread(target=thread_queue_channel_send)
message_thread.start()
def start_transcription_thread(max_threads: int):
for i in range(max_threads):
t_thread = threading.Thread(target=get_transcription)
t_thread.start()
async def offer(request: requests.Request):
params = await request.json()
offer = RTCSessionDescription(sdp=params["sdp"], type=params["type"])
pc = RTCPeerConnection()
pc_id = "PeerConnection(%s)" % uuid.uuid4()
pcs.add(pc)
def log_info(msg: str, *args):
LOGGER.info(pc_id + " " + msg, *args)
log_info("Created for " + request.remote)
@pc.on("datachannel")
def on_datachannel(channel):
global data_channel, start_time
data_channel = channel
channel_log(channel, "-", "created by remote party")
start_time = datetime.datetime.now()
@channel.on("message")
def on_message(message: str):
channel_log(channel, "<", message)
if isinstance(message, str) and message.startswith("ping"):
# reply
channel.send("pong" + message[4:])
@pc.on("connectionstatechange")
async def on_connectionstatechange():
log_info("Connection state is " + pc.connectionState)
if pc.connectionState == "failed":
await pc.close()
pcs.discard(pc)
@pc.on("track")
def on_track(track):
log_info("Track " + track.kind + " received")
pc.addTrack(AudioStreamTrack(relay.subscribe(track)))
# handle offer
await pc.setRemoteDescription(offer)
# send answer
answer = await pc.createAnswer()
await pc.setLocalDescription(answer)
return web.Response(
content_type="application/json",
text=json.dumps({
"sdp": pc.localDescription.sdp,
"type": pc.localDescription.type
}),
)
async def on_shutdown(app: web.Application):
coros = [pc.close() for pc in pcs]
await asyncio.gather(*coros)
pcs.clear()
if __name__ == "__main__":
app = web.Application()
app.on_shutdown.append(on_shutdown)
start_transcription_thread(6)
app.router.add_post("/offer", offer)
web.run_app(
app, access_log=None, host="127.0.0.1", port=1250
)

View File

@@ -1,57 +0,0 @@
import requests
import spacy
# Enter the Machine where the LLM is hosted
LLM_MACHINE_IP = ""
# This is the URL of text-generation-webui
URL = f"http://{LLM_MACHINE_IP}:5000/api/v1/generate"
headers = {
"Content-Type": "application/json"
}
def split_text_file(filename, token_count):
nlp = spacy.load('en_core_web_md')
with open(filename, 'r') as file:
text = file.read()
doc = nlp(text)
total_tokens = len(doc)
parts = []
start_index = 0
while start_index < total_tokens:
end_index = start_index + token_count
part_tokens = doc[start_index:end_index - 5]
part = ' '.join(token.text for token in part_tokens)
parts.append(part)
start_index = end_index
return parts
final_summary = ""
parts = split_text_file("transcript.txt", 1600)
for part in parts:
prompt = f"""
### Human:
Given the following text, distill the most important information
into a short summary: {part}
### Assistant:
"""
data = {
"prompt": prompt
}
try:
response = requests.post(URL, headers=headers, json=data)
print(response.json())
except Exception as e:
print(str(e))
with open("summary.txt", "w") as sum:
sum.write(" ".join(final_summary))

View File

@@ -1,43 +0,0 @@
import torch
from transformers import BertTokenizer, BertModel
from sentence_transformers import SentenceTransformer
from sklearn.metrics.pairwise import cosine_similarity
# Load the pre-trained BERT model and tokenizer
model_name = "bert-base-uncased"
model = BertModel.from_pretrained(model_name)
tokenizer = BertTokenizer.from_pretrained(model_name)
# Set the device to use
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model.to(device)
# Load the SentenceTransformer model
sentence_transformer_model = SentenceTransformer('average_word_embeddings_glove.6B.300d')
# Define the input text
text = "Your input text to be summarized goes here."
# Tokenize the text
tokens = tokenizer.tokenize(text)
input_ids = tokenizer.convert_tokens_to_ids(tokens)
input_ids = torch.tensor([input_ids]).to(device)
# Get the BERT model output
with torch.no_grad():
outputs = model(input_ids)[0] # Extract the last hidden states
# Calculate sentence embeddings
sentence_embeddings = outputs.mean(dim=1).squeeze().cpu().numpy()
input_text_embedding = sentence_transformer_model.encode([text])[0]
# Calculate cosine similarity between sentences and input text
similarity_scores = cosine_similarity([input_text_embedding], sentence_embeddings)
# Sort the sentences by similarity scores in descending order
sorted_sentences = [sent for _, sent in sorted(zip(similarity_scores[0], sentences), reverse=True)]
# Choose the top sentences as the summary
num_summary_sentences = 2 # Adjust as needed
summary = ". ".join(sorted_sentences[:num_summary_sentences])
print("Summary:", summary)

View File

@@ -1,79 +0,0 @@
"""
This is an example code containing the bare essentials to load a chat
LLM and infer from it using a predefined prompt. The purpose of this file
is to show an example of inferring from a chat LLM which is required for
banana.dev due to its design and platform limitations
"""
# The following logic was tested on the monadical-ml machine
import json
import torch
from transformers import (
AutoModelForCausalLM,
AutoTokenizer
)
from transformers.generation import GenerationConfig
# This can be passed via the environment variable or the params supplied
# when starting the program via banana.dev platform
MODEL_NAME = "lmsys/vicuna-13b-v1.5"
# Load the model in half precision, and less memory usage
model = AutoModelForCausalLM.from_pretrained(MODEL_NAME,
low_cpu_mem_usage=True,
torch_dtype=torch.bfloat16
)
# Generation config
model.config.max_new_tokens = 300
gen_cfg = GenerationConfig.from_model_config(model.config)
gen_cfg.max_new_tokens = 300
# Load the tokenizer
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
# Move model to GPU
model = model.cuda()
print(f"Loading {MODEL_NAME} successful")
# Inputs
sample_chunks = [
"You all just came off of your incredible Google Cloud next conference where you released a wide variety of functionality and features and new products across artisan television and also across the entire sort of cloud ecosystem . You want to just first by walking through , first start by walking through all the innovations that you sort of released and what you 're excited about when you come to Google Cloud ? Now our vision is super simple . If you look at what smartphones did for a consumer , you know they took a computer and internet browser , a communication device , and a camera , and made it so that it 's in everybody 's pocket , so it really brought computation to every person . We feel that , you know , our , what we 're trying to do is take all the technological innovation that Google 's doing , but make it super simple so that everyone can consume it . And so that includes our global data center footprint , all the new types of hardware and large-scale systems we work on , the software that we 're making available for people to do high-scale computation , tools for data processing , tools for cybersecurity , processing , tools for cyber security , tools for machine learning , but make it so simple that everyone can use it . And every step that we do to simplify things for people , we think adoption can grow . And so that 's a lot of what we 've done these last three , four years , and we made a number of announcements that next in machine learning and AI in particular , you know , we look at our work as four elements , how we take our large-scale compute systems that were building for AI and how we make that available to everybody . Second , what we 're doing with the software stacks and top of it , things like jacks and other things and how we 're making those available to everybody . Third is advances because different people have different levels of expertise . Some people say I need the hardware to build my own large language model or algorithm . Other people say , look , I really need to use a building block . You guys give me . So , 30s we 've done a lot with AutoML and we announce new capability for image , video , and translation to make it available to everybody . And then lastly , we 're also building completely packaged solutions for some areas and we announce some new stuff . ",
" We 're joined next by Thomas Curian , CEO of Google Cloud , and Alexander Wang , CEO and founder of Scale AI . Thomas joined Google in November 2018 as the CEO of Google Cloud . Prior to Google , Thomas spent 22 years at Oracle , where most recently he was president of product development . Before that , Thomas worked at McKinsey as a business analyst and engagement manager . His nearly 30 years of experience have given him a deep knowledge of engineering enterprise relationships and leadership of large organizations . Thomas 's degrees include an MBA in administration and management from Stanford University , as an RJ Miller scholar and a BSEE in electrical engineering and computer science from Princeton University , where he graduated suma cum laude . Thomas serves as a member of the Stanford graduate School of Business Advisory Council and Princeton University School of Engineering Advisory Council . Please welcome to the stage , Thomas Curian and Alexander Wang . This is a super exciting conversation . Thanks for being here , Thomas ."]
# Model Prompt template for current model
prompt = f"""
### Human:
Create a JSON object as response.The JSON object must have 2 fields:
i) title and ii) summary.For the title field,generate a short title
for the given text. For the summary field, summarize the given text
in three sentences.
{sample_chunks[0]}
### Assistant:
"""
# Inference : Chat generation
input_ids = tokenizer.encode(prompt, return_tensors='pt').to(model.device)
output = model.generate(input_ids, generation_config=gen_cfg)
# Process output
response = tokenizer.decode(output[0].cpu(), skip_special_tokens=True)
response = response.split("### Assistant:\n")
print("TitleSummaryJsonResponse :", json.loads(response[1]))
print("Inference successful")
# Sample response for sample_chunks[0]
# TitleSummaryJsonResponse :
# {
# 'title': 'Google Cloud Next Conference: Simplifying AI and Machine Learning for Everyone',
# 'summary': 'Google Cloud announced a wide range of innovations and new products in the AI
# and machine learning space at the recent Google Cloud Next conference. The goal
# is to make these technologies accessible to everyone by simplifying the process
# and providing tools for data processing, cybersecurity, and machine learning.
# Google is also working on advances in AutoML and packaged solutions for certain areas.'
# }

View File

@@ -1,101 +0,0 @@
# Approach 1
from transformers import GPTNeoForCausalLM, GPT2Tokenizer
model_name = 'EleutherAI/gpt-neo-1.3B'
tokenizer = GPT2Tokenizer.from_pretrained(model_name)
model = GPTNeoForCausalLM.from_pretrained(model_name)
conversation = """
Summarize the following conversation in 3 key sentences:
We 're joined next by Thomas Curian , CEO of Google Cloud , and Alexander Wang , CEO and founder of Scale AI .
Thomas joined Google in November 2018 as the CEO of Google Cloud . Prior to Google , Thomas spent 22 years at Oracle , where most recently he was president of product development .
Before that , Thomas worked at McKinsey as a business analyst and engagement manager . His nearly 30 years of experience have given him a deep knowledge of engineering enterprise relationships and leadership of large organizations .
Thomas 's degrees include an MBA in administration and management from Stanford University , as an RJ Miller scholar and a BSEE in electrical engineering and computer science from Princeton University , where he graduated suma cum laude .
Thomas serves as a member of the Stanford graduate School of Business Advisory Council and Princeton University School of Engineering Advisory Council .
Please welcome to the stage , Thomas Curian and Alexander Wang . This is a super exciting conversation . Thanks for being here , Thomas .
"""
input_ids = tokenizer.encode(conversation, return_tensors='pt')
output = model.generate(input_ids,
max_length=30,
num_return_sequences=1)
caption = tokenizer.decode(output[0], skip_special_tokens=True)
print("Caption:", caption[len(input_ids):])
# Approach 2
import torch
from transformers import GPT2LMHeadModel, GPT2Tokenizer
model_name = "gpt2"
tokenizer = GPT2Tokenizer.from_pretrained(model_name)
model = GPT2LMHeadModel.from_pretrained(model_name)
model.eval()
text = """
You all just came off of your incredible Google Cloud next conference where you released a wide variety of functionality and features and new products across artisan television and also across the entire sort of cloud ecosystem . You want to just first by walking through , first start by walking through all the innovations that you sort of released and what you 're excited about when you come to Google Cloud ? Now our vision is super simple . If you look at what smartphones did for a consumer , you know they took a computer and internet browser , a communication device , and a camera , and made it so that it 's in everybody 's pocket , so it really brought computation to every person . We feel that , you know , our , what we 're trying to do is take all the technological innovation that Google 's doing , but make it super simple so that everyone can consume it . And so that includes our global data center footprint , all the new types of hardware and large-scale systems we work on , the software that we 're making available for people to do high-scale computation , tools for data processing , tools for cybersecurity , processing , tools for cyber security , tools for machine learning , but make it so simple that everyone can use it . And every step that we do to simplify things for people , we think adoption can grow . And so that 's a lot of what we 've done these last three , four years , and we made a number of announcements that next in machine learning and AI in particular , you know , we look at our work as four elements , how we take our large-scale compute systems that were building for AI and how we make that available to everybody . Second , what we 're doing with the software stacks and top of it , things like jacks and other things and how we 're making those available to everybody . Third is advances because different people have different levels of expertise . Some people say I need the hardware to build my own large language model or algorithm . Other people say , look , I really need to use a building block . You guys give me . So , 30s we 've done a lot with AutoML and we announce new capability for image , video , and translation to make it available to everybody . And then lastly , we 're also building completely packaged solutions for some areas and we announce some new stuff . "
"""
tokenizer.pad_token = tokenizer.eos_token
input_ids = tokenizer.encode(text,
max_length=100,
truncation=True,
return_tensors="pt")
attention_mask = torch.ones(input_ids.shape, dtype=torch.long)
output = model.generate(input_ids,
max_new_tokens=20,
num_return_sequences=1,
num_beams=2,
attention_mask=attention_mask)
chapter_titles = [tokenizer.decode(output[i], skip_special_tokens=True) for i in range(output.shape[0])]
for i, title in enumerate(chapter_titles):
print("Caption: ", title)
# Approach 3
import torch
from transformers import GPT2LMHeadModel, GPT2Tokenizer
def generate_response(conversation, max_length=100):
input_text = ""
for entry in conversation:
role = entry["role"]
content = entry["content"]
input_text += f"{role}: {content}\n"
# Tokenize the entire conversation
input_ids = tokenizer.encode(input_text, return_tensors="pt")
# Generate text based on the entire conversation
with torch.no_grad():
output = model.generate(input_ids, pad_token_id=tokenizer.eos_token_id)
# Decode the generated text and return it
response = tokenizer.decode(output[0], skip_special_tokens=True)
return response
if __name__ == "__main__":
# Call appropriate approach from the main while experimenting
model_name = "gpt2"
model = GPT2LMHeadModel.from_pretrained(model_name)
tokenizer = GPT2Tokenizer.from_pretrained(model_name)
sample_chunks = [
"You all just came off of your incredible Google Cloud next conference where you released a wide variety of functionality and features and new products across artisan television and also across the entire sort of cloud ecosystem . You want to just first by walking through , first start by walking through all the innovations that you sort of released and what you 're excited about when you come to Google Cloud ? Now our vision is super simple . If you look at what smartphones did for a consumer , you know they took a computer and internet browser , a communication device , and a camera , and made it so that it 's in everybody 's pocket , so it really brought computation to every person . We feel that , you know , our , what we 're trying to do is take all the technological innovation that Google 's doing , but make it super simple so that everyone can consume it . And so that includes our global data center footprint , all the new types of hardware and large-scale systems we work on , the software that we 're making available for people to do high-scale computation , tools for data processing , tools for cybersecurity , processing , tools for cyber security , tools for machine learning , but make it so simple that everyone can use it . And every step that we do to simplify things for people , we think adoption can grow . And so that 's a lot of what we 've done these last three , four years , and we made a number of announcements that next in machine learning and AI in particular , you know , we look at our work as four elements , how we take our large-scale compute systems that were building for AI and how we make that available to everybody . Second , what we 're doing with the software stacks and top of it , things like jacks and other things and how we 're making those available to everybody . Third is advances because different people have different levels of expertise . Some people say I need the hardware to build my own large language model or algorithm . Other people say , look , I really need to use a building block . You guys give me . So , 30s we 've done a lot with AutoML and we announce new capability for image , video , and translation to make it available to everybody . And then lastly , we 're also building completely packaged solutions for some areas and we announce some new stuff . "
]
conversation = [
{"role": "system", "content": "Summarize this text"},
{"role": "user", "content": " text : " + sample_chunks[0]},
]
response = generate_response(conversation)
print("Response:", response)

View File

@@ -1,157 +0,0 @@
import spacy
import sys
# Observe the incremental summaries by performing summaries in chunks
with open("transcript.txt", "r", encoding="utf-8") as file:
transcription = file.read()
def split_text_file(filename, token_count):
nlp = spacy.load('en_core_web_md')
with open(filename, 'r', encoding="utf-8") as file:
text = file.read()
doc = nlp(text)
total_tokens = len(doc)
parts = []
start_index = 0
while start_index < total_tokens:
end_index = start_index + token_count
part_tokens = doc[start_index:end_index]
part = ' '.join(token.text for token in part_tokens)
parts.append(part)
start_index = end_index
return parts
# Set the chunk length here to split the transcript and test
MAX_CHUNK_LENGTH = 1000
chunks = split_text_file("transcript.txt", MAX_CHUNK_LENGTH)
print("Number of chunks", len(chunks))
# Write chunks to file to refer to input vs output, separated by blank lines
with open("chunks" + str(MAX_CHUNK_LENGTH) + ".txt", "a", encoding="utf-8") as file:
for c in chunks:
file.write(c + "\n\n")
# If we want to run only a certain model, type the option while running
# ex. python incsum.py 1 => will run approach 1
# If no input, will run all approaches
try:
index = sys.argv[1]
except:
index = None
# Approach 1 : facebook/bart-large-cnn
if index == "1" or index is None:
SUMMARY_MODEL = "facebook/bart-large-cnn"
MIN_LENGTH = 5
MAX_LENGTH = 10
BEAM_SIZE = 2
print("Performing chunk summary : " + SUMMARY_MODEL)
from transformers import BartTokenizer, BartForConditionalGeneration
tokenizer = BartTokenizer.from_pretrained(SUMMARY_MODEL)
model = BartForConditionalGeneration.from_pretrained(SUMMARY_MODEL)
summaries = []
for c in chunks:
input_ids = tokenizer.encode(c,
truncation=True,
max_length=MAX_CHUNK_LENGTH,
padding="max_length",
return_tensors='pt')
summary_ids = model.generate(
input_ids,
num_beams=BEAM_SIZE,
max_length=56,
early_stopping=True,
length_penalty=1.0)
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
summaries.append(summary)
with open("bart-summaries.txt", "a", encoding="utf-8") as file:
for summary in summaries:
file.write(summary + "\n\n")
# Approach 2
if index == "2" or index is None:
print("Performing chunk summary : " + "gpt-neo-1.3B")
import torch
from transformers import GPTNeoForCausalLM, GPT2Tokenizer
model = GPTNeoForCausalLM.from_pretrained("EleutherAI/gpt-neo-1.3B")
tokenizer = GPT2Tokenizer.from_pretrained("EleutherAI/gpt-neo-1.3B")
tokenizer.add_special_tokens({'pad_token': '[PAD]'})
summaries = []
for c in chunks:
input_ids = tokenizer.encode(c,
truncation=True,
return_tensors='pt')
input_length = input_ids.shape[1]
attention_mask = torch.ones(input_ids.shape, dtype=torch.long)
max_summary_length = 100
max_length = input_length + max_summary_length
output = model.generate(input_ids,
max_length=max_length,
attention_mask=attention_mask,
pad_token_id=model.config.eos_token_id,
num_beams=4,
length_penalty=2.0,
early_stopping=True)
summary_ids = output[0, input_length:]
summary = tokenizer.decode(summary_ids, skip_special_tokens=True)
summaries.append(summary)
with open("gptneo1.3B-summaries.txt", "a", encoding="utf-8") as file:
file.write(summary + "\n\n")
# Approach 3
if index == "3" or index is None:
print("Performing chunk summary : " + "mpt-7B")
import torch
import transformers
from transformers import AutoTokenizer
config = transformers.AutoConfig.from_pretrained('mosaicml/mpt-7b',
trust_remote_code=True)
config.attn_config['attn_impl'] = 'triton'
config.max_seq_len = 1024
config.init_device = "meta"
model = transformers.AutoModelForCausalLM.from_pretrained(
'mosaicml/mpt-7b',
trust_remote_code=True,
torch_dtype=torch.bfloat16
)
tokenizer = AutoTokenizer.from_pretrained('EleutherAI/gpt-neox-20b')
summaries = []
for c in chunks:
input_ids = tokenizer.encode(c, return_tensors="pt")
attention_mask = torch.ones(input_ids.shape, dtype=torch.long)
output = model.generate(input_ids,
max_new_tokens=25,
attention_mask=attention_mask,
pad_token_id=model.config.eos_token_id,
num_return_sequences=1)
summary = tokenizer.decode(output[0],
skip_special_tokens=True)
summaries.append(summary)
with open("mpt-7b-summaries.txt", "a", encoding="utf-8") as file:
for summary in summaries:
file.write(summary + "\n\n")

View File

@@ -1,37 +0,0 @@
# Use OpenAI API endpoint to send data to OpenAI
# along with prompts to caption/summarize the conversation
import openai
openai.api_key = ""
# to caption, user prompt used : "caption this conversation"
# max_tokens=20
# to incremental summarize, user prompt used : "summarize this conversation in a few sentences by taking key points"
# max_tokens=300
sample_chunks = [
"You all just came off of your incredible Google Cloud next conference where you released a wide variety of functionality and features and new products across artisan television and also across the entire sort of cloud ecosystem . You want to just first by walking through , first start by walking through all the innovations that you sort of released and what you 're excited about when you come to Google Cloud ? Now our vision is super simple . If you look at what smartphones did for a consumer , you know they took a computer and internet browser , a communication device , and a camera , and made it so that it 's in everybody 's pocket , so it really brought computation to every person . We feel that , you know , our , what we 're trying to do is take all the technological innovation that Google 's doing , but make it super simple so that everyone can consume it . And so that includes our global data center footprint , all the new types of hardware and large-scale systems we work on , the software that we 're making available for people to do high-scale computation , tools for data processing , tools for cybersecurity , processing , tools for cyber security , tools for machine learning , but make it so simple that everyone can use it . And every step that we do to simplify things for people , we think adoption can grow . And so that 's a lot of what we 've done these last three , four years , and we made a number of announcements that next in machine learning and AI in particular , you know , we look at our work as four elements , how we take our large-scale compute systems that were building for AI and how we make that available to everybody . Second , what we 're doing with the software stacks and top of it , things like jacks and other things and how we 're making those available to everybody . Third is advances because different people have different levels of expertise . Some people say I need the hardware to build my own large language model or algorithm . Other people say , look , I really need to use a building block . You guys give me . So , 30s we 've done a lot with AutoML and we announce new capability for image , video , and translation to make it available to everybody . And then lastly , we 're also building completely packaged solutions for some areas and we announce some new stuff . ",
" We 're joined next by Thomas Curian , CEO of Google Cloud , and Alexander Wang , CEO and founder of Scale AI . Thomas joined Google in November 2018 as the CEO of Google Cloud . Prior to Google , Thomas spent 22 years at Oracle , where most recently he was president of product development . Before that , Thomas worked at McKinsey as a business analyst and engagement manager . His nearly 30 years of experience have given him a deep knowledge of engineering enterprise relationships and leadership of large organizations . Thomas 's degrees include an MBA in administration and management from Stanford University , as an RJ Miller scholar and a BSEE in electrical engineering and computer science from Princeton University , where he graduated suma cum laude . Thomas serves as a member of the Stanford graduate School of Business Advisory Council and Princeton University School of Engineering Advisory Council . Please welcome to the stage , Thomas Curian and Alexander Wang . This is a super exciting conversation . Thanks for being here , Thomas ."]
conversation = [
{"role": "system",
"content": sample_chunks[1]},
{"role": "user",
"content": "summarize this conversation in a few sentences by taking key points"}
]
model = "gpt-3.5-turbo"
response = openai.ChatCompletion.create(model=model,
messages=conversation,
n=1,
max_tokens=300)
# Try fine tuned model
# model = "davinci:ft-personal-2023-07-14-10-43-51"
# response = openai.Completion.create(model=model,
# prompt=sample_chunks[0] + " -> ")
caption = response.choices[0]
print(caption)

View File

@@ -1,33 +0,0 @@
from transformers import PegasusForConditionalGeneration, PegasusTokenizer
import torch
# Load the Pegasus model and tokenizer
model_name = "google/pegasus-large"
model = PegasusForConditionalGeneration.from_pretrained(model_name)
tokenizer = PegasusTokenizer.from_pretrained(model_name)
# Set the device to use
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model.to(device)
sample_chunks = ["You all just came off of your incredible Google Cloud next conference where you released a wide variety of functionality and features and new products across artisan television and also across the entire sort of cloud ecosystem . You want to just first by walking through , first start by walking through all the innovations that you sort of released and what you 're excited about when you come to Google Cloud ? Now our vision is super simple . If you look at what smartphones did for a consumer , you know they took a computer and internet browser , a communication device , and a camera , and made it so that it 's in everybody 's pocket , so it really brought computation to every person . We feel that , you know , our , what we 're trying to do is take all the technological innovation that Google 's doing , but make it super simple so that everyone can consume it . And so that includes our global data center footprint , all the new types of hardware and large-scale systems we work on , the software that we 're making available for people to do high-scale computation , tools for data processing , tools for cybersecurity , processing , tools for cyber security , tools for machine learning , but make it so simple that everyone can use it . And every step that we do to simplify things for people , we think adoption can grow . And so that 's a lot of what we 've done these last three , four years , and we made a number of announcements that next in machine learning and AI in particular , you know , we look at our work as four elements , how we take our large-scale compute systems that were building for AI and how we make that available to everybody . Second , what we 're doing with the software stacks and top of it , things like jacks and other things and how we 're making those available to everybody . Third is advances because different people have different levels of expertise . Some people say I need the hardware to build my own large language model or algorithm . Other people say , look , I really need to use a building block . You guys give me . So , 30s we 've done a lot with AutoML and we announce new capability for image , video , and translation to make it available to everybody . And then lastly , we 're also building completely packaged solutions for some areas and we announce some new stuff . ",
" We 're joined next by Thomas Curian , CEO of Google Cloud , and Alexander Wang , CEO and founder of Scale AI . Thomas joined Google in November 2018 as the CEO of Google Cloud . Prior to Google , Thomas spent 22 years at Oracle , where most recently he was president of product development . Before that , Thomas worked at McKinsey as a business analyst and engagement manager . His nearly 30 years of experience have given him a deep knowledge of engineering enterprise relationships and leadership of large organizations . Thomas 's degrees include an MBA in administration and management from Stanford University , as an RJ Miller scholar and a BSEE in electrical engineering and computer science from Princeton University , where he graduated suma cum laude . Thomas serves as a member of the Stanford graduate School of Business Advisory Council and Princeton University School of Engineering Advisory Council . Please welcome to the stage , Thomas Curian and Alexander Wang . This is a super exciting conversation . Thanks for being here , Thomas ."]
# Define the input text for summarization
text = sample_chunks[1]
inputs = tokenizer(text, truncation=True, padding="longest", return_tensors="pt").to(device)
# Generate the summary
summary_ids = model.generate(
inputs["input_ids"],
attention_mask=inputs["attention_mask"],
max_length=200,
num_beams=4,
length_penalty=2.0,
early_stopping=True,
)
# Decode and print the summary
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
print("Summary:", summary)

View File

@@ -1,27 +0,0 @@
from transformers import T5ForConditionalGeneration, T5Tokenizer
import torch
# Load the T5 model and tokenizer
model_name = "t5-base"
model = T5ForConditionalGeneration.from_pretrained(model_name)
tokenizer = T5Tokenizer.from_pretrained(model_name)
# Set the device to use
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model.to(device)
sample_chunks = ["You all just came off of your incredible Google Cloud next conference where you released a wide variety of functionality and features and new products across artisan television and also across the entire sort of cloud ecosystem . You want to just first by walking through , first start by walking through all the innovations that you sort of released and what you 're excited about when you come to Google Cloud ? Now our vision is super simple . If you look at what smartphones did for a consumer , you know they took a computer and internet browser , a communication device , and a camera , and made it so that it 's in everybody 's pocket , so it really brought computation to every person . We feel that , you know , our , what we 're trying to do is take all the technological innovation that Google 's doing , but make it super simple so that everyone can consume it . And so that includes our global data center footprint , all the new types of hardware and large-scale systems we work on , the software that we 're making available for people to do high-scale computation , tools for data processing , tools for cybersecurity , processing , tools for cyber security , tools for machine learning , but make it so simple that everyone can use it . And every step that we do to simplify things for people , we think adoption can grow . And so that 's a lot of what we 've done these last three , four years , and we made a number of announcements that next in machine learning and AI in particular , you know , we look at our work as four elements , how we take our large-scale compute systems that were building for AI and how we make that available to everybody . Second , what we 're doing with the software stacks and top of it , things like jacks and other things and how we 're making those available to everybody . Third is advances because different people have different levels of expertise . Some people say I need the hardware to build my own large language model or algorithm . Other people say , look , I really need to use a building block . You guys give me . So , 30s we 've done a lot with AutoML and we announce new capability for image , video , and translation to make it available to everybody . And then lastly , we 're also building completely packaged solutions for some areas and we announce some new stuff . ",
" We 're joined next by Thomas Curian , CEO of Google Cloud , and Alexander Wang , CEO and founder of Scale AI . Thomas joined Google in November 2018 as the CEO of Google Cloud . Prior to Google , Thomas spent 22 years at Oracle , where most recently he was president of product development . Before that , Thomas worked at McKinsey as a business analyst and engagement manager . His nearly 30 years of experience have given him a deep knowledge of engineering enterprise relationships and leadership of large organizations . Thomas 's degrees include an MBA in administration and management from Stanford University , as an RJ Miller scholar and a BSEE in electrical engineering and computer science from Princeton University , where he graduated suma cum laude . Thomas serves as a member of the Stanford graduate School of Business Advisory Council and Princeton University School of Engineering Advisory Council . Please welcome to the stage , Thomas Curian and Alexander Wang . This is a super exciting conversation . Thanks for being here , Thomas ."]
# Define the input text for summarization
text = "Summarize the following text in 3 key points. text : " + sample_chunks[1]
# Tokenize the input text
inputs = tokenizer.encode(text, return_tensors="pt").to(device)
# Generate the summary
summary_ids = model.generate(inputs, max_length=1000, num_beams=4, early_stopping=True)
# Decode and print the summary
summary = tokenizer.decode(summary_ids.squeeze(), skip_special_tokens=True)
print("Summary:", summary)

File diff suppressed because one or more lines are too long

View File

@@ -1,44 +0,0 @@
from gpt4all import GPT4All
model = GPT4All("/Users/gokulmohanarangan/Library/Application Support/nomic.ai/GPT4All/ggml-vicuna-13b-1.1-q4_2.bin")
import spacy
def split_text_file(filename, token_count):
nlp = spacy.load('en_core_web_md')
with open(filename, 'r') as file:
text = file.read()
doc = nlp(text)
total_tokens = len(doc)
parts = []
start_index = 0
while start_index < total_tokens:
end_index = start_index + token_count
part_tokens = doc[start_index:end_index]
part = ' '.join(token.text for token in part_tokens)
parts.append(part)
start_index = end_index
return parts
parts = split_text_file("transcript.txt", 1800)
final_summary = []
for part in parts:
prompt = f"""
### Human:
Summarize the following text without missing any key points and action items.
{part}
### Assistant:
"""
output = model.generate(prompt)
final_summary.append(output)
with open("sum.txt", "w") as sum:
sum.write(" ".join(final_summary))

View File

@@ -1,8 +0,0 @@
AGENDA: Most important things to look for in a start up
TAM: Make sure the market is sufficiently large than once they win they can get rewarded
Product market fit: Being in a good market with a product than can satisfy that market
Unit economics: Profit for delivering all-in cost must be attractive (% or $ amount)
LTV CAC: Life-time value (revenue contribution) vs cost to acquire customer must be healthy
Churn: Fits into LTV, low churn leads to higher LTV and helps keep future CAC down
Business: Must have sufficient barriers to entry to ward off copy-cats once established
Founders: Must be religious about their product. Believe they will change the world against all odds.

View File

@@ -1,183 +0,0 @@
#!/usr/bin/env python3
# summarize https://www.youtube.com/watch?v=imzTxoEDH_g
# summarize https://www.sprocket.org/video/cheesemaking.mp4 summary.txt
# summarize podcast.mp3 summary.txt
import argparse
import os
import re
import subprocess
import tempfile
from datetime import datetime
from urllib.parse import urlparse
import jax.numpy as jnp
import moviepy.editor
import nltk
import yt_dlp as youtube_dl
from whisper_jax import FlaxWhisperPipline
from ...utils.file_utils import download_files, upload_files
from ...utils.log_utils import LOGGER
from ...utils.run_utils import CONFIG
from ...utils.text_utils import post_process_transcription, summarize
from ...utils.viz_utils import create_talk_diff_scatter_viz, create_wordcloud
nltk.download('punkt', quiet=True)
nltk.download('stopwords', quiet=True)
WHISPER_MODEL_SIZE = CONFIG['WHISPER']["WHISPER_MODEL_SIZE"]
NOW = datetime.now()
if not os.path.exists('../../artefacts'):
os.makedirs('../../artefacts')
def init_argparse() -> argparse.ArgumentParser:
"""
Parse the CLI arguments
:return: parser object
"""
parser = argparse.ArgumentParser(
usage="%(prog)s [OPTIONS] <LOCATION> <OUTPUT>",
description="Creates a transcript of a video or audio file, then"
" summarizes it using ChatGPT."
)
parser.add_argument("-l", "--language",
help="Language that the summary should be written in",
type=str,
default="english",
choices=['english', 'spanish', 'french', 'german',
'romanian'])
parser.add_argument("location")
return parser
def main():
parser = init_argparse()
args = parser.parse_args()
# Parse the location string that was given to us, and figure out if it's a
# local file (audio or video), a YouTube URL, or a URL referencing an
# audio or video file.
url = urlparse(args.location)
# S3 : Pull artefacts to S3 bucket ?
media_file = ""
if url.scheme == 'http' or url.scheme == 'https':
# Check if we're being asked to retreive a YouTube URL, which is
# handled differently, as we'll use a secondary site to download
# the video first.
if re.search('youtube.com', url.netloc, re.IGNORECASE):
# Download the lowest resolution YouTube video
# (since we're just interested in the audio).
# It will be saved to the current directory.
LOGGER.info("Downloading YouTube video at url: " + args.location)
# Create options for the download
ydl_opts = {
'format': 'bestaudio/best',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}],
'outtmpl': './artefacts/audio', # Specify output file path and name
}
# Download the audio
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download([args.location])
media_file = "../artefacts/audio.mp3"
LOGGER.info("Saved downloaded YouTube video to: " + media_file)
else:
# XXX - Download file using urllib, check if file is
# audio/video using python-magic
LOGGER.info(f"Downloading file at url: {args.location}")
LOGGER.info(" XXX - This method hasn't been implemented yet.")
elif url.scheme == '':
media_file = url.path
# If file is not present locally, take it from S3 bucket
if not os.path.exists(media_file):
download_files([media_file])
if media_file.endswith(".m4a"):
subprocess.run(["ffmpeg", "-i", media_file, f"./artefacts/{media_file}.mp4"])
media_file = f"./artefacts/{media_file}.mp4"
else:
print("Unsupported URL scheme: " + url.scheme)
quit()
# Handle video
if not media_file.endswith(".mp3"):
try:
video = moviepy.editor.VideoFileClip(media_file)
audio_filename = tempfile.NamedTemporaryFile(suffix=".mp3",
delete=False).name
video.audio.write_audiofile(audio_filename, logger=None)
LOGGER.info(f"Extracting audio to: {audio_filename}")
# Handle audio only file
except Exception:
audio = moviepy.editor.AudioFileClip(media_file)
audio_filename = tempfile.NamedTemporaryFile(suffix=".mp3",
delete=False).name
audio.write_audiofile(audio_filename, logger=None)
else:
audio_filename = media_file
LOGGER.info("Finished extracting audio")
LOGGER.info("Transcribing")
# Convert the audio to text using the OpenAI Whisper model
pipeline = FlaxWhisperPipline("openai/whisper-" + WHISPER_MODEL_SIZE,
dtype=jnp.float16,
batch_size=16)
whisper_result = pipeline(audio_filename, return_timestamps=True)
LOGGER.info("Finished transcribing file")
whisper_result = post_process_transcription(whisper_result)
transcript_text = ""
for chunk in whisper_result["chunks"]:
transcript_text += chunk["text"]
with open("./artefacts/transcript_" + NOW.strftime("%m-%d-%Y_%H:%M:%S") +
".txt", "w") as transcript_file:
transcript_file.write(transcript_text)
with open("./artefacts/transcript_with_timestamp_" +
NOW.strftime("%m-%d-%Y_%H:%M:%S") + ".txt",
"w") as transcript_file_timestamps:
transcript_file_timestamps.write(str(whisper_result))
LOGGER.info("Creating word cloud")
create_wordcloud(NOW)
LOGGER.info("Performing talk-diff and talk-diff visualization")
create_talk_diff_scatter_viz(NOW)
# S3 : Push artefacts to S3 bucket
prefix = "./artefacts/"
suffix = NOW.strftime("%m-%d-%Y_%H:%M:%S")
files_to_upload = [prefix + "transcript_" + suffix + ".txt",
prefix + "transcript_with_timestamp_" + suffix + ".txt",
prefix + "df_" + suffix + ".pkl",
prefix + "wordcloud_" + suffix + ".png",
prefix + "mappings_" + suffix + ".pkl",
prefix + "scatter_" + suffix + ".html"]
upload_files(files_to_upload)
summarize(transcript_text, NOW, False, False)
LOGGER.info("Summarization completed")
# Summarization takes a lot of time, so do this separately at the end
files_to_upload = [prefix + "summary_" + suffix + ".txt"]
upload_files(files_to_upload)
if __name__ == "__main__":
main()

View File

@@ -1,151 +0,0 @@
#!/usr/bin/env python3
import time
import wave
from datetime import datetime
import jax.numpy as jnp
import pyaudio
from pynput import keyboard
from termcolor import colored
from whisper_jax import FlaxWhisperPipline
from ...utils.file_utils import upload_files
from ...utils.log_utils import LOGGER
from ...utils.run_utils import CONFIG
from ...utils.text_utils import post_process_transcription, summarize
from ...utils.viz_utils import create_talk_diff_scatter_viz, create_wordcloud
WHISPER_MODEL_SIZE = CONFIG['WHISPER']["WHISPER_MODEL_SIZE"]
FRAMES_PER_BUFFER = 8000
FORMAT = pyaudio.paInt16
CHANNELS = 2
RATE = 96000
RECORD_SECONDS = 15
NOW = datetime.now()
def main():
p = pyaudio.PyAudio()
AUDIO_DEVICE_ID = -1
for i in range(p.get_device_count()):
if p.get_device_info_by_index(i)["name"] == \
CONFIG["AUDIO"]["BLACKHOLE_INPUT_AGGREGATOR_DEVICE_NAME"]:
AUDIO_DEVICE_ID = i
audio_devices = p.get_device_info_by_index(AUDIO_DEVICE_ID)
stream = p.open(
format=FORMAT,
channels=CHANNELS,
rate=RATE,
input=True,
frames_per_buffer=FRAMES_PER_BUFFER,
input_device_index=int(audio_devices['index'])
)
pipeline = FlaxWhisperPipline("openai/whisper-" +
CONFIG["WHISPER"]["WHISPER_REAL_TIME_MODEL_SIZE"],
dtype=jnp.float16,
batch_size=16)
transcription = ""
TEMP_AUDIO_FILE = "temp_audio.wav"
global proceed
proceed = True
def on_press(key):
if key == keyboard.Key.esc:
global proceed
proceed = False
transcript_with_timestamp = {"text": "", "chunks": []}
last_transcribed_time = 0.0
listener = keyboard.Listener(on_press=on_press)
listener.start()
print("Attempting real-time transcription.. Listening...")
try:
while proceed:
frames = []
start_time = time.time()
for i in range(0, int(RATE / FRAMES_PER_BUFFER * RECORD_SECONDS)):
data = stream.read(FRAMES_PER_BUFFER,
exception_on_overflow=False)
frames.append(data)
end_time = time.time()
wf = wave.open(TEMP_AUDIO_FILE, 'wb')
wf.setnchannels(CHANNELS)
wf.setsampwidth(p.get_sample_size(FORMAT))
wf.setframerate(RATE)
wf.writeframes(b''.join(frames))
wf.close()
whisper_result = pipeline(TEMP_AUDIO_FILE, return_timestamps=True)
timestamp = whisper_result["chunks"][0]["timestamp"]
start = timestamp[0]
end = timestamp[1]
if end is None:
end = start + 15.0
duration = end - start
item = {'timestamp': (last_transcribed_time,
last_transcribed_time + duration),
'text': whisper_result['text'],
'stats': (str(end_time - start_time), str(duration))
}
last_transcribed_time = last_transcribed_time + duration
transcript_with_timestamp["chunks"].append(item)
transcription += whisper_result['text']
print(colored("<START>", "yellow"))
print(colored(whisper_result['text'], 'green'))
print(colored("<END> Recorded duration: " +
str(end_time - start_time) +
" | Transcribed duration: " +
str(duration), "yellow"))
except Exception as exception:
print(str(exception))
finally:
with open("real_time_transcript_" + NOW.strftime("%m-%d-%Y_%H:%M:%S")
+ ".txt", "w", encoding="utf-8") as file:
file.write(transcription)
with open("real_time_transcript_with_timestamp_" +
NOW.strftime("%m-%d-%Y_%H:%M:%S") + ".txt", "w",
encoding="utf-8") as file:
transcript_with_timestamp["text"] = transcription
file.write(str(transcript_with_timestamp))
transcript_with_timestamp = \
post_process_transcription(transcript_with_timestamp)
LOGGER.info("Creating word cloud")
create_wordcloud(NOW, True)
LOGGER.info("Performing talk-diff and talk-diff visualization")
create_talk_diff_scatter_viz(NOW, True)
# S3 : Push artefacts to S3 bucket
suffix = NOW.strftime("%m-%d-%Y_%H:%M:%S")
files_to_upload = ["real_time_transcript_" + suffix + ".txt",
"real_time_transcript_with_timestamp_" + suffix + ".txt",
"real_time_df_" + suffix + ".pkl",
"real_time_wordcloud_" + suffix + ".png",
"real_time_mappings_" + suffix + ".pkl",
"real_time_scatter_" + suffix + ".html"]
upload_files(files_to_upload)
summarize(transcript_with_timestamp["text"], NOW, True, True)
LOGGER.info("Summarization completed")
# Summarization takes a lot of time, so do this separately at the end
files_to_upload = ["real_time_summary_" + suffix + ".txt"]
upload_files(files_to_upload)
if __name__ == "__main__":
main()