import openai import gradio as gr import uuid import time import IPython from playsound import playsound import threading from scipy.io import wavfile #tts = TTS(model_name="tts_models/multilingual/multi-dataset/your_tts", progress_bar=False)#.to("cuda") conv_uuid = str(uuid.uuid4()) import os # Replace with your key # openai.api_key = os.getenv('openai_api') seller_prompt_path = "./prompts/seller_prompt_no_meat.txt" extras_for_senior = """ Cybersecurity Incident: During the negotiation of the Letter of Intent, the seller disclosed that there was a breach in their customer data. Email addresses from the customer’s data that was exposed totalled no more than 200. No other personal identifiable information was exfiltrated. That client has since filed a claim requesting for compensation related to damages from this breach. TechEase has disclosed the privacy breach to its customer base, has taken remedial action to prevent another breach and correct the security weaknesses in its infrastructure, and has complied with all relevant regulatory requirements concerning the breach. """ extras_for_partner = """ Multiple Cybersecurity Breaches/Weak security infrastructure Your associate had just informed you of the current status of the deal: Quasi-fundamental reps and warranties related to cybersecurity, IP, and privacy are already set up Special indemnities are also already set up for cybersecurity and privacy TechEase has cybersecurity and privacy insurance Recently, new problems have come up with TechEase, and we need your expertise to renegotiate TechEase’s AI platform has unique product functionalities and a fast-growing customer base. Security infrastructure is not its focus. Accordingly, there are key issues to be discussed with regards to infiltrations into its system and what type of information technology security infrastructure is in place. TechEase just advised ShopMaster of multiple occurrences of prior breaches to its security infrastructure and it does not know what data, if any, was exfiltrated. Several clients have just switched to TechEase’s competitors given the historical weaknesses of its security infrastructure. Most clients, though, are still enthusiastic about continuous improvements of its core AI product. TechEase has also disclosed the security breaches to its customer base, and has taken remedial action to prevent another breach. However, TechEase does not have the talent to investigate the root causes behind multiple breaches. ShopMaster is deeply concerned and wants to drop the deal. However, ShopMaster is still interested in TechEase’s AI platform, but does not want to deal with the security issues related to the company. """ with open(seller_prompt_path, 'r') as f: seller_prompt = f.read() seller_prompt_path_markdown = "./prompts/seller_prompt_no_meat_markdown.txt" with open(seller_prompt_path_markdown, 'r') as f: seller_prompt_markdown = f.read() seller_meat_1 = "./prompts/seller_meat_1.txt" with open(seller_meat_1, 'r') as f: seller_meat_1 = f.read() seller_meat_1_markdown = "./prompts/seller_meat_1_markdown.txt" with open(seller_meat_1_markdown, 'r') as f: seller_meat_1_markdown = f.read() hint_counter = 0 initial_prompt = os.getenv("system_prompt") #def play_sound_in_background(): # playsound("output.wav") def predict(message, history, username, bdi_checkbox_value, api_box): global initial_prompt openai.api_key = api_box chatinterface.additional_inputs[0].value = username history_openai_format = [] if level_dropdown.value == 'Senior': initial_prompt += extras_for_senior elif level_dropdown.value == 'Partner': initial_prompt += extras_for_partner history_openai_format.append( {"role": "system", "content": initial_prompt.replace("Philip", name_box.value)}) for human, assistant in history: history_openai_format.append({"role": "user", "content": human}) history_openai_format.append( {"role": "assistant", "content": assistant}) history_openai_format.append({"role": "user", "content": message}) response = openai.ChatCompletion.create( model='gpt-4o', messages=history_openai_format, temperature=0.8, stream=True ) partial_message = "" print(bdi_checkbox_value) for chunk in response: if len(chunk['choices'][0]['delta']) != 0: partial_message = partial_message + \ chunk['choices'][0]['delta']['content'] user_name_no_space = username.replace(" ","_") file_name = f"{user_name_no_space}_{conv_uuid}.txt" if bdi_checkbox_value: # save user history and new text with username.txt with open(file_name, "a") as f: f.write(f"User: {message}\n") f.write(f"Assistant: {partial_message}\n") # before returning let's save an audio and play it # tts.tts_to_file(partial_message, speaker_wav="/home/hammh0a/Downloads/New Recording 2 (1).wav", language="en", file_path="output.wav") # threading.Thread(target=play_sound_in_background, args=(), daemon=True).start() # audio_button.value = "output.wav" return partial_message else: # save user history and new text with username.txt remove_bdi = partial_message.split("Response:")[-1] try: with open(file_name, "a") as f: f.write(f"User: {message}\n") f.write(f"Assistant: {partial_message}\n") except: pass # tts.tts_to_file(remove_bdi, speaker_wav="/home/hammh0a/Downloads/New Recording 2 (1).wav", language="en", file_path="output.wav") # threading.Thread(target=play_sound_in_background, args=(), daemon=True).start() # audio_button.value = "output.wav" return remove_bdi #def read_audio_again(audio_button): # return wavfile.read("output.wav") # gr.ChatInterface(predict).queue().launch() def vote(data: gr.LikeData): if data.liked: print("You upvoted this response: " + data.value) else: print("You downvoted this response: " + data.value) def update_name(name): # This function will be called when the user types in the name_box return name negotiation_areas = { "Junior": "(1) Defining type of representations and warranties (fundamental, general and possibly quasi). \n(2) [More Advanced, Second-Layer Negotiation]:Setting parameters of liability. \n(3)Survival period, cap on liability, and basket.", "Senior": "(1) Mitigation of the incident (i.e. known risk): indemnification clause (e.g. survival period, cap, holdback, basket). \n(2) Managing vulnerability exposed (i.e. unknown risk): renegotiation of reps and warranties regarding cybersecurity and privacy ", "Partner": "Deal Structure" } # def issue_change(rs): # return gr.update(choices=general_issues[rs], value=None) # def update_textbox_issues(issue_selection): # issue_textbox.value = specific_issues.get(issue_selection, "Invalid Selection") # issue_dropdown.value = issue_selection # return specific_issues.get(issue_selection, "Invalid Selection") def update_incident(selection): if selection == "Junior": markdown_incident.value = "" elif selection == "Senior": markdown_incident.value ="""During the negotiation of the Letter of Intent, the seller disclosed that there was a breach in their customer data. Email addresses from the customer’s data that was exposed totalled no more than 200. No other personal identifiable information was exfiltrated. That client has since filed a claim requesting for compensation related to damages from this breach. TechEase has disclosed the privacy breach to its customer base, has taken remedial action to prevent another breach and correct the security weaknesses in its infrastructure, and has complied with all relevant regulatory requirements concerning the breach. """ elif selection == "Partner": markdown_incident.value = """Multiple Cybersecurity Breaches/Weak security infrastructure Your associate had just informed you of the current status of the deal: Quasi-fundamental reps and warranties related to cybersecurity, IP, and privacy are already set up Special indemnities are also already set up for cybersecurity and privacy TechEase has cybersecurity and privacy insurance Recently, new problems have come up with TechEase, and we need your expertise to renegotiate TechEase’s AI platform has unique product functionalities and a fast-growing customer base. Security infrastructure is not its focus. Accordingly, there are key issues to be discussed with regards to infiltrations into its system and what type of information technology security infrastructure is in place. TechEase just advised ShopMaster of multiple occurrences of prior breaches to its security infrastructure and it does not know what data, if any, was exfiltrated. Several clients have just switched to TechEase’s competitors given the historical weaknesses of its security infrastructure. Most clients, though, are still enthusiastic about continuous improvements of its core AI product. TechEase has also disclosed the security breaches to its customer base, and has taken remedial action to prevent another breach. However, TechEase does not have the talent to investigate the root causes behind multiple breaches. ShopMaster is deeply concerned and wants to drop the deal. However, ShopMaster is still interested in TechEase’s AI platform, but does not want to deal with the security issues related to the company. """ if selection == "Junior": return gr.Textbox.update(visible = False)#markdown_incident.value else: return gr.Textbox.update(value = markdown_incident.value, visible = True) def update_markdown_notice(selection): if selection == "Junior": markdown_notice.value = seller_meat_1_markdown elif selection == "Senior": markdown_notice.value = seller_meat_1_markdown elif selection == "Partner": markdown_notice.value = "" return markdown_notice.value # Step 1 - Based on the level of the user, display the main focus def update_textbox_focuses(selection): global hint_counter hint_counter = 0 # Reset the hint counter focuses = { "Junior": "Types of representations and warranties.", "Senior": "Cybersecurity incident.", "Partner": "Multiple Cybersecurity Breaches/Weak security infrastructure.", } main_focus_textbox.value = focuses.get(selection, "Invalid selection") return focuses.get(selection, "Invalid selection") # Step 2 - Based on the main focus, display suggested areas of negotiation. def update_textbox_negotiation_options(selection): negotiation_areas_textbox.value = negotiation_areas.get(selection, "Invalid selection") level_dropdown.value = selection return negotiation_areas.get(selection, "Invalid selection") # def update_textbox_disussion_options(selection): # print(selection) # discussion_options = { # "Focus 1": "This is discussion option 1. \nThis is discussion option 2. ", # "Focus 2": "This is discussion option 3. \nThis is discussion option 4.", # "Focus 3": "This is discussion option 5. \nThis is discussion option 6.", # "Focus 4": "This is discussion option 7. \nThis is discussion option 8.", # } # options.value = discussion_options.get(selection, "Invalid selection") # main_focus_dropdown.value = selection # return discussion_options.get(selection, "Invalid selection") hints = { "Junior": ["Hint 1: Remember the highlighted risk factors!", 'Sample Prompt 1: We propose the fundamental representations and warranties will include IP, cybersecurity, data privacy, regulatory/compliance, employee health and benefits, in addition to the traditional fundamental categories.', 'Sample Prompt 2: We propose the survival period for general representations to be set at 3 years.', 'Sample Prompt 3: We propose the cap on liability for general representations to be set at 50% of purchase Price with a 0.25% tipping basket.', 'Sample Prompt 4: We propose the cap on liability for fundamental representations to be set at 100% of purchase price with full duration of the statute of limitations and no basket.'], "Senior": ['Hint 1: Consider there are two types of risks (known, unknown) that require mitigation.', "Hint 2: Recall distinction between standalone indemnities and reps and warranties.", "Hint 3: Recall there are different levels of reps and warranties which trigger different levels of protection.", "Hint 4: Consider elevating cybersecurity and privacy reps and warranties to fundamental."], "Partner": ["No hints available for partners."] } def hint_click(): global hint_counter # if level is junior then we have two hints else if senior only one hint and partner nothing. if hint_counter == 0 and level_dropdown.value == "Junior": hint_counter += 1 hint_textbox.value = hints.get(level_dropdown.value)[0] elif hint_counter == 1 and level_dropdown.value == "Junior": hint_counter += 1 hint_textbox.value = hints.get(level_dropdown.value)[1] elif hint_counter == 2 and level_dropdown.value == "Junior": hint_counter += 1 hint_textbox.value = hints.get(level_dropdown.value)[2] elif hint_counter == 3 and level_dropdown.value == "Junior": hint_counter += 1 hint_textbox.value = hints.get(level_dropdown.value)[3] elif hint_counter == 4 and level_dropdown.value == "Junior": hint_counter +=1 hint_textbox.value = hints.get(level_dropdown.value)[4] elif hint_counter == 5 and level_dropdown.value == "Junior": hint_counter = 0 hint_textbox.value = "No more hints available for this level." elif hint_counter == 0 and level_dropdown.value == "Senior": hint_counter += 1 hint_textbox.value = hints.get(level_dropdown.value)[0] elif hint_counter == 1 and level_dropdown.value == "Senior": hint_counter += 1 hint_textbox.value = hints.get(level_dropdown.value)[1] elif hint_counter == 2 and level_dropdown.value == "Senior": hint_counter += 1 hint_textbox.value = hints.get(level_dropdown.value)[2] elif hint_counter == 3 and level_dropdown.value == "Senior": hint_counter += 1 hint_textbox.value = hints.get(level_dropdown.value)[3] elif hint_counter == 4 and level_dropdown.value == "Senior": hint_counter = 0 hint_textbox.value = "No more hints available for this level." elif level_dropdown.value == "Partner": hint_textbox.value = "No hints available for partners." return hint_textbox.value with gr.Blocks(theme=gr.themes.Soft()) as demo: with gr.Tab("Documentation"): header = gr.Markdown() header.value = """
""" documentation = gr.Markdown() with open("./prompts/documentation_markdown.txt", "r") as f: documentation.value = f.read() with gr.Tab("App"): header = gr.Markdown() header.value = """
""" system_message = gr.Markdown() system_message.value = """
Your goal is to negotiate the most beneficial deal for your client and to properly assess the scope.