futuristicdude/The_First_Principle_thinker
1
1import os2import requests3import gradio as gr4from bardapi import Bard5 6os.environ['_BARD_API_KEY'] = 'YQhcBNtbZQftr726ozcL5F6qLi63wu0m5FmA5fBral7_sjGtW7IFIZRzgEb4t-HIgZ7hEg.'7 8session = requests.Session()9session.headers = {10 "Host": "bard.google.com",11 "X-Same-Domain": "1",12 "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36",13 "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",14 "Origin": "https://bard.google.com",15 "Referer": "https://bard.google.com/",16}17 18session.cookies.set("__Secure-1PSID", os.getenv("_BARD_API_KEY"))19 20bard = Bard(session=session, timeout=30)21 22# Function to get answer23def get_answer(prompt):24 return bard.get_answer(prompt)['content']25 26# Define input and output components using Gradio27input_text = gr.inputs.Textbox(label="Enter your problem or goal:")28output_text = gr.outputs.HTML(label="Solution")29 30# Define the processing function31def process_problem(problem):32 summary = get_answer("Please provide a summary of the problem or goal:\n" + problem)33 components = get_answer("Please break down the problem into its fundamental components or elements:\n" + problem)34 challenges = get_answer("Please question and challenge each component to find out what is true and what is not:\n" + components)35 eliminated = get_answer("Please eliminate any assumptions, biases, analogies, or conventions that are not supported by facts or evidence:\n" + challenges)36 solution = get_answer("Please synthesize and combine the remaining components or elements into a new view or solution that is logical, consistent, and original:\n" + eliminated)37 validation = get_answer("Please test and validate the solution against reality and feedback:\n" + solution)38 39 # Format the answers using HTML40 formatted_output = f"<h3>Summary:</h3><p>{summary}</p>" \41 f"<h3>Components:</h3><p>{components}</p>" \42 f"<h3>Challenges:</h3><p>{challenges}</p>" \43 f"<h3>Eliminated Assumptions:</h3><p>{eliminated}</p>" \44 f"<h3>Solution:</h3><p>{solution}</p>" \45 f"<h3>Validation:</h3><p>{validation}</p>"46 47 return formatted_output48 49# Create the Gradio interface50interface = gr.Interface(fn=process_problem, inputs=input_text, outputs=output_text, title="The First Principle Thinker",51 description="Enter your problem or goal, and the AI will help break it down into components and provide a solution using first principles thinking.")52 53# Launch the interface54interface.launch()55 