Files
digital-forensics-lab/AI4Forensics/CKIM2024/HillaryEmails/email_analysis_summarization.ipynb
2024-05-31 11:08:35 -04:00

574 lines
38 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# pip -q install google-generativeai==0.3.0\n",
"# pip -q install google-ai-generativelanguage==0.4.0\n",
"# pip install python-dotenv\n",
"# pip install --upgrade langchain\n",
"# pip -q install langchain_experimental langchain_core\n",
"# pip -q install langchain-google-genai\n",
"# pip show langchain langchain-core\n",
"# pip install python-pptxy\n",
"\n",
"\n",
"import numpy as np\n",
"import os\n",
"import re\n",
"import datetime\n",
"import time\n",
"import tenacity\n",
"import argparse\n",
"import configparser\n",
"import json\n",
"import tiktoken\n",
"import jieba\n",
"from collections import namedtuple\n",
"\n",
"# setup\n",
"import google.generativeai as genai\n",
"\n",
"from IPython.display import display\n",
"from IPython.display import Markdown\n",
"\n",
"import os\n",
"from dotenv import load_dotenv\n",
"\n",
"# Load environment variables from the .env file\n",
"load_dotenv(\"my_config.env\")\n",
"\n",
"# Access the environment variables\n",
"GOOGLE_AI_STUDIO = os.getenv(\"GOOGLE_AI_STUDIO2\")\n",
"genai.configure(api_key=GOOGLE_AI_STUDIO )"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# Set up the model\n",
"generation_config = {\n",
" \"temperature\": 0.0,\n",
" \"top_p\": 1,\n",
" \"top_k\": 32,\n",
" \"max_output_tokens\": 4096,\n",
"}\n",
"\n",
"safety_settings = [\n",
" {\"category\": \"HARM_CATEGORY_HARASSMENT\", \"threshold\": \"BLOCK_NONE\"},\n",
" {\"category\": \"HARM_CATEGORY_HATE_SPEECH\", \"threshold\": \"BLOCK_NONE\"},\n",
" {\"category\": \"HARM_CATEGORY_SEXUALLY_EXPLICIT\", \"threshold\": \"BLOCK_NONE\"},\n",
" {\"category\": \"HARM_CATEGORY_DANGEROUS_CONTENT\", \"threshold\": \"BLOCK_NONE\"},\n",
"]"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# read a paper\n",
"from langchain_google_genai import ChatGoogleGenerativeAI\n",
"from langchain.prompts import ChatPromptTemplate\n",
"from langchain_core.output_parsers import StrOutputParser\n",
"\n",
"model = ChatGoogleGenerativeAI(\n",
" model=\"gemini-pro\",\n",
" safety_settings=safety_settings,\n",
" generation_config=generation_config,\n",
" google_api_key=GOOGLE_AI_STUDIO,\n",
")\n",
"\n",
"\n",
"template = \"\"\" \n",
"{role}\\\n",
"{provided_data}\\\n",
"{start} \n",
"\"\"\"\n",
"prompt = ChatPromptTemplate.from_template(template)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The provided email does not contain any information related to Israel.\n",
"The email does not contain any information or requests pertaining to Israel.\n",
"No information related to Israel or Israeli affairs was found in the provided email.\n",
"12:30 Israeli PM Netanyahu\n",
"- Dennis Ross recently visited Israel and will share information with the recipient before upcoming meetings.\n",
"There is no mention of Israel or Israeli in the email provided.\n",
"This email does not contain any information related to Israel.\n",
"This email does not contain any information related to Israel or Israelis.\n",
"**Subject:** The Vice President's Residence\n",
"\n",
"**Date:** N/A\n",
"\n",
"**Summary:**\n",
"\n",
"- 9:00 am: Bilateral meeting with Israeli President Shimon Peres at the Omni Shoreham Hotel.\n",
"The provided email does not contain any information related to Israel or Israeli.\n",
"This email does not mention Israel or Israeli-related topics.\n",
"This email does not contain any information related to Israel or Israeli.\n",
"No information related to Israel or Israeli is present in the provided email.\n",
"In a discussion about arrangements on settlements with Israel, two options are presented:\n",
"\n",
"1. Describe it as an agreement, which would raise concerns about legitimizing Israeli activity in the West Bank and triggering complaints from Arabs and Palestinians.\n",
"\n",
"2. The administration could acknowledge progress made, express differences with the Israeli government on their intention to complete housing units, and stress that substantial progress warrants the resumption of peace talks and Arab steps toward Israel for a two-state solution. This option maintains credibility and allows for forward movement.\n",
"- Israel strongly expressed to the US their concern about a potential UNGA vote on the peace process.\n",
"- George Mitchell, the US Special Envoy for Middle East Peace, reported this concern to Hillary Clinton and President Obama.\n",
"- Mitchell planned to inform Rahm Emanuel, White House Chief of Staff, and Dan Shapiro, US Ambassador to Israel, about Israel's position.\n",
"The provided email does not contain any information related to Israel or Israelis.\n",
"Sure, here is a concise summary of the email you provided, focusing on Israel-related information:\n",
"\n",
"**Email Summary**\n",
"\n",
"**From:** Hillary Clinton\n",
"**To:** N/A\n",
"**Date:** N/A\n",
"**Subject:** N/A\n",
"**Israel-Related Information:**\n",
"\n",
"- Phone call with Israeli Foreign Minister Avigdor Lieberman scheduled for 2:15pm.\n",
"This email does not contain any information related to Israel.\n",
"The email does not contain any information related to Israel or Israeli.\n",
"I cannot find any information about Israel in the provided email.\n",
"There is no mention of Israel or Israeli in the provided text.\n",
"**Summary:**\n",
"\n",
"* Statement regarding Israel-Palestinian conflict to be released in sender's name.\n",
"* Statement supports good-faith negotiations for a two-state solution.\n",
"* Palestinian goal: Independent state based on 1967 lines with agreed swaps.\n",
"* Israeli goal: Jewish state with secure borders reflecting subsequent developments and meeting security requirements.\n",
"* Commitment to achieving a two-state solution with peace and security is unwavering.\n",
"The email you provided does not contain any specific information or requests related to Israel. Therefore, I cannot provide a summary of this email.\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Retrying langchain_google_genai.chat_models._chat_with_retry.<locals>._chat_with_retry in 2.0 seconds as it raised ResourceExhausted: 429 Resource has been exhausted (e.g. check quota)..\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"This email does not contain any information related to Israel.\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Retrying langchain_google_genai.chat_models._chat_with_retry.<locals>._chat_with_retry in 4.0 seconds as it raised ResourceExhausted: 429 Resource has been exhausted (e.g. check quota)..\n",
"Retrying langchain_google_genai.chat_models._chat_with_retry.<locals>._chat_with_retry in 8.0 seconds as it raised ResourceExhausted: 429 Resource has been exhausted (e.g. check quota)..\n",
"Retrying langchain_google_genai.chat_models._chat_with_retry.<locals>._chat_with_retry in 2.0 seconds as it raised ResourceExhausted: 429 Resource has been exhausted (e.g. check quota)..\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"- 2:00pm SECURE CALL w/ISRAELI PM BINYAMIN NETANYAHU\n",
"- 2:30pm PHONE CALL w/ISRAELI DEFENSE MINISTER EHUD BARAK\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Retrying langchain_google_genai.chat_models._chat_with_retry.<locals>._chat_with_retry in 4.0 seconds as it raised ResourceExhausted: 429 Resource has been exhausted (e.g. check quota)..\n",
"Retrying langchain_google_genai.chat_models._chat_with_retry.<locals>._chat_with_retry in 8.0 seconds as it raised ResourceExhausted: 429 Resource has been exhausted (e.g. check quota)..\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"This email does not contain any information related to Israel or Israeli.\n",
"The provided email doesn't contain any information related to Israel or Israeli.\n",
"This email does not contain any information related to Israel.\n",
"No information related to Israel found in the provided email content.\n",
"**Summary:**\n",
"\n",
"On October 28, 2009, Palau and Israel joined the United States in voting against a UN resolution calling for an end to the US embargo on Cuba.\n",
"On Friday, Steinberg reportedly reprimanded Israeli Ambassador to the US Michael Oren over the country's conduct during Vice President Biden's visit.\n",
"This email does not pertain to Israel.\n",
"The email does not contain any information related to Israel.\n",
"No relevant information about Israel was included in the provided email.\n",
"FYI. Israelis spinning up a storm, starting with plane briefing on the way over.\n",
"The provided article does not contain any emails, therefore I cannot extract the requested information.\n",
"This email does not contain any information related to Israel or Israeli.\n",
"The email does not contain any information related to Israel, so I cannot provide a summary.\n",
"No information related to Israel or Israelis was found in the provided email.\n",
"The provided email does not contain any information or requests related to Israel or Israeli affairs.\n",
"I'm sorry, but the provided text does not contain any emails from Hillary Clinton's private email server or any information related to Israel. Please provide the relevant emails for me to process.\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Retrying langchain_google_genai.chat_models._chat_with_retry.<locals>._chat_with_retry in 2.0 seconds as it raised ResourceExhausted: 429 Resource has been exhausted (e.g. check quota)..\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Error processing line: (\"Below is the final text of the Quartet statement, which Lavrov, Ban, and Ashton have now agreed to release *without a\\ncall.* Sounds like your discussion with Lavrov did the trick:\\nThe Quartet re-affirms that the current situation in Gaza, including the humanitarian and human rights situation of the\\ncivilian population, is unsustainable, unacceptable, and not in the interests of any of those concerned. The Quartet\\nreiterates its call for a solution that addresses Israel's legitimate security concerns, including an end to weapons\\nsmuggling into Gaza; promotes Palestinian unity based on the Palestine Liberation Organization commitments and the\\nreunification of Gaza and the West Bank under the legitimate Palestinian Authority; and ensures the unimpeded flow of\\nhumanitarian aid, commercial goods and persons to and from Gaza, consistent with United Nations Security Council\\nresolution 1860 (2009). The Quartet declares its readiness to work closely with Israel, the Palestinian Government and\\ninternational donors in order to achieve sustainable economic development on the basis of the full implementation of\\nthe Agreement on Access and Movement of 2005 and in the broader perspective of the two-state solution.\\nConsistent with these objectives, the Quartet and the Quartet Representative have worked with Israel, as well as\\nconsulting the Palestinian Authority, Egypt, and other concerned parties, to effect a fundamental change in policy in\\nGaza. The new policy towards Gaza just announced by the Government of Israel is a welcome development. The Quartet\\nnotes that the elaboration of further details and modalities of implementation will be important in ensuring the\\neffectiveness of the new policy. Full and effective implementation will comprise a significant shift in strategy towards\\nmeeting the needs of Gaza's population for humanitarian and commercial goods, civilian reconstruction and\\ninfrastructure, and legitimate economic activity as well as the security needs of Israel. The Quartet will continue to work\\nwith Israel, the Palestinian Authority, and other concerned parties to ensure these arrangements are implemented as\\nquickly as possible. The Quartet affirms that much work remains to achieve fully the solution stated above, and, in\\nconsultation with the concerned parties, it will monitor closely the implementation of the policy in all its aspects. It will\\nactively explore additional ways to improve the situation in Gaza, encourage involvement of the PA at the crossings and\\npromote greater commerce between the West Bank and Gaza.\\nThe Quartet stresses the importance of United Nations and other international interventions, as well as the work of local\\nnon-governmental organizations, to be expanded in Gaza to meet urgent civilian needs, and calls on all parties to fully\\nenable this work.\\nThe Quartet recognizes that Israel has legitimate security concerns that must continue to be safeguarded, and believes\\nefforts to maintain security while enabling movement and access for Palestinian people and goods are critical. The\\nQuartet commits to work with Israel and the international community to prevent the illicit trafficking of arms and\\nammunition into Gaza. It urges all those wishing to deliver goods to do so through established channels so that their\\ncargo can be inspected and transferred via land crossings into Gaza. The Quartet emphasizes that there is no need for\\nunnecessary confrontations and calls on all parties to act responsibly in meeting the needs of the people of Gaza.\\nThe Quartet also calls for an end to the deplorable detention of Gilad Shalit in advance of the fourth anniversary of his\\ncapture on June 25; it further condemns the violation of Hamas' international obligation to provide him access by the\\nInternational Committee of the Red Cross and demands that Hamas immediately remedy the situation.\\nThe Quartet also reiterates its support for proximity talks toward the resumption, without pre-conditions, of direct\\nbilateral negotiations that resolve all final status issues as previously agreed by the parties. The Quartet believes these\\nnegotiations should lead to a settlement, negotiated between the parties within 24 months, that ends the occupation\\nwhich began in 1967 and results in the emergence of an independent, democratic, and viable Palestinian state in the\\nWest Bank and Gaza, living side by side in peace and security with Israel and its other neighbours.\",)\n",
"finish_reason: RECITATION\n",
"index: 0\n",
"\n",
"This email does not contain any information related to Israel or Israelis.\n",
"This email does not contain any information related to Israel.\n",
"This email discusses Israel's settlement freeze and construction in the West Bank. Key points include:\n",
"\n",
"- Ongoing construction in Israeli settlement of Har Homa exposes Netanyahu's settlement freeze as an illusion.\n",
"- Right-wing parties in Israel's coalition government are pressuring Netanyahu to block the renewal of the settlement freeze policy, which is set to expire on September 26.\n",
"- Israeli Minister of Public Affairs and the Diaspora Yuli Edelstein stated that the settlement freeze should be lifted and construction resumed, as \"It's our land anyway!\"\n",
"- Construction of new settlement units in Har Homa, just days after Netanyahu announced the freeze in November 2009, shows that Netanyahu authorized the building of new settlement units.\n",
"This email does not contain any information related to Israel.\n",
"This email discusses a leaked poll regarding American perceptions of the Israeli operation against the Gaza Flotilla. The poll found that:\n",
"- 56% of Americans agree there is a humanitarian crisis in Gaza.\n",
"- 43% of Americans agree that people in Gaza are starving.\n",
"- 34% of Americans support the Israeli operation against the Flotilla.\n",
"- 20% of Americans felt support for Israel following the announcement of easing the Gaza closure.\n",
"**Email Summary Related to Israel:**\n",
"\n",
"**Subject:** SECURITY COUNCIL PRESIDENTIAL STATEMENT ON THE RECENT INCIDENT IN THE EASTERN MEDITERRANEAN\n",
"\n",
"**Summary:**\n",
"\n",
"* The Security Council condemns Israel's military actions against the Gaza-bound convoy.\n",
"* The Council demands immediate release of the ships and civilians detained by Israel.\n",
"* The Council urges Israel to allow consular access, repatriation of casualties, and delivery of humanitarian aid.\n",
"* The Council calls for a prompt and impartial investigation into the incident.\n",
"* The Council stresses the need to alleviate the humanitarian crisis in Gaza and facilitate regular movement of goods and people.\n",
"* The Council emphasizes the importance of a two-state solution to the Israeli-Palestinian conflict.\n",
"* The Council urges restraint and cooperation between the parties and international partners.\n",
"The email you provided does not contain any information related to Israel or Israelis.\n",
"This email does not contain any information related to Israel or Israeli affairs.\n",
"- Israel disputes the Obama administration's claim that the US warned Israeli officials to exercise caution and restraint while intercepting the flotilla.\n",
"- Israel's Ambassador to the US, Michael B. Oren, has denied receiving any such contact from the US administration and is seeking clarification.\n",
"Sorry, but the provided email does not contain any content related to Israel or Israeli.\n",
"The provided text does not contain any emails. Therefore, I cannot extract the requested information.\n",
"There is no mention of Israel or Israeli in the email you provided.\n",
"I'm sorry but this email does not contain information related to Israel.\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Retrying langchain_google_genai.chat_models._chat_with_retry.<locals>._chat_with_retry in 2.0 seconds as it raised ResourceExhausted: 429 Resource has been exhausted (e.g. check quota)..\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"I'm sorry, but the provided text does not contain any emails. It only includes an article that analyzes the Israeli media's coverage of the Gaza Freedom Flotilla raid. Therefore, I cannot extract the requested information from the provided context.\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Retrying langchain_google_genai.chat_models._chat_with_retry.<locals>._chat_with_retry in 4.0 seconds as it raised ResourceExhausted: 429 Resource has been exhausted (e.g. check quota)..\n",
"Retrying langchain_google_genai.chat_models._chat_with_retry.<locals>._chat_with_retry in 8.0 seconds as it raised ResourceExhausted: 429 Resource has been exhausted (e.g. check quota)..\n",
"Retrying langchain_google_genai.chat_models._chat_with_retry.<locals>._chat_with_retry in 16.0 seconds as it raised ResourceExhausted: 429 Resource has been exhausted (e.g. check quota)..\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"The provided email does not mention anything related to Israel and therefore I cannot extract the requested information.\n",
"This email contains no information related to Israel.\n",
"This email does not contain any information related to Israel or Israelis.\n",
"The provided email does not contain any information related to Israel or Israelis.\n",
"This email does not mention anything about Israel or Israeli, so I cannot extract the requested information.\n",
"This email does not contain any information related to Israel or Israeli matters.\n",
"Sorry, but the provided text does not contain any emails for analysis. I cannot extract the requested information from the provided context.\n",
"No information related to Israel or Israelis was found in the provided email.\n",
"There is no mention of Israel or Israeli affairs in the provided email.\n",
"The provided email does not contain any information related to Israel.\n",
"Error processing line: ('You may have been alerted to this incident: the barring of Noam Chomsky from Israel. His political views may be\\nridiculous or objectionable, though he is the greatest linguistic scholar in the world, but barring him for his political opinions\\nhas created a needless PR disaster, not least for the US, as he is, after all, a US citizen, and a very prominent one\\ninternationally. It is unfortunate on every level. And the US should not be a passive onlooker. He is a US citizen barred for\\nhis political views, after all. This story is splashed across the European press this morning. Not what anyone needs, yes,\\nyes, like a hole in the head, and bone stupid, but the US effort on his behalf to gain entry should be part of the story. This\\nincident can be profitable if Israel understands it should not be doing this to US or European critics in the future. This is a\\ndownward slope, bad news for everyone involved. S\\n14 16, 2010, 11:01 pm\\nChomsky Barred From West Bank by Israel\\nBy ROBERT MACKEY\\nNoam Chomsky, an American linguist and political thinker who has been critical of Israel, was denied entry into the West\\nBank on Sunday by Israeli immigration officials when he tried to cross into the Palestinian territory from Jordan to deliver a\\nlecture.\\nAmira Hass of the Israeli newspaper Haaretz reported:\\nNo reason was initially given for the decision, but the Interior Ministry later said immigration officials at the Allenby Bridge\\nborder crossing from Jordan had misunderstood Chomsky\\'s intentions thinking initially he was also due to visit Israel.\\nChomsky, who is on a speaking tour in the region, was scheduled to speak at Bir Zeit University in the West Bank on\\nMonday.\\nA spokeswoman for Israel\\'s interior ministry also told Reuters that there had been a misunderstanding and \"officials were\\ntrying to get clearance from the Israeli military, which controls access to the West Bank to allow Chomsky to enter.\"\\nIn a television interview from Amman, Jordan, after he was rebuffed, Mr. Chomsky told Al Jazeera English, \"the facts were\\ncompletely clear to everyone; there was no basis for a misunderstanding.\" He explained that he was interrogated for\\nseveral hours before being told that he would not be allowed to cross into the occupied Palestinian territory. The 81-year-\\nold scholar added:\\nI can only say what was conveyed to me in the discussion with the official who was carrying out the interrogation — he\\nwas receiving instructions from the [Israeli] ministry of interior and relaying them. There were two basic points. One was\\nthat the government of Israel does not like the kinds of things I say — which puts them into the category of I suppose\\nevery other government in the world. The second was that they seemed upset about the fact that I was just taking an\\ninvitation from Bir Zeit and I had no plans to go on to speak in Israeli universities, as I have done many times in the past\\nbut not this time.\\nMr. Chomsky had been invited to speak about American foreign and domestic policy by the philosophy department at the\\nPalestinian university in Ramallah.\\nThe renowned linguist was outspoken in his opposition to the Israeli offensive in Gaza, which ended in January 2009 and\\nhas criticized Israel\\'s occupation of Palestinian territory many times.\\nIn an interview with Deborah Solomon of The New York Times Magazine in 2003, Mr. Chomsky said, \"I objected to the\\nfounding of Israel as a Jewish state. I don\\'t think a Jewish or Christian or Islamic state is a proper concept. I would object\\nto the United States as a Christian state.\" When Ms. Solomon pressed Mr. Chomsky on his opposition to Israel, saying,\\n\"Your father was a respected Hebraic scholar, and sometimes you sound like a self-hating Jew,\" he replied:\\nIt is a shame that critics of Israeli policies are seen as either anti-Semites or self-hating Jews. It\\'s grotesque. If an Italian\\ncriticized Italian policies, would he be seen as a self-hating Italian?\\n• Copyright 2010 The New York Times Company\\n• Privacy Policy\\n• NYTimes.com 620 Eighth Avenue New York, NY 10018',)\n",
"finish_reason: RECITATION\n",
"index: 0\n",
"\n",
"There is no mention of Israel in the provided text.\n",
"- Request to discuss the situation in Israel and trip cancellation;\n",
"- Sender is flexible with timing;\n",
"- Phil Gordon and Jeff Feltman are monitoring the situation;\n",
"- No formal talking points available at the time of the email.\n",
"No information related to Israel was found in this email.\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Retrying langchain_google_genai.chat_models._chat_with_retry.<locals>._chat_with_retry in 2.0 seconds as it raised ResourceExhausted: 429 Resource has been exhausted (e.g. check quota)..\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"This email does not contain any information related to Israel or Israelis.\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Retrying langchain_google_genai.chat_models._chat_with_retry.<locals>._chat_with_retry in 4.0 seconds as it raised ResourceExhausted: 429 Resource has been exhausted (e.g. check quota)..\n",
"Retrying langchain_google_genai.chat_models._chat_with_retry.<locals>._chat_with_retry in 8.0 seconds as it raised ResourceExhausted: 429 Resource has been exhausted (e.g. check quota)..\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"This email does not contain any information related to Israel or Israeli, so I cannot provide a summary.\n",
"The provided email does not contain any information related to Israel or Israeli.\n",
"I apologize, but the provided email does not contain any information related to Israel, so I cannot provide a summary.\n",
"This email does not contain any information related to Israel or Israeli.\n",
"This email does not contain any information related to Israel or Israeli.\n",
"The provided email does not contain any information related to Israel or Israeli.\n",
"There is no mention of Israel or Israeli affairs in the provided email.\n",
"**Date:** Not specified\n",
"\n",
"**Subject:** Not specified\n",
"\n",
"**Summary:** This email contains details of a scheduled trilateral meeting between Secretary Clinton, Israeli Prime Minister Binyamin Netanyahu, and Palestinian National Authority President Mahmoud Abbas at 10:00 am, followed by a bilateral meeting at 11:30 am.\n",
"This email does not mention Israel or Israeli and is therefore not relevant to your query.\n",
"**Summary:**\n",
"\n",
"The email discusses the cancellation of a joint interview with Israeli and Palestinian media outlets. The sender objects to the cancellation, citing the following concerns:\n",
"\n",
"* High expectations for the interview, and cancellation would be perceived negatively.\n",
"* Cancellation would contribute to a negative narrative in Israeli media.\n",
"* Potential for negative symbolism by canceling on the Israeli media outlet, Channel 2.\n",
"\n",
"The sender suggests offering Channel 2 an exclusive interview in Jerusalem in two weeks as a way to mitigate the consequences of cancellation.\n",
"The context provided does not mention anything about Israel, so I cannot extract the requested information.\n",
"- 9:15 am: Joint taped interview with Udi Segal, Israeli Channel 2\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Retrying langchain_google_genai.chat_models._chat_with_retry.<locals>._chat_with_retry in 2.0 seconds as it raised ResourceExhausted: 429 Resource has been exhausted (e.g. check quota)..\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"The provided email does not contain any information related to Israel.\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Retrying langchain_google_genai.chat_models._chat_with_retry.<locals>._chat_with_retry in 4.0 seconds as it raised ResourceExhausted: 429 Resource has been exhausted (e.g. check quota)..\n",
"Retrying langchain_google_genai.chat_models._chat_with_retry.<locals>._chat_with_retry in 8.0 seconds as it raised ResourceExhausted: 429 Resource has been exhausted (e.g. check quota)..\n",
"Retrying langchain_google_genai.chat_models._chat_with_retry.<locals>._chat_with_retry in 16.0 seconds as it raised ResourceExhausted: 429 Resource has been exhausted (e.g. check quota)..\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"The provided text does not contain any emails.\n",
"No mention of Israel or Israeli in the provided email.\n",
"This email does not contain any information related to Israel.\n",
"This email does not contain any information related to Israel or any Israeli.\n",
"There is no information about Israel in the provided email.\n",
"There is no mention of Israel or Israeli in the provided email content.\n",
"- Anne-Marie Slaughter has attached a paper by Louise Diamond, an expert on psychology and negotiations who has done a lot of work between Israel and the Palestinians.\n",
"- Slaughter recommends watching a video produced by a Rand study called The Arc, which proposes a high-speed road/rail project connecting the key cities in the West Bank and Gaza.\n",
"The provided email does not contain any information related to Israel or Israeli.\n",
"The provided email does not contain any information related to Israel or Israeli.\n",
"This email does not contain any information related to Israel or Israeli.\n",
"There is no mention of Israel in the provided email.\n",
"No information related to Israel is present in this email.\n",
"I am unable to provide a summary since the email you sent does not mention Israel.\n",
"This email does not contain any information related to Israel.\n",
"The provided email does not contain any information related to Israel or Israelis.\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Retrying langchain_google_genai.chat_models._chat_with_retry.<locals>._chat_with_retry in 2.0 seconds as it raised ResourceExhausted: 429 Resource has been exhausted (e.g. check quota)..\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"No information related to Israel or Israeli was found in the provided email.\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Retrying langchain_google_genai.chat_models._chat_with_retry.<locals>._chat_with_retry in 4.0 seconds as it raised ResourceExhausted: 429 Resource has been exhausted (e.g. check quota)..\n",
"Retrying langchain_google_genai.chat_models._chat_with_retry.<locals>._chat_with_retry in 8.0 seconds as it raised ResourceExhausted: 429 Resource has been exhausted (e.g. check quota)..\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"This email does not contain any information related to Israel or Israelis.\n",
"This email does not contain any information related to Israel or Israeli affairs.\n",
"This email does not relate to Israel.\n",
"There is no mention of Israel in the provided email.\n",
"This email does not contain any data on Israel\n",
"This email is not related to Israel or Israeli.\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Retrying langchain_google_genai.chat_models._chat_with_retry.<locals>._chat_with_retry in 2.0 seconds as it raised ResourceExhausted: 429 Resource has been exhausted (e.g. check quota)..\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"This email does not contain any information related to Israel or Israeli.\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Retrying langchain_google_genai.chat_models._chat_with_retry.<locals>._chat_with_retry in 4.0 seconds as it raised ResourceExhausted: 429 Resource has been exhausted (e.g. check quota)..\n",
"Retrying langchain_google_genai.chat_models._chat_with_retry.<locals>._chat_with_retry in 8.0 seconds as it raised ResourceExhausted: 429 Resource has been exhausted (e.g. check quota)..\n",
"Retrying langchain_google_genai.chat_models._chat_with_retry.<locals>._chat_with_retry in 16.0 seconds as it raised ResourceExhausted: 429 Resource has been exhausted (e.g. check quota)..\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"The provided email does not contain any information related to Israel.\n",
"The provided text does not contain any mention of Israel or Israeli-related issues, so I cannot extract the requested summary.\n",
"No information relevant to Israel or Israeli is found in this email.\n",
"This email does not contain any information related to Israel or Israelis.\n",
"**Summary:**\n",
"\n",
"* Israel Prime Minister Netanyahu is in a strong political position with a stable ruling coalition.\n",
"* Netanyahu could have extended the settlement freeze before its expiry to support US peacemaking efforts, but chose not to.\n",
"* Netanyahu is concerned about keeping Lieberman in the government to prevent him from garnering support from the right-wing.\n",
"* Kadima leader Tzipi Livni is willing to bring her party into the government without demanding rotation if Netanyahu is serious about negotiating peace.\n",
"* Netanyahu's negotiating tactics are self-defeating and contribute to distrust on the Palestinian side.\n",
"* Israeli public is ready for a peace deal; failure to make a serious move will further delegitimize Israel internationally.\n",
"* Yuval Diskin, former head of Shin Bet, warns that Palestinian security motivation may disappear if Netanyahu does not quickly demonstrate seriousness to Abu Mazen.\n",
"The provided context does not contain any emails related to Israel. Therefore, I cannot extract the requested information.\n",
"The email does not mention Israel or any Israeli figures.\n",
"This email does not contain any information related to Israel or Israeli.\n",
"- Jake suggests a condolence call to Netanyahu and offering assistance.\n",
"- About forty people died due to a forest fire in northern Israel.\n",
"No information related to Israel is present in the provided email.\n",
"9:00 am Secretary's Conference Room\n",
"MEETING w/ISRAELI CHIEF NEGOTIATOR YITZHAK MOLHO\n",
"Results have been saved to results_email_summary.txt\n"
]
}
],
"source": [
"output_parser = StrOutputParser()\n",
"chain = prompt | model | output_parser\n",
"\n",
"with open(r\".\\role_email_summarization.txt\", \"r\") as file:\n",
" role = file.read()\n",
"\n",
"# Open the email_israel.txt file and read each line\n",
"with open(r\".\\email_israel.txt\", \"r\") as file:\n",
" provided_data_lines = file.readlines()\n",
"\n",
"# Open the start.txt file and read its content\n",
"with open(r\".\\start_email_summarization.txt\", \"r\") as file:\n",
" start = file.read()\n",
"\n",
"# Initialize a list to store the results\n",
"results = []\n",
"\n",
"# Process each line from the email_israel.txt file\n",
"# Open a new file to save the results\n",
"with open(r\".\\results_email_summary.txt\", \"w\") as result_file:\n",
" # Process each line from the email_israel.txt file\n",
" for line in provided_data_lines:\n",
" try:\n",
" result = chain.invoke(\n",
" {\n",
" \"role\": role,\n",
" \"provided_data\": line.strip(),\n",
" \"start\": start,\n",
" }\n",
" )\n",
" print(result)\n",
" # Write the result to the results file\n",
" if \"not contain any\" not in result:\n",
" result_file.write(result + \"\\n\")\n",
" except Exception as e:\n",
" # Print the error message and continue with the next line\n",
" print(f\"Error processing line: {line.strip()}\\n{e}\")\n",
" continue\n",
"\n",
"\n",
"print(\"Results have been saved to results_email_summary.txt\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.18"
}
},
"nbformat": 4,
"nbformat_minor": 2
}