Over drinks at a Eurofinance event, we discussed use cases and how treasurers could create simple automations and so we discussed how to create a form filling app using AI which would save time and tedious work. I proposed using ChatGPT to design and prototype something and overall the majority of what would be needed to build an application is there.
The technology is good enough that if you dream it, it's probably possible!
Here was the prompt and the result:
Prompt: I would like to create a prototype of an application which reads a pdf (using Python) uses gen ai to translate the field names to the database hierarchy and performs any data transformations needed and then uses Python to complete the final form. Please provide the code and descriptions for an example of how this could work in practice
Response: We can break down the solution into multiple steps. Below is a high-level description of each part of the process, followed by example code snippets:
Steps:
- Read and extract data from the PDF using a library like PyPDF2 or pdfplumber.
- Use a generative AI model (e.g., OpenAI's GPT or any other AI model you prefer) to translate the field names from the PDF into a structured database schema.
- Perform necessary data transformations to ensure the data aligns with your target database structure.
- Complete a form or generate an output using the transformed data.
Example Workflow:
- Extract data from PDF: We can use a Python library like pdfplumber to read and extract the text from the PDF.
2. Use Generative AI for field name translation: You can integrate a generative AI model (e.g., OpenAI GPT) to translate the raw text into field names and map them to a database hierarchy. For the sake of simplicity, I'll simulate the AI response here.
3. Perform Data Transformations: Based on the AI response, you will likely need to clean and transform the data to fit your database. This could involve converting dates, normalising text fields, etc.
4. Generate Final Form or Database Entry: After transforming the data, you can use it to either populate a form, save it in a database, or generate a report.
Example Output:
This would output a JSON object or any other form output, representing the final transformed data:
Integration Points:
- Generative AI: In practice, you can replace the simulated AI call with an actual API call to a service like OpenAI GPT. You would send the extracted PDF text as input and ask the model to output mappings of the fields.
Example of calling OpenAI API:
Database/Forms: Depending on your use case, the final form output can be directly inserted into a database, used in an API, or saved in a document.
This workflow gives you a starting point to create a robust system for PDF processing, field translation using AI, and data transformation. You can modify each step to suit the specific requirements of your project.