Friday, 4 October 2024

Generative AI Assisting Software Architecture Design for Video Games

Generative AI presents a promising avenue for revolutionising software architecture design processes in the video game industry. This study explores the potential of generative AI in designing software architecture tailored to the unique requirements of video game development. It examines how this technology impacts the software structure of digital entertainment products and identifies conditions for generative AI to become a standardized tool for this purpose.

To do so, this contribution firstly defines software architecture and its form in the context of video game development, then analyses the challenges of using generative AI to design architectural solutions for video games and finally proposes ways for a more functional interaction between generative AI and the Game Development Life Cycle (GDLC). This study closes with the proposal of an empirical methodology to further develop the research in this field.

Keywords—AI, Game Development, Generative AI, Software Architecture, Video Games

Photo by Ron Lach

I. INTRODUCTION

AI is poised to play an increasingly integral role in the evolution of video games in the coming years [1]. It is anticipated to substantially streamline and expedite the game development process while also enhancing the level of experience customisation available to players. AI is already used in game development to gather data, generate scenarios, game assets and non-player characters (NPC) [2], automate and test various pipeline components, or conduct sentiment analysis for players’ feedback [3]. New tools might arise to simplify processes, with financial and operational advantages for game studios. For example, game assets, which are frequently outsourced to third parties when there is the need of a high number of objects in a short amount of time, could be efficiently handled in-house; this might help art directors and supervisors in maintaining graphic and aesthetic consistency, reducing inter-company communications [4]. Budget constraints, especially for independent game developments, may encourage developers to adopt an in-house approach rather than subcontracting. However, employing full-time staff for bigger developments entails costs related to salaries, equipment, benefits, and workplace, which could become considerable [4]. Hence there is a need to carefully balance external, in-house and AI contributions. Further regulations are required if AI tools will be involved more consistently in this way, since these tools can be trained on copyrighted artworks [5].  

Video games represent a field where AI is tested in various forms, for example using Natural Language Processing (NLP) for text-based games [6]. New emerging AI trends in liminal areas of video gaming, such as cloud computing, blockchain, AR and VR [3], are evolving at a fast pace. One of these is generative AI. This study (1) explores the potential of generative AI in assisting game developers with designing an appropriate software architecture for video games. It (2) examines how this technology impacts the software structure of digital entertainment products and (3) identifies the necessary conditions for generative AI to become a standardized tool for this purpose.

The exploration of whether generative AI will emerge as a standardised approach to software architecture design in the realm of video games holds profound implications for the future trajectory of the gaming industry. In fact, it underscores the transformative potential of AI in reshaping how games are conceptualised, developed, and experienced by players [7].

II. SOFTWARE ARCHITECTURES FOR VIDEO GAMES

The ISO/IEC 42010 standard establishes a framework for describing the architecture of systems and offers guidelines and principles for creating architecture descriptions that can be applied in various contexts [8]. Through architectural descriptions and specifications, software developers and architects can design, develop, validate, and evolve systems at a higher-level of abstraction while preserving system quality and functionality [9]. Software architecture is a functional partition of a whole into smaller parts that maintain specific relations among themselves; each partition is the result of a careful design process which is carried out to satisfy the driving quality attribute requirements and the central business objectives behind the system [10].

In defining a software architecture, it is noteworthy to differentiate large organisations vs small teams of developers [11]; in the game industry, these two scenarios can be representative of two specific video game productions known as triple-A (AAA) and independent (indie). AAA is used in the game industry to refer to the product made by a medium-large development company; this requires a meaningful budget for its development [12] and can entail complex software architectures due to their large scale and scope, post-launch support and updates, optimisation for various platforms etc. Indie usually refers to individuals or small teams of developers without the financial or logistical assistance of a large publisher. It must be noted that video game production also includes part-time hobbyists, aspirational students, client-facing contractors, independents, and artist collectives [13] who respond to diverse business objectives. Hence, video game software architectures significantly vary from one project to another and cannot be rigidly standardised.

Because of this, there is no consensus over a standard video game software architecture or software architecture design process. A massive multiplayer online video game (MMO) that requires updates and constant interaction with other players [14] has different requirements from a single-player video game which typically has a predefined storyline or set of objectives that players can complete on their own. For example, in MMOs, conversely to single-player video games, it is essential to oversee certain security requirements, like providing protection against application-layer DDoS attacks that exploit in-game dependencies to cause massive spikes in bandwidth [15].

A systematic literature review of software engineering for industry-scale computer games [16] reveals that video games are unique in terms of size, complexity, and creativity, in comparison to traditional software engineering. The study asserts that commonalities between traditional software development and game development are mainly in the project management and the impact of commercial requirements over the design decisions [16]. The differences emerges from the analysis of the peculiar features of game development: for instance, its multidisciplinary nature, the emphasis on subjective player experience, the highly iterative process and non-agile methodology, the fixed deadlines, the management of a large amount of assets, the complex testing phase, the incorporation of post-release additions, the management of various software systems, and the utilization of highly specialized middleware – like game engines – that have democratized the process for developers without an engineering background [16].

A debated argument around software architectures for video games is the choice between monolithic and microservices architectures [17] which highlights important decisions and trade-offs that development teams must consider for their product [18]. Monoliths are designed, developed, and deployed as a single unit while microservices refer to a collection of loosely coupled and independently developed, deployed, and scaled services [19]. Microservice architecture tends to be cloud-native architecture [20]. In the context of video games, there is no consensus on adopting one approach over the other one and indeed there are cases where both are involved. A small development team with a small codebase size and concerns about performance might adopt a monolithic architecture for a video game with a non-exponential evolution and a singular deployment. An MMO might use a traditional client-server model [21] with some functionalities implemented within a microservice architecture. This approach is particularly effective when game services require constant updates in real time, new functionalities to build and maintain, faults to isolate and fix [22], and a substantial number of users scattered in various geographical locations that might peak. However, as advantageous as it might appear, this might also bring additional overhead over a monolithic approach. Attention must also be given to the communication between the components of the architecture; in microservice architecture, components communicate between themselves using a lightweight convention such as HTTP and an application programming interface (API) contract [23]; in monolithic architectures, data tends to be kept on the same machine. Monolithic architectures are unified, with all their functions managed and served in one place [18]; monolithic applications tend to excel in low latency due to local execution [17] and thus might increase the performance of the game.

A fitting solution for game developers in the context of online games is represented by a hybrid solution [17]. It must also be noted that migration from monolithic to microservices architecture might be possible [24] if the need arises. In consideration of this, it becomes apparent that, within the contemporary game industry, no predetermined architectural framework can perfectly align with every business requirement.

Photo by Francesco Ungaro

III. GENERATIVE AI AND VIDEO GAMES SOFTWARE ARCHITECTURE

Generative AI refers to a technology that produces content based on a given prompt [25]. This technology can generate various forms of output, including text, images, and other media, in accordance with the instructions provided. Generative AI has been extensively researched in recent years, with various studies identifying a large growth in adopting tools such as ChatGPT and Midjourney in several domains, including healthcare, business, the military, and design [26]. Research has also explored generative AI in the context of designing system architectures, with numerous contributions from experts in the industry.

This study [27] highlighted that design decisions and assumptions made in the design process for software architectures require a familiarity with the context. Architectural knowledge and the ability to make meaningful compromises are skills which imply the experience of having seen similar scenarios over different situations [27]. Practical expertise is fundamental in crafting appropriate prompts that would guide generative AI tools in designing software architectures. In the light of this, the prompt engineer interacting with the generative AI should have extensive knowledge of related systems and be aware of the context and trade-offs for that specific product requiring an architectural solution. This is also essential to correctly interpret the output and avoid hallucinations, meant as the phenomenon in which generative AI software systems produce fabricated or false information [28]. It has been proven that, although generative AI is trained on large amounts of data, it might struggle to provide accurate responses to questions that require practical knowledge or experience, up-to-date technology, and context understanding [29]. This might be problematic for the purpose of establishing suitable software architectures for complex products such as video games.

As previously stated, video game and traditional software development share some commonalities such as the impact of commercial requirements over the design decision. The system/software development life cycle (SDLC), meant as a series of stages within the methodology that are followed in the process of developing and revising an information system or software, establishes segments for the development which are usually completed using software development tools [30]. In the context of video games, some scholar has theorised a more specific game development life cycle (GDLC) which consists of an initiation, pre-production, production, testing and release stage [31], with other experts theorising an additional step such as the beta stage [32]. Considering that several game developers have proposed their own GDLC on the internet, it can be reasonably claimed that there is no univocal solution to the establishment of a procedural pipeline for all video games. Therefore, to efficiently prioritize specific requirements or constraints in a video game development workflow, generative AI aiming to support game development must be trained on diverse and factual GDLC models that are relevant to existing game architectures. Gaining exposure to comparable scenarios subject to multiple conditions, coupled with an assessment of the advantages and disadvantages of the adopted architectural solutions in each situation, would enhance architectural knowledge and foster a more streamlined decision-making process for the game developer.

To create suitable software architectures, generative AI also requires specific information on the desired quality attributes such as performance, reliability, security, and modifiability. Taking traditional software architecture as an example, if the emphasis is on high performance, generative AI might suggest exploiting potential parallelism by decomposing the work into synchronising or cooperating processes, manage the network and interprocess data access frequencies and communication volume, identify performance bottlenecks, and be able to evaluate predictable latencies and throughputs [10]. The establishment of detailed quality attributes for video games is equally important, but it necessitates additional parameters that can be extrapolated by the client brief, the game design document (GDD) and/or other pre-production documents. For instance, parameters might include requisites such as the use of a specific engine for graphics, for sound/audio, for rendering, or explicit input/output (I/O) units; these can also describe other requirements related to the context of the game, the target audience, the game genre and similar. These parameters, along with the specification of quality attributes, should be formulated as a functional prompt which serves as the input. The goal is to receive a video game software architecture output from generative AI that requires minimal modifications from the development team.

This approach to the software architecture design process does not influence the game development in its core components like the game design or the asset creation, but rather in the structuring of the system supporting them, and in the flow and economy of the development process. However, a more systematic approach to design system architectures for video games through generative AI can only be theorised since research and industrial practice have shown a lack of consistency in its current implementation.

IV. CONCLUSION

Generative AI holds significant promise for informing video game software architecture design, potentially streamlining development processes and optimising workflows. However, there is no standardised utilisation in the game industry due to various challenges in consistency and implementation. Despite these challenges, the transformative impact of AI on game development is evident in several predictable aspects, and it might signal a shift in how games might be conceptualised, developed, and experienced by players in the near future.

This initial investigation lays the groundwork for further exploration into the capabilities of generative AI tools for providing software architectural suggestions. Experiments could be designed to assess the potential of these tools (e.g., ChatGPT) in offering diverse solutions for theoretical video game projects with varying requirements. The output generated by such tools can then be marked and catalogued according to predefined criteria for analysis, with the aim of evaluating the current capabilities of generative AI in designing software architectures for video games.

References

[1] Y. Wu, A. Yi, C. Ma, L. Chen, "Artificial intelligence for video game visualization, advancements, benefits and challenges," Mathematical Biosciences and Engineering, vol. 20, no. 8, pp. 15345-15373, 2023, doi: 10.3934/mbe.2023686.

[2] L. J. Gunawan, B. N. Marlim, N. E. Sutrisno, R. Yulistiani, and F. Purnomo, "Analyzing AI and the impact in video games," in 2022 4th International Conference on Cybernetics and Intelligent System (ICORIS), Prapat, Indonesia, 2022, pp. 1-4, doi: 10.1109/ICORIS56080.2022.10031590.

[3] S. Srivastava, "How AI in gaming propelling the industry into a new epoch," Appinventive, [Online]. Available: https://appinventiv.com/blog/ai-in-gaming/#:~:text=Looking%20ahead%2C%20AI%20will%20play,to%20monetize%20their%20gaming%20platforms (accessed: Mar. 22, 2024).

[4] Juegoadmin, “How to outsource game art: a comprehensive guide,” Juego Studios, [Online]. Available: https://www.juegostudio.com/blog/how-to-outsource-game-art (accessed: Mar. 29, 2024).

[5] J. G. Gatto, "Video Games," Licensing Journal, vol. 43, no. 8, pp. 26-27, 2023.

[6] T. Gao, J. Li, and Q. Mi, "From game AI to metaverse AI: realistic simulation training as a new development direction for game artificial intelligence," in 2023 International Conference on Emerging Techniques in Computational Intelligence (ICETCI), Hyderabad, India, 2023, pp. 130-137, doi: 10.1109/ICETCI58599.2023.10331190.

[7] A. Christofferson, A. James, T. Rowland, and I. Rey, "How will generative AI change the video game Industry?" Bain & Company, Sep. 14, 2023, [Online]. Available: https://www.bain.com/insights/how-will-generative-ai-change-the-video-game-industry (accessed: Mar. 29, 2024).

[8] ISO/IEC/IEEE, "Systems and software engineering–architecture description," ISO/IEC 42010, Tech. Rep., Dec. 2011.

[9] A. A. Khan, A. A., M. Waseem, P. Liang, M. Fahmideh, T. Mikkonen, and P. Abrahamsson, "Software architecture for quantum computing systems — A systematic review," Journal of Systems and Software, vol. 201, p. 111682, 2023, doi: 10.1016/j.jss.2023.111682.

[10] P. Clements et al., Documenting Software Architectures: Views and Beyond, 2nd ed. Boston, MA, USA: Addison-Wesley Professional. 2010.

[11] C. Hofmeister, P. Kruchten, R. L. Nord, H. Obbink, A. Ran, and P. America, "A general model of software architecture design derived from five industrial approaches," Journal of Systems and Software, vol. 80, no. 1, pp. 106-126, 2007, doi: 10.1016/j.jss.2006.05.024.

[12] G. Balla, "Adapting visual references in concept art for films and video games in design uncanny monsters," Journal of Adaptation in Film & Performance, vol. 16, no. 1, pp. 133-145, 2023, doi: 10.1386/jafp_00093_1.

[13] B. Keogh, The Videogame Industry Does Not Exist: Why We Should Think Beyond Commercial Game Production. The MIT Press, 2023, doi: 10.7551/mitpress/14513.001.0001. ISBN: 9780262374132.

[14] F. Lu, S. E. Parkin, and G. Morgan, "Load balancing for massively multiplayer online games," in Proceedings of the 5th Workshop on Network and System Support for Games, NETGAMES 2006, Singapore, Oct. 30-31, 2006, doi: 10.1145/1230040.1230064.

[15] N. Gavrić and Ž. Bojović, "Security concerns in MMO games-Analysis of a potent application layer DDoS threat," Sensors (Basel), vol. 22, no. 20, pp. 7791, 2022, doi: 10.3390/s22207791.

[16] J. Chueca, J. Verón, J. Font, F. Pérez, and C. Cetina, "The consolidation of game software engineering: A systematic literature review of software engineering for industry-scale computer games," Information and Software Technology, vol. 165, p. 107330, 2024, ISSN 0950-5849, doi: 10.1016/j.infsof.2023.107330.

[17] Ascendion, "Monoliths vs microservices in gaming architecture: striking the right balance," Ascendion Blog, [Online]. Available: https://ascendion.com/blog/monoliths-vs-microservices-in-gaming-architecture-striking-the-right-balance (accessed: Mar. 29, 2024).

[18] M. Beznos, "Microservices vs monolith: which architecture is the best choice for your business?" N-iX, Jan. 03, 2023, [Online]. Available: https://www.n-ix.com/microservices-vs-monolith-which-architecture-best-choice-your-business/ (accessed: Mar. 29, 2024).

[19] Z. Tan, "Appendix A. monoliths vs. microservices," in Acing the System Design Interview. United States: Manning Publications Co. LLC, 2024.

[20] A. Balalaie et al., "Microservices migration patterns," Software: Practice and Experience, vol. 48, no. 11, pp. 2019-2042, 2018, doi: 10.1002/spe.2608.

[21] Kim, H.Y., & Park, H.J. (2013). "An efficient gaming user oriented load balancing scheme for MMORPGs," Wireless Personal Communications, vol. 73, pp. 289-297, doi: 10.1007/s11277-013-1237-2.

[22] Hanson, J., "Why you should run your game servers independently from your chat," FreeCodeCamp, Apr. 11, 2018, [Online]. Available: https://www.freecodecamp.org/news/why-you-should-run-your-game-servers-independently-from-your-chat-3263b4b9548e/ (accessed: Apr. 20, 2024).

[23] A. Razzaq, S. A. K. Ghayyur, "A systematic mapping study: the new age of software architecture from monolithic to microservice architecture—awareness and challenges," Computer Applications in Engineering Education, vol. 31, no. 2, pp. 421-451, 2022, doi: 10.1002/cae.22586.

[24] S. Newman, Monolith to Microservices. O'Reilly Media, Inc., 2019.

[25] Lim, W.M., Gunasekara, A., Pallant, J.L., Pallant, J.I., & Pechenkina, E. (2023). "Generative AI and the future of education: Ragnarök or reformation? A paradoxical perspective from management educators," The International Journal of Management Education, vol. 21, no. 2, p. 100790, doi: 10.1016/j.ijme.2023.100790.

[26] David, Y., Krebs, A., & Rosenbaum, A. (2023). "The use of generative AI tools in design thinking academic makeathon," CERN IdeaSquare Journal of Experimental Innovation, vol. 7, no. 3, pp. 43-49, doi: 10.23726/cij.2023.1470.

[27] Ozkaya, I., "Can architecture knowledge guide software development with generative AI?," IEEE Software, vol. 40, no. 5, pp. 4-8, 2023, doi: 10.1109/MS.2023.3306641.

[28] J. Christensen, J. M. Hansen, and P. Wilson, "Understanding the role and impact of generative artificial intelligence (AI) hallucination within consumers’ tourism decision-making processes," Current Issues in Tourism, pp. 1-16, 2024, doi: 10.1080/13683500.2023.2300032.

[29] G. Menzel, "ChatGPT – the solution architect of the future?" LinkedIn, Mar. 13, 2023, [Online]. Available: https://www.linkedin.com/pulse/chatgpt-solution-architect-future-gunnar-menzel (accessed: Apr. 22, 2024).

[30] G. D. Everett and R. McLeod, Software Testing: Testing Across the Entire Software Development Life Cycle. Hoboken, NJ: John Wiley and Sons, Inc., 2007.

[31] M. S. Sulaiman, M. H. I. Jamaludin, and Z. Derasit, "Code cody: A game-based learning platform for programming education," Journal of ICT in Education, vol. 10, no. 1, pp. 79-91, 2023, doi: 10.37134/jictie.vol10.1.7.2023.

[32] R. Ramadan and Y. Widyani, "Game development life cycle guidelines," 2013 International Conference on Advanced Computer Science and Information Systems (ICACSIS), Sanur Bali, Indonesia, 2013, pp. 95-100, doi: 10.1109/ICACSIS.2013.6761558.

Wednesday, 1 May 2024

Dockerizing Python Apps on Windows

Docker is a popular tool in software development and deployment workflows released in 2013. It is a platform that uses OS-level virtualization* to deliver software in packages called containers.

*(a form of virtualization where the operating system kernel allows the existence of multiple isolated user space instances, called containers, to run concurrently on a single host operating system. It shares the host operating system's kernel among the containers, conversely to traditional virtualization where each virtual machine (VM) runs its own separate operating system. For this reason, containers are typically faster to start up and use less memory!).

Docker is used for developing, shipping, and running applications. It utilizes containerization technology to package applications and their dependencies into standardized units called containers which run the application in isolation, away from other processes on the host machine. These containers encapsulate everything needed to run the application, including the code, runtime, libraries, and system tools, ensuring that the application behaves consistently across different environments.

Let’s imagine being part of a development team working on a Node.js application with very specific version requirements. This application needs to be shared with another developer on the team who must run it on their computer. To ensure it runs correctly, they need to set up their development environment to match mine. This involves installing the same version of Node.js, all project dependencies, and configurations such as environment variables. The setup is significant and should be applied to any machine running the same application. Docker and containers were developed to solve this problem.
 
-------------------------------------------------------------------
OBJECTIVE

In this post, I will illustrate how to (1) install Docker on Windows, (2) create an image for a simple Python application, and (3) run the image. 


THE APPLICATION

When given a name, this Python application outputs a tailored greeting message.

def greeting (name):
    phrase = 'Hello, ' + name + '!'
    return phrase    

if __name__ == '__main__':
    name = input('What is your name? ')
    print(greeting(name))

This Python file, called greeting.py, is saved in a folder that I specifically created for this exercise.


INSTALL DOCKER DESKTOP ON WINDOWS

To do this, Docker Desktop should be installed. I am using Windows, so its installation is trickier than the installation on a computer which already has a Linux distribution.

The reason for this is ignored in this post but it might be the subject for another post.

This page contains the download URL, information about system requirements, and instructions on how to install Docker Desktop for Windows. Basically, to run Docker, I have to run a full Linux environment on Windows without a virtual machine. For this, WSL, which is a Windows subsystem for Linux, can be used. To install WSL, instructions can be found here
 
 
DOCKER IMAGES

Docker images are blueprints (read-only) for containers. They are essentially a snapshot of a filesystem that includes everything needed to run an application: the application code, runtime environment, libraries, dependencies, and any additional configurations or commands required. 
 
Once a Docker image is created, it cannot be modified; instead, it must be recreated. When you run a Docker image, a container is created based on that image. Images can typically be shared without significant worries regarding compatibility.

Docker images are organised in layers. Generally, the first layer is the parent image which includes a lightweight OS and a runtime environment. Parent images for Docker can be found in a public repository called Docker Hub. Here we have a list of parent images to choose from and "pull" (download).


DOCKERFILE

A Dockerfile is a text file that contains a set of instructions used to build a Docker image. These instructions specify the steps needed to create a Docker image, including setting up the environment, installing dependencies, copying files into the image, and configuring the container's behaviour.

Each instruction in a Dockerfile roughly translates to an image layer. The order of Dockerfile instructions matters.

How a Dockerfile translates into a stack of layers in a container image (docker.docs).

In the folder where my Python application is, I create a file called "Dockerfile", with the capital "D" and no extension (I use Visual Studio Code with the Docker package installed). A list of commands that can be used in a Dockerfile can be found here.

The Dockerfile for my Python application contains:

# Define the structure of the Docker image. 
# Start from the top.
  
# Use a Python runtime as the base image.
# Found on Docker Hub.
FROM python:3.12-alpine

# Set working directory in the container (app).
# Commands are now executed relative to this dir.  
WORKDIR /app

# Copy the current dir contents into /app.
# First . ->Files in the dir where the Dockerfile is.
    # Source directory (host machine). 
# Second . ->Install files in /app.
    # Destination directory (container).  
COPY . .

# Run the application when the container starts.
CMD ["python", "greeting.py"]

 

DOCKER BUILD

The docker build command compiles the instructions from the Dockerfile to create the Docker image. 

I make sure that Docker Desktop is running on my computer. 

In the same directory where the Dockerfile is, in the terminal, I type docker build -t name_of_the_app .

-t is a flag used to give a name and a tag to the image (tag is "latest" if not specified).

. is the relative path to the Dockerfile (I am already in that directory).

This creates the Docker image which can be found in the Docker Desktop under "Images". From there, I can select the image and run a new container. Then I can select that container and start it.

However, starting the container does not launch the Python application. In fact, under "Logs" for that specific container in the Docker Desktop, I found an EOFError: EOF related to the part of the code which asks for an input (the user's name). In the context of running a Docker container, this error may occur if there is no interactive terminal available for the container to accept user input. When running a Docker container, the default behaviour is non-interactive, meaning it does not allow for interactive input from the user. The container for this image must be recreated. Read down on how to solve this.


DOCKER RUN VIA CLI

docker images -> list all available images.

docker run -it --name container_1 name_of_the_app -> to run a container named "container1" from the "name_of_the_app" image.

-it is used to

  • allocate a pseudo-TTY which enables terminal-like features such as displaying output and accepting input (t).
  • enable interactivity (i). Indeed, the "-i" flag instructs Docker to attach STDIN for the container, allowing me to interact with it. I required the user to insert a name as the input for the Python application so interactivity is needed. This solves  the EOFError related to the input.

With this, the Python application runs on the terminal no problem as soon as I create the container. If I want to run it again, I need to re-start the container.

docker ps -> list all running containers.

docker ps -a -> list all containers.

docker stop container_1 -> to stop "container_1".

docker start container_1 -> to start a "container_1" which was stopped.

In my case, when I start the container again, I need to make it interactive, so I have to type:  

docker start -i container_1

No need to enable terminal-like features with the "-t" flag again, since these features have been embedded in the container when I first created it through the CLI.    

However, stopping and restarting a container to run an application which is on it is not functional because it would reset the container's state, potentially losing any changes made during the container's previous execution.

Alternatively, I can use

docker exec -it container_1 python greeting.py 

to execute a command inside a running container without restarting it. Now, when my container is running, I can execute the Python application every time I want!

In the writing of this post, I ignored .dockerignore and Volumes, which might become the subject for another post.

Monday, 1 April 2024

S3 File Editor App: Integrating Python with AWS

In this post, I illustrate how I tackled the problem of making a specific application in Python that would communicate with AWS services. 

You can find the code in this repository: https://github.com/gianlucaballa/s3-file-editor

Task: Create an application that allows users to effortlessly share and modify written information such as materials, quantities, and important notes with one another.

The application needs to meet the following criteria:

  • Any user should be able to open the application on a pc with a double-click.
  • Upon opening the application, users should have immediate access to a simple text file for viewing, editing, and saving (structure for the text file is not necessary – a blank text file suffices).
  • The user can read, modify, and save the text file for other users to use.

This application will be specifically used by building engineers to easily share information such as material to buy, quantity and similar notes regarding construction sites. 

No overheads: ease of use is vital here.

Key criteria: accessibility, seamless file handling, collaboration. 

----------------------------------------------------------------------------------------------------------------------

My solution:

At first, I thought about using RDS in AWS and creating a simple table with 3 columns for a MySQL database. I steered away from this solution because it would have over complicated the code for the execution of SQL commands, without producing any significant benefit.

Instead, I proceeded with the following steps:

  1. I created an S3 bucket in AWS using a specific user with specific permissions and credentials.
  2. I uploaded an empty text file with a specific name to the S3 bucket.
  3. I wrote a Python application using boto3*.

*(Boto3 is the official AWS SDK for Python. It provides an easy-to-use Python interface to interact with various AWS services such as S3. With Boto3, developers can programmatically manage AWS resources, automate tasks, and build applications that leverage AWS services without needing to manually configure API requests). 

This solution showed to be effective and satisfied the established key criteria, as it will be demonstrated below.

----------------------------------------------------------------------------------------------------------------------

Explanation:

By sharing and analysing the Python code that I wrote for the application (see point 3. above), you can better understand the operation of the application that I designed.

    The code (formatted with Black):

import boto3
import os


def download_file(bucket_name, key, local_filename):
    s3 = boto3.client(
        "s3",
        region_name="insert_region",
        aws_access_key_id="insert_id",
        aws_secret_access_key="insert_secret",
    )
    s3.download_file(bucket_name, key, local_filename)


def upload_file(bucket_name, key, local_filename):
    s3 = boto3.client(
        "s3",
        region_name="insert_region",
        aws_access_key_id="insert_id",
        aws_secret_access_key="insert_secret",
    )
    s3.upload_file(local_filename, bucket_name, key)


def edit_file(local_filename):
    os.system(f'notepad "{local_filename}"')


def main():
    bucket_name = "insert_bucket_name"
    key = "insert_file_name.txt"
    local_filename = "temp_file.txt"

    # Download the file from S3.
    download_file(bucket_name, key, local_filename)

    # Allow the user to edit the file.
    edit_file(local_filename)

    # Upload the modified file back to S3.
    upload_file(bucket_name, key, local_filename)

    # Clean up the temporary file.
    os.remove(local_filename)

    print("Success!")


if __name__ == "__main__":
    main()

import boto3
import os

These import the "boto3" module and the "os" module. The "os"  module provides a way of using the operating system dependent functionality. For example, it allows the application to execute a command in the system's shell.
 
def download_file(bucket_name, key, local_filename):
    s3 = boto3.client(
        "s3",
        region_name="insert_region",
        aws_access_key_id="insert_id",
        aws_secret_access_key="insert_secret",
    )
    s3.download_file(bucket_name, key, local_filename)
 
This function called download_file takes 3 arguments. 
Once called, it creates an S3 client object, in other words, an interface through which your Python code can communicate with Amazon S3. In order to do this, it is necessary to specify the region in which the S3 exists, the AWS access key and secret access key of the AWS user (see point 1. above).
 
Hardcoding keys is never a good idea because they can be seen by anyone looking at the code! I hardcoded them to test the application.
 
Then the download_file function downloads the file from the specified S3 bucket (bucket_name) with the specified key/name of the file (key) to the local file (local_filename) on the file system using the function (usually the local file is where the file with the code is on the pc). s3.download_file(bucket_name, key, local_filename) is a specific function provided by Boto3.
 
def upload_file(bucket_name, key, local_filename):
    s3 = boto3.client(
        "s3",
        region_name="insert_region",
        aws_access_key_id="insert_id",
        aws_secret_access_key="insert_secret",
    )
    s3.upload_file(local_filename, bucket_name, key)
 
This is a similar function but now it uploads the local file (local_filename) on the file system using the function to the specified S3 bucket (bucket_name) with the specified key/name of the file (key). s3.upload_file(local_filename, bucket_name, key) is a specific function provided by Boto3.
 
def edit_file(local_filename):
    os.system(f'notepad "{local_filename}"')
 
The edit_file function opens the specified file (local_filename) in the default text editor of the system using the os.system function. Since I am testing this application in Windows, I specified "notepad" as the default text editor.
 
def main():
    bucket_name = "insert_bucket_name"
    key = "insert_file_name.txt"
    local_filename = "temp_file.txt"
 
    # Download the file from S3.
    download_file(bucket_name, key, local_filename)

    # Allow the user to edit the file.
    edit_file(local_filename)

    # Upload the modified file back to S3.
    upload_file(bucket_name, key, local_filename)

    # Clean up the temporary file.
    os.remove(local_filename)

    print("File has been updated and uploaded to S3.")
 
In Python, main() is a conventional name for the main entry point of a script or program. It's a function that typically contains the main logic or sequence of actions that the script should perform when executed.The purpose of defining a main() function is to encapsulate the main functionality of the script and to provide a clear starting point for the program's execution. This makes the code more modular and easier to understand, as the main logic is isolated within a specific function. 
 
In this case, main() is used to call the functions that I defined above in a specific order (download, edit, upload), clean up the temporary file on the pc once it is uploaded to S3 (using os.remove(local_filename)) and print a message once the process is concluded. In main(), I also establish variables that will be used as arguments for the functions: the name of the S3 bucket (see point 1. above), the name of the .txt file that I initially uploaded to S3 (see point 2. above) and the local file name (temp_file.txt works fine for this).

if __name__ == "__main__":
    main()

This final block ensures that the main() function is executed only when the script is run directly, not when it's imported as a module into another script. This allows the script to be used both as a stand-alone program and as a reusable module. 
 
Final notes:
  • Ensure that the IAM user associated with the AWS credentials has the necessary permissions to access the specified S3 bucket and perform read/write operations on the objects.
  • Make sure to handle sensitive information such as AWS access keys securely.
  • This script is intended for educational purposes and can be modified to suit specific requirements. 

----------------------------------------------------------------------------------------------------------------------

To transform the script into a clickable .exe, I can use

pyinstaller --onefile my_script_name.py
After PyInstaller finishes, it will create a "dist" directory in the script's directory, containing the executable file. This executable can be distributed to others.

Friday, 1 March 2024

Adapting Visual References in Concept Art For Monster Design

(This is a short version of one of my academic articles that you can find here).

There is efficacy in adapting visual references (3D renders and photos) to concept art for high-budget game development and film production.

For example, embedding visual references into an artwork for time efficiency, correct use of perspective and establishment of believable textures is significant in a video game triple-A development. The search for realism enhanced by the use of visual references also shows to be advantageous in designing uncanny monsters. 

Visual references can be manipulated in software such as Photoshop to prepare not only the blueprints for the 3D modelling/sculpting stage but also to design the special effects makeup for live-action monsters and animatronics. 

There is a gap between our current understanding of the uncanny valley, as it is defined in robotics, and the process of designing characters. Investigating this subject is important for a dual reason:

  1. It moves knowledge forward in the field of the uncanny valley’s applications to concept art, since this has not been investigated in depth.
  2. It helps professional concept artists in shaping and controlling the uncanniness of antagonistic characters.

Analyses on industrial practice showed that:

  • The use of photorealistic references to be implanted directly into concept art is not a mandatory request for all game developments and digital effects film productions but it is increasingly encouraged for certain products such as triple-A games because it reduces hiccups in the workflow: indeed, this practice spares the artist from hand painting texture details through brush strokes and minimizes perspective mistakes.
  • When it comes to designing uncanny monsters, the use of these references pushes the design towards realism facilitating the triggering of the uncanny valley phenomenon at a design level – as highlighted by the current literature on the subject. The horror genre often favours rich textures (e.g., organic material such as blood, filth, rustiness, etc.) not only in characters but environments too – this adds to the subtle subversion of the concept of affinity which is at the centre of the uncanny valley and it is commonly used in horrors to make the viewer feel vulnerable. 

In the light of this, the adaptation of photorealistic visual references might represent a strong starting point for concept artists who aim to trigger the "uncanniness" through character design. This type of reference should be directly inserted into the work and then transformed through deformation tools, photo bashing and minimal painting. The use of "previs", in collaboration with the animation department, can implement the monster’s movements, since these contribute to the uncanniness of the creature. 

A study on the finalisation of the sculpting and modelling work which analyses how to convey the texture of the uncanny monster in a three-dimensional environment (e.g., UV mapping) would represent a natural development for a research which aims to formalise a specific industrial pipeline. 

Furthermore, an investigation into the role of scriptwriting and sound on making uncanny monsters for films and games would be a valuable supplement because it could make clearer how the integration of visuals, narrative and audio influences the design of the uncanny monster. Study on sound in particular would offer significant insight that can be applied in robotics.

Generative AI – like Midjourney, Stable Diffusion and OpenAI’s DALL-E – might bring a significant change to contemporary practice. In fact, the use of AI has already demonstrated to be powerful in testing ideas, establishing colour palettes and producing suggestive photographic references with a high degree of realism. Because of this and their impact on the concept art practice, generative AI applied to this subject requires further investigations.

Photo by Pavel Danilyukyuk: https://www.pexels.com/photo/close-up-shot-of-white-robot-toy-8294606/Photo by Pavel Danilyuk: https://www.pexels.com/photo/close-up-shot-of-white-robot-toy-8294606/

 

Generative AI Assisting Software Architecture Design for Video Games

Generative AI presents a promising avenue for revolutionising software architecture design processes in the video game industry. This study ...