# Centralized Database Access: Transformer Framework and LLM/Chatbot Integration-Based Hybrid Model
## 4 API Implementation  
An API (application programming interface) is a set of defined rules and specifications that enable communication between software applications. It allows applications to access functions and data from other applications, services, or platforms. The OpenAI API is used in the program code, as the following line shows (Figure 4). Through the API, GPT-4, OpenAI's most advanced system, is invoked. The model is based on transformer neural network technology, eliminating the need for training for each specific task, making it ideal for personal data applications. The user interface is created using the Tkinter package. The basic components include:  
* Main window: Initialized with root = tk.Tk(). This is the main window of the application in which other elements are located. * Query Input Field: A text field in which the user can enter queries or keywords. Initialized with input_entry = tk.Entry(root, width = 50). * Buttons: There are several buttons in the user interface, including one for processing queries (send_button), searching for keywords (keyword_button), searching for images (image_search_button) and starting a new conversation (new_conversation_button). * Text Field for Results: The results of queries are displayed in this area. It is initialized with result_text = tk.Text(root, wrap = tk.WORD, width = 100, height = 20, state = tk.DISABLED). The user interface is designed to be as simple as possible in order to demonstrate its functionality. In case of further development and implementation, it is possible to customize the user interface to new esthetic trends to make it more intuitive and better. Database and Data Processing  
The program is based on the local storage of data, especially PDFs and images. These data are stored in directories defined by the variables pdf_folder and image folder of particular interest is how the PDF content is processed. The variable pdf_folder refers to a database with PDF files of educational materials that the program uses to generate responses. PDF files undergo a text extraction process in which each page of each file is transformed into a searchable textual format, accumulating content in a variable called 'raw_text' (Figure 5). To enable an efficient search, the text is split into parts using CharacterTextSplitter. The text is segmented into parts with a size of 800 characters and an overlap of 200 characters, as defined in the line (Figure 6):  
Figure 4: Calling GPT-4 through API. Figure 5: Loading PDF files. In addition to text splitting, OpenAIEmbeddings are used for contextual searches, which convert each text segment into a vector form or embedding. These vector shapes are then indexed with the FAISS tool, which enables a quick search for similar text segments. This can be seen in this line (Figure 7):  
Furthermore, to search for textual data, there is functionality for searching images with the function search_image(). This function uses the 'difflib.SequenceMatcher', which searches for images based on the similarity of names and compares the similarity between two sequences and returns a similarity ratio. If the similarity_ratio is higher than a set threshold (in this case 0.4), the image is considered similar to the keyword and displayed to the user (Figure 8). The proposed hybrid model is designed to be adaptable and flexible by changing the educational materials in the database and changing the specificity of the output by changing the code. Any educational field that can represent knowledge in the form of text will have no problems with this model. The value 0.4 can be adjusted as required. The larger the number, the more similar the output is to the input i.e., expressions are extracted from the database that are more similar to the word entered. If you increase the \"similarity number\", the range of information that can be extracted becomes smaller. At the same time, precision increases, which is beneficial for retrieving specific data from materials.