-
Notifications
You must be signed in to change notification settings - Fork 0
/
app-test.py
96 lines (77 loc) · 19 KB
/
app-test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import pytube
import requests
import asyncio
import os
from langchain import PromptTemplate, LLMChain
from langchain.chat_models import ChatOpenAI
from bardapi import Bard
from dotenv import find_dotenv, load_dotenv
import openai
load_dotenv(find_dotenv())
openai.api_key = os.getenv("OPENAI_API_KEY")
BARD_API_KEY=os.getenv("BARD_API_KEY")
bard = Bard(token=BARD_API_KEY)
# Extract audio from YouTube
def get_audio(video_url):
# Create a PyTube object for the video.
youtube_video = pytube.YouTube(video_url)
# Get the audio stream from the video.
audio_stream = youtube_video.streams.filter(only_audio=True)
# Download the audio stream to a file.
audio_stream[0].download(output_path="audios", filename="audio.mp3")
# Audio to text
def get_text(filename):
audio_file= open(filename, "rb")
transcript = openai.Audio.transcribe("whisper-1", audio_file)
return transcript
def get_facts(transcript):
template = """
Given this text. Extract top 3 facts from it.;
CONTEXT: {transcript}
FACTS:
"""
prompt = PromptTemplate(template=template, input_variables=["transcript"])
fact_llm = LLMChain(llm=ChatOpenAI(
model_name="gpt-3.5-turbo", temperature=1), prompt=prompt, verbose=True)
facts = fact_llm.predict(transcript=transcript)
return facts
def organize_facts(facts):
# Split the input text into individual facts based on a delimiter
facts_text = facts.split("\n")
organized_facts = []
for i, fact_text in enumerate(facts_text, start=1):
organized_fact = {
"description": fact_text.strip() # Remove leading/trailing whitespaces
}
organized_facts.append(organized_fact)
return organized_facts[1:-1]
def check_facts(organized_facts):
for fact in organized_facts:
# print(f"{fact['description']}")
fact_to_check = fact['description']
query = f"""
Answer in yes or no. Check if the following statement is factually correct. Check years, names, locations, historical events, numbers, or any other named entity. {fact_to_check} ?
"""
answer = bard.get_answer(query)['content']
print (answer)
print("------")
# get_audio("https://www.youtube.com/watch?v=uAOFH62JQl0")
# transcript = get_text("audios/audio.mp3")
# print(transcript)
# transcript = "Hi, welcome to another episode of ColdFusion. Preventing a war is difficult. Hot tempers can get in the way of cool and rational reasoning, and the result of war is something that nobody wants to live through. To stop a war takes discussion and diplomacy, reason and thought. But what if a war could be stopped by just one man? A man who chose to trust his gut instead of a machine. And not just any war, but a nuclear war between the United States and Russia. In other words, this one man single-handedly stopped what would have been World War III. It sounds like something out of a science fiction movie, but one day back in 1983, this exact event happened. Stanislav Yevgrafovich Petrov, a Russian lieutenant, literally saved the world. Without him, it's possible that you wouldn't be here, and the world as we knew it could have ended on that day. So what happened on that fateful day, and what would have happened if the two superpowers nuked each other? Well, get comfortable, and get ready for an insane story. This episode truly was one of my favorites to make. You are watching ColdFusionTV. It's the 26th of September, 1983, and 44-year-old Russian military lieutenant Stanislav Petrov sits at his console. It's been a regular day so far, but suddenly, his screen lights up. It's five American nuclear missiles coming straight towards Russia. He had a choice to make. Should he pick up the phone and advise a retaliation strike against the United States? He doesn't have much time to make a decision. If he acts, America would be nuked, and a world war would erupt. If he does nothing, he risks losing his fellow countrymen's lives in a US nuclear attack. At this point, the weight of the world is on his shoulders. But we need to rewind here. How did the world get to the point of one person standing between normality and complete annihilation? Shortly after the end of the Second World War in 1945, hostility started brewing between the United States and the Soviet Union. And from 1947 onwards, the world got divided into two geopolitical blocks of power. The Eastern Bloc, led by the Soviet Union, and the Western Bloc, led by the United States. What ensued for the next couple of decades is what we call the Cold War. Though this period never had an actual war between the two countries, it was characterized by a highly intense conflict for global domination, which involved espionage and military conflict in foreign countries through proxy wars. The Korean Wars and Vietnam Wars were two such conflicts. The two global rivals competed with each other to become the leader in various aspects of science, technology, and warfare, through space exploration, nuclear development, and an arms race. While the United States had an edge in building nuclear weapons after the ending of World War II, the Soviets soon caught up. By the 1960s, the two were so much on par with each other in regards to their nuclear capabilities that they were capable of destroying each other in a nuclear war. This led to the concept of mutual assured destruction, which implied that each one's offensive weaponry surpassed the defensive capability of the other. To drive this home, in 1961, Russia tested the Tsar Bomba. It was a hydrogen bomb that was the most powerful weapon ever created. It was the equivalent of 54 megatons of TNT, or to put it another way, all the explosive power of all the bombs used in World War II at the same time, times 10. When the Russian Tsar Bomba was dropped, the flash of the blast could be seen 1,000 kilometers away, or 630 miles, and the mushroom cloud was 64 kilometers high, or 40 miles high. Villages 55 kilometers away were flattened, and damage was sustained by buildings hundreds of miles away. Radio communication was disrupted for over an hour because of the radiation. The pilots who had dropped the bomb almost lost control of their Tu-95 bomber from the shockwave blast, and this was despite being 50 kilometers or 30 miles away, and placing a parachute on the bomb so it could slowly float down to Earth while they had a chance to escape. Third-degree burns were possible from hundreds of kilometers away, and shockwaves from the blast were still being recorded on its third revolution around the Earth. It's insane to think that in the original Soviet designs, the Tsar Bomba was supposed to be twice as powerful. Needless to say, the possibility of nuclear war was always a dark dread, a dread that loomed overhead the citizens of planet Earth throughout the 60s, 70s and 80s. It was September of 1983. Tensions were running high between the East and the West. The United States was busy developing psychological warfare exercises against Moscow, and the Soviet Union was expecting that the US was going to launch an attack. And there was a reason for this. The Soviets had just shot down a Korean Airlines commercial flight that crossed into Soviet airspace, killing a congressman from Georgia among 269 passengers. Anxiety had started to mount when the flight from New York to Seoul with a stop in Anchorage wasn't heard from for several hours. Then came the unavoidable savage troop. It had disappeared from the sky itself by a heat-seeking missile fired by a Soviet Su-15 interceptor. Among those presumed dead, United States Senator Larry McDonald, and at least 30, possibly 40 other Americans, and an Australian family of four. In Washington, Secretary of State Schultz said this was no accident. President Reagan, at his Californian ranch, was said to have been briefed continually. Birds can scarcely express our revulsion at this horrifying act of violence. That Flight 7 was substantially off course and well into Soviet airspace, over some of the most sensitive and jealously guarded airspace the Soviets have. Because underneath is a nuclear submarine base, an air fighter base, and a missile testing range. From Moscow, the silence was deafening. On the early morning of the 26th of September 1983, three weeks after the downed Korean flight, the world came the closest it's ever been to ending. Lieutenant Stanislav Petrov sat down at his computer and began his shift at Serpukhov-15, a command centre stationed just outside of Moscow. He had been on his shift for a few hours, when suddenly, the ballistic missile early warning system began to sound. This alarm indicated that the Soviets' early warning satellites over the United States had detected an intercontinental ballistic missile being fired from a US base. Shocked, Petrov began to try and wrap his head around the situation of what had just happened. Suddenly, the system set off four more alarms, one after the other, implying that the United States had launched a total of five intercontinental ballistic missiles. The warning system had changed its alert from launch to missile strike, and it showed that the reliability of these warnings was at the highest level. Petrov was now truly shocked. Petrov was a critical link in the chain of decision-making on retaliation in the case of a missile strike by the US. He had studied radio engineering at a Soviet air force base in Kiev and joined the Soviet air defence forces and rose through the ranks over the years. His role now was to oversee the staff that monitored signals from the early warning satellites. There were no specific rules for deciding if a warning was a false alarm or not. It was totally dependent on Petrov and whether he decided to report to his seniors. The circumstances demanded that any early warning of a missile strike be reported promptly so that those at the highest level of command could make a decision quickly. As juniors at the station waited for Petrov to make a decision, he sat frozen in his chair and couldn't bring himself to quickly dial in a report. Once reported to his superiors, it would all be out of his hands and probably result in a nuclear strike against the United States. But doing nothing would risk his entire nation. Take a second and think to yourself, what would you do? Holding a phone in one hand and an intercom in the other, Petrov pondered over the consequences that his decision would lead to. After five minutes, he decided that the warnings from the system were false alarms and reported the same to his superiors at the headquarters. They trusted his decision and didn't order a missile strike on the US. But now Petrov had to wait. Had he made the right decision? Did his failure to act cause the death of millions? Lieutenant Petrov stressed in a sea of his own thoughts. This went on for roughly 25 minutes. He then realized that if there was an actual attack, he would have come to know within that time. The more time that passed, the more relaxed he became. Finally, he concluded he had indeed made the right decision. So how could this have happened? The false alarm was set off by primitive 80s technology. The Soviet satellites that were monitoring the incoming missiles mistakenly identified the sun's reflection off the top of clouds for a missile launch. The coding in the program was supposed to filter out such wrong stimuli, but the coders didn't do a good enough job. The code was later rewritten to avoid such dangerous incidents in the future. In interviews given during his later years, Lieutenant Petrov revealed that the early warning system of the Soviets had been introduced in haste as the United States had launched a similar system. And because of this, he didn't consider the system 100% reliable and believed that humans, being the creator of such computer systems, were wiser than them. The critical decision was taken based purely on a guess. Quote, I had a funny feeling in my gut, he told the Washington Post. He explains that it originated from his skepticism of the early warning system and the realization that if the US was indeed going to attack, it wouldn't just fire five missiles. So what would have happened if the US did retaliate? If Petrov had chosen to interpret the warnings as a real attack in 1983, the Soviets may have launched a fierce attack on the United States, leading to a retaliation from the US, ending in mutual annihilation for both nations. A 1979 study by the US Office of Technology Assessment states the following, A nuclear war between the US and Soviet Union would cause around 35 to 77% of the population of the United States to have been wiped out, and the Soviets would have lost 20 to 40% of its population. Any war between the two nations would have inevitably led to their allies getting involved, leading to a third world war. So what would a nuclear bomb do to a city? A 10 kiloton bomb, detonated on the ground of Times Square in New York, would explode with a flash so bright that it would briefly blind people for hundreds of miles. A massive fireball with core temperatures running at millions of degrees would immediately erupt. Everyone and everything within 100 feet of the blast would be completely annihilated. A one mile radius would be charred, and a 500 mile an hour pressure wave would expand out, destroying everything in its path. And all of this would happen within a few seconds of the blast. Radioactive particle dust would be spread and scattered all over the city. People exposed to this dust would suffer from acute radiation syndrome, showing early symptoms such as dizziness, nausea, headaches and vomiting within a matter of hours. This would be followed by symptoms such as fever, seizures, diarrhea, hair loss and bleeding in the mouth and under the skin. Victims may also experience more severe symptoms over the next couple of weeks, and most of these people would eventually die. An electromagnetic pulse generated along with the blast would disable electronic devices such as computers, cell phones and communication towers up to several miles away. If more attacks are carried out, the sheer amount of smoke would block sunlight and plunge the global temperature by several degrees for years, leading to a phenomenon called nuclear winter. This may affect crops and lead to a famine. So I think we can all agree we have to say thanks to Petrov for helping us all avoid such an outcome. After the nuclear missile incident was avoided, at first Petrov was initially praised for his calm while facing an unprecedented and critical situation. But soon after this, he was investigated over the incident. Among the questions he was asked during his interrogation was, why had he failed to record everything in his logbook? To this, he famously replied that he had a phone in one hand and an intercom in the other and didn't have a third hand. He was let go with a reprimand. According to Petrov, it was just a matter of pride because he had found multiple bugs in the early warning systems and because of this, it would become unfavourable for his employers to reward him. It may also be why his story isn't widely known. Petrov was long forgotten after the incident and was reduced to growing potatoes for a living. In fact, almost nobody on earth knew about their almost destruction until 1998, when a retired commander of Soviet missile defence, Yuri V. Votinstev, had his memoir published. In the memoir, he told this story and that was the first time that this became public. And from this point, the world finally recognised what Petrov had done and lauded him for his role in averting the Third World War. In 2006, he received an award from the Association of World Citizens in the United States. In 2013, he was honoured with the Dresden Peace Prize and in 2014, a Danish documentary called The Man Who Saved the World was made about him. Petrov died at the age of 77 on May 19th, 2017 in a Moscow suburb where he lived alone on a small pension. It is a very humble end to a man who was so pivotal to world history. Again, without him, we might not be here. And I just find this story fascinating. The story of how one person changed the course of history and potentially saved millions upon millions of lives by essentially deciding to do nothing. But let's take this opportunity to collectively remind ourselves that nations going to war in this fashion is something that nobody wants. Thanks so much for watching and I hope you enjoyed the episode. I may already be at 3 million subscribers by the time this goes out, so a huge thank you to all of you who decided that you liked my videos enough to subscribe. I'm thinking of doing a live chat over at the ColdFusion Discord to celebrate. I'm sure I'll have more details on that later. I also wanted to do a quick correction on the last video. I said that a neighbourhood was bought by an investment firm, but I didn't make the distinction that that neighbourhood wasn't open for buying to the public and was intended only for wholesale. It was pointed out by some of you, so I thought I'd clear that up. Anyway, my name is Dagogo and you've been watching ColdFusion, and I'll catch you again soon for the next episode. Cheers guys. Have a good one. ColdFusion."
# facts = get_facts(transcript)
# print(facts)
facts = """
1. In 1983, Russian military lieutenant Stanislav Petrov prevented a nuclear war between the United States and Russia by not retaliating against a false alarm of American missile attacks.
2. The Cold War, which lasted from 1947 to the late 1980s, was a period of intense conflict and tension between the United States and the Soviet Union.
3. The Soviet Union and the United States engaged in an arms race and competed to become leaders in science, technology, and warfare during the Cold War.
4. The concept of mutually assured destruction, in which each country's offensive weaponry surpassed the other's defensive capabilities, characterized the nuclear threat between the United States and the Soviet Union.
5. In 1961, the Soviet Union tested the Tsar Bomba, the most powerful weapon ever created, which had an explosive power equivalent to 54 megatons of TNT.
6. A nuclear war between the United States and the Soviet Union would have caused significant casualties, with estimates suggesting that 35 to 77% of the US population and 20 to 40% of the Soviet population would have been wiped out.
7. If a 10 kiloton nuclear bomb were detonated in New York City's Times Square, it would cause immediate destruction within a one-mile radius, a pressure wave destroying everything in its path, and radioactive fallout leading to acute radiation syndrome and potential death for those exposed.
8. Petrov's decision not to retaliate against the false alarm saved countless lives and prevented a Third World War involving the allies of the two superpowers.
9. Petrov's decision was based on a gut feeling and skepticism of the early warning system, as well as the realization that a real attack would likely involve more than five missiles.
10. Despite his crucial role in preventing nuclear war, Petrov was only initially praised for his actions and was later investigated over the incident. He was eventually recognized and honored for his role in averting disaster.
"""
organized_facts = organize_facts(facts)
check_facts(organized_facts)