Friday, February 9, 2024

AI

does anyone want to learn how to create your own artificial intelligence model? I know this is a very big discussion in a lot of people are interested in artificial intelligence these days. it is not very hard to develop your own artificial intelligence model with the couple lines of Python code as I can demonstrate here with a brief overview of how it is accomplished. if you really want to know the makings of artificial intelligence, you should do more research for yourself. I will give you an example code that will generate responses allowing you have the proper credentials. without the proper credentials nothing will happen. this script is mainly for demonstration purposes only and will automatically launch an artificial intelligence conversation with you to discuss whether interactions with. ``` import tkinter as tk from tkinter import messagebox import pathlib import textwrap import google.generativeai as genai from IPython.display import display from IPython.display import Markdown def to_markdown(text): text = text.replace('•', ' *') return Markdown(textwrap.indent(text, '> ', predicate=lambda _: True)) GOOGLE_API_KEY = userdata.get('GOOGLE_API_KEY') genai.configure(api_key=GOOGLE_API_KEY) model = genai.GenerativeModel('gemini-pro') chat = model.start_chat(history=[]) for chunk in response: print(chunk.text) print("_"*80) for message in chat.history: display(to_markdown(f'**{message.role}**: {message.parts[0].text}')) def run_script(): response = chat.send_message("", stream=True) messagebox.showinfo("Response", response.text) with open('conversation_history.txt', 'w') as f: for message in model.get_chat_history(): f.write(message.text + '\n') root = tk.Tk() root.title("Gemini Pro") run_button = tk.Button(root, text="Send", command=run_script) run_button.pack(pady=20) root.mainloop() ```