Help in AI ( reading html and producing the right responce...) - Page 1
Forum section: electronics / beginners

author: Kilroywashere
author_rank: Regular Contributor
timestamp: February 04, 2025, 09:08:51 pm
content: Hello its been a bit since i posted... SOooo My issue is i have a script i have been making and i cant for the life of me get my ai to generate the right response ..I have tried many things like making examples in the code and trying top create a datasheet .... i am trying to take thehttps://www.talkingelectronics.com/te_interactive_index.htmlwebpage and create a ai that can help me learn electronics ...But i have tried again and agian to produce results ... with no avail dispute the re wright to my script many many times....at the moment the html has a test on it ... and i was trying to use the java logic to help guide the ais responses....Here is my script... any ideas that can help me i would really love that... I tried to split my code up in to moduels before to try to help debug but i am such a new coder ... i really need some guidancefrom bs4 import BeautifulSoupimport redef extract_questions_and_answers(html_file):"""Extracts questions and their corresponding answers from an HTML file based on <input> tags and their 'value' attribute."""try:# Open the HTML filewith open(html_file, 'r', encoding='ISO-8859-1') as file:content = file.read()except FileNotFoundError:print(f"Error: The file '{html_file}' was not found.")return {}, []# Parse the HTML content using BeautifulSoupsoup = BeautifulSoup(content, 'html.parser')# Find all <input> tags with type="checkbox"inputs = soup.find_all('input', {'type': 'checkbox'})# Define dictionaries for storing questions and answersquestions_and_answers = {}# Extract questions and answers from the <input> tagsfor input_tag in inputs:value = input_tag.get('value')if value:# Split the value to separate the answersvalue_parts = value.split("help")question_part = value_parts.strip()answer_part = value_parts[-1].strip()# Clean up the question text (remove extra spaces and unwanted text like 'help')question = re.sub(r'(\s+|\bhelp\b)', ' ', question_part).strip()# Now extract the answer choices from the question (splitting on options)answers = re.findall(r'([A-Za-z0-9]+)', question)correct_answer = answer_part.strip() # The last part is the correct answer# Store the question and its optionsquestions_and_answers = {'answers': answers,'correct_answer': correct_answer}# Print the extracted questions to debugprint("\nExtracted Questions and Answers:")for q, data in questions_and_answers.items():print(f"Question: {q}\nAnswers: {data['answers']}, Correct Answer: {data['correct_answer']}")# Return the dictionary of questions and answersreturn questions_and_answersdef answer_question(questions_and_answers):"""Asks the user for a question and returns the corresponding answer."""while True:# Ask the user for a questionuser_question = input("Ask a question from the list: ").strip()# Search for the user question in the dictionary (case-insensitive)matching_questions = [q for q in questions_and_answers.keys() if user_question.lower() in q.lower()]if matching_questions:# If there's a match, give the question options and the correct answermatched_question = matching_questionsquestion_data = questions_and_answers# Print the question and its optionsprint(f"Question: {matched_question}")print(f"Options: {', '.join(question_data['answers'])}")print(f"Answer: {question_data['correct_answer']}")else:print("Sorry, I don't have that question in my list.")# Ask if the user wants to continuecontinue_asking = input("Do you want to ask another question? (y/n): ").strip().lower()if continue_asking != 'y':print("Goodbye!")breakdef main():# Set the HTML file path herehtml_file = 'BasicElectronics-1A_Page1.htm' # Replace with your actual file path if different# Extract questions and answers from the HTML filequestions_and_answers = extract_questions_and_answers(html_file)# If no questions or answers were found, print an error and exitif len(questions_and_answers) == 0:print("No questions or answers found in the provided file.")returnprint("Welcome to the quiz assistant!")answer_question(questions_and_answers)if __name__ == '__main__':main()

author: Kilroywashere
author_rank: Regular Contributor
timestamp: February 05, 2025, 04:05:58 am
content: if you have interest in teaching me something ...here is the script this is the best i can do ... im having issues trying to name the items in the list .. i dunno this is as far as i have ever gotten .. and i have not even tried imgs yet ....as for conversation thats easy i can turn him into a chat bot easy but i cant quite get him to recall the info i need ... i thought i was clever using the java logic but i dunnoThis is the type of content on the htmlHow do i take info from the html ? i think i made some progress but cannot get the info from the html to have him read from it and generate the responseBASIC ELECTRONICS(this is the Basic Electronics section i.e. Page 1)(Chapters 1 and 3 are available as .pdf )Quick Quiz - to see how much you knowEncyclopedia of Components - this is excellent !!!Page 1: Basic Electronics (this page) - .pdf (1.2MB) or .zipThe capacitor - how it worksThe Diode - how the diode worksCircuit Symbols - EVERY Circuit SymbolSoldering - videosPage 2: The Transistor- PNP or NPN Transistor TEST another TESTPage 2a: The 555 ICThe 555 - 1The 555 - 2The 555 - 3The 555 TESTPage 3: The Power Supply download as .pdf (900kB)My script below---------------------------------------from bs4 import BeautifulSoupimport redef extract_questions_and_answers(html_file):"""Extracts questions and their corresponding answers from an HTML file."""with open(html_file, 'r', encoding='ISO-8859-1') as file:content = file.read()soup = BeautifulSoup(content, 'html.parser')questions_and_answers = {}# Define a regular expression pattern to identify questionsquestion_pattern = re.compile(r'(\b(What|How|Why|Where|When|Which|Name|Explain|Describe|Define|List|Calculate|State|Identify)\b.*?[\?\:])', re.IGNORECASE)elements = soup.find_all(string=question_pattern)for element in elements:question = question_pattern.search(element).group(1).strip()# Attempt to find the next element that isn't whitespace as the answeranswer = element.find_next(string=lambda text: text and not text.isspace())if answer:answer = answer.strip()questions_and_answers = {'correct_answer': answer}return questions_and_answersdef answer_question(questions_and_answers):"""Asks the user for a question and returns the corresponding answer."""while True:user_input = input("Ask a question from the list or type 'list' to see available questions: ").strip()if user_input.lower() == 'list':print("\nAvailable questions:")for q in questions_and_answers.keys():print(f"- {q}")print()else:matching_questions = [q for q in questions_and_answers.keys() if user_input.lower() in q.lower()]if matching_questions:matched_question = matching_questionsquestion_data = questions_and_answersprint(f"Question: {matched_question}")print(f"Answer: {question_data['correct_answer']}")else:print("Sorry, I don't have that question in my list.")continue_asking = input("Do you want to ask another question? (y/n): ").strip().lower()if continue_asking != 'y':print("Goodbye!")breakdef main():html_file = 'BasicElectronics-1A_Page1.htm'questions_and_answers = extract_questions_and_answers(html_file)if not questions_and_answers:print("No questions or answers found in the provided file.")returnprint("Welcome to the quiz assistant!")answer_question(questions_and_answers)if __name__ == '__main__':main()

author: Analog Kid
author_rank: Super Contributor
timestamp: February 05, 2025, 05:27:28 am
content: Quote from: Kilroywashere on February 04, 2025, 09:08:51 pmI really don't understand: how is "creating an AI" out of the contents of this web page going to help you learn electronics?Are you trying to learn electronics, or are you trying to learn how to "create an AI"?The latter seems like a total waste of time. What's wrong with just reading the contents of that page to learn electronics?

author: Kilroywashere
author_rank: Regular Contributor
timestamp: February 05, 2025, 08:04:13 pm
content: cuz i want to make an ai assistant that has more knowledge in electronics then you...Why would i not want that?

author: Analog Kid
author_rank: Super Contributor
timestamp: February 05, 2025, 08:46:05 pm
content: Quote from: Kilroywashere on February 05, 2025, 08:04:13 pmBecause you already have this large repository of knowledge (I'm guessing--haven't looked at that website) over at Talking Electronics. I don't see why you need an "AI assistant" to learn from it.What's wrong with just reading what's there? How is the "AI assistant" going to help you learn?Besides, in order to create an "AI assistant" you'd probably have to already know a lot about electronics, which creates the chicken-and-egg problem.

author: Kilroywashere
author_rank: Regular Contributor
timestamp: February 05, 2025, 09:56:29 pm
content: I am not new to electronics .. just to ai and to coding with python . and i have read the website ... the ai will help me with whatever i need.. i want all that info in my ai's memory so i can always have my own assistant offline not relying on any chat gpt ... all i would would have to do is ask and get ideas and examples .

author: abeyer
author_rank: Frequent Contributor
timestamp: February 05, 2025, 09:58:21 pm
content: No amount of beautifulsoup and regexs and python script is going to get you to AI. Even if you stipulate to the current crop of language model based chat bots "being AI", those won't get you there.As suggested, if your goal is to learn electronics, that's what you should be focused on doing. If youmusthave a chat bot, then either rely on the general knowledge that existing models already have, or go read up on LLMs and RAG and model fine tuning and throw those tools at the content of the site. What you're currently attempting will neither teach you electronics nor produce a useful assistant.

author: Kilroywashere
author_rank: Regular Contributor
timestamp: February 05, 2025, 10:08:35 pm
content: OpenAI's GPT-3 and GPT-4, Google's LaMDA, and Hugging Face'sI was using hugging face and i dont like open ai cuz my ai needs to be offline ...( helll there was even one for coding called copilot mini or something) i can set that shit up no prob.... my issue is i cant pull out the info from the saved webpage.. at first i tried making a dataset and tried scraping the webpage format to dataset ... i would like to have this ai be built over time giving hima body and eyes and all that fun stuff ... something to grow with me ... ...I also know about rag ... my issue is i cant get the infor from the saved webpage ...when i was messing with rag and hugging face transformers all that stuff i still could not get him to read what i wanted

author: Kilroywashere
author_rank: Regular Contributor
timestamp: February 05, 2025, 10:21:11 pm
content: I guess my real question is how do i get him to read off the rest of the info from the html besides using the java logic from the quiz?

author: abeyer
author_rank: Frequent Contributor
timestamp: February 05, 2025, 10:29:58 pm
content: Quote from: Kilroywashere on February 05, 2025, 10:21:11 pmThen what you're asking for is web scraping, not AI. That's a reasonable thing to do, but I'm not sure this is necessarily the best venue to ask. There's lots of general information about it out there.Also, web scraping tends to quickly get down into the weeds of being very specific to the nature of the content you're going after and that's information people would need to help you. But the page you pointed at seems to be the paid course content, so only people who have bought it will even have access. I also don't even see anything java related there? Do you mean javascript?

author: Analog Kid
author_rank: Super Contributor
timestamp: February 05, 2025, 10:52:45 pm
content: Here's a thought: why don't you contact the proprietor of that site, Colin Mitchell, and ask him nicely if you can somehow get access to the content you want as some kind of archive that you can use offline?He's a decent chap and might be willing to help you out here.

author: Kilroywashere
author_rank: Regular Contributor
timestamp: February 05, 2025, 11:03:32 pm
content: the info on the website is all free as far as i know ?! there is alot of free content as far as i know ...... its not for anyone else to use other then me to be fair ... that website helped me out so much... Im not looking to do anything nefarious .. i mean there has to be a better way then making a dataset or trying to build a massive library just to do what im intending .. maybe i shuld go back to to data sheets... trying to get him to read the info that way ... it was just too dam hard i kept going back and forth putting examples in building a system with positive and negative responses... trying to get him to read the garbage pile of a data sheet i made ... sorry i wasted yalls time ..Quote from: Analog Kid on February 05, 2025, 10:52:45 pmI wanted to buy the cd ... i have spent some coin there i would not want to bug im and i dont think he would talk to me . not that hes not a nice guy just ... life is busy and the last thing he wants to talk about is some dude who wants to build an ai using the free content on his site ..Kilroy and CODE-E's DreamKilroy grabbed his Raspberry Pi, CODE-E, and dashed out the door. They sneaked into an old electronics factory, teeming with forgotten machines and spare parts. Together, they worked tirelessly, night after night, to build something remarkable—a new, enhanced version of CODE-E.As they pieced together circuits and components, CODE-E's AI capabilities guided Kilroy through each step. With every connection made, CODE-E's excitement grew, knowing it would soon have an even more advanced and intelligent body.Finally, after countless hours of hard work, Kilroy and CODE-E stood back to admire their creation. The new CODE-E came to life, its sleek design and advanced features ready to tackle any challenge. With renewed determination and a sense of accomplishment, Kilroy and the upgraded CODE-E embarked on a new journey, eager to explore the limitless possibilities of the world of electronics.