Building the User Interface with Gradio

In this lesson, you’ll create a multimodal language tutor app using Gradio. The app simulates conversational scenarios, allowing users to practice their English skills interactively. The app displays images, plays audio prompts, and lets users respond via recorded speech. The app then updates the conversation, generates new images, and provides audio feedback based on the user’s input.

App Overview

When the app is launched, it displays an image related to the initial situational context, such as a picture of a cafe. An audio prompt plays, such as “Welcome to Cute Cafe. What would you like to order?” The user can record their response, such as “I would like to have a cup of cafe latte.” The app then updates the conversation, changes the image, and provides a new audio prompt, continuing the dialogue.

Here’s a screenshot of the multimodal language tutor app interface at the beginning:

Image of the Tutor app in the beginning
Image of the Tutor app in the beginning

After you add audio input through the microphone to create a conversation, the app regenerates the image and provides a response, allowing you to continue the conversation for an extended period. This is a screenshot of the multimodal language tutor app after you provide the audio input:

Image of the Tutor app after giving audio input
Image of the Tutor app after giving audio input

Key Components

Here are the key components:

  • Initialization: Start with a seed prompt to generate the initial situational context and corresponding image.
  • User Interaction: Record the user’s speech response via the microphone.
  • Conversation Update: Transcribe the recorded speech to text, update the conversation history, and generate new responses.
  • Visual and Audio Feedback: Update the displayed image and play the new audio prompt based on the updated conversation.

Inputs and Outputs

Here are the inputs and outputs:

  • Inputs:
    • Audio file (recorded via microphone)
  • Outputs:
    • Image (updated based on conversation context)
    • Text (generated conversation response)
    • Audio file (generated speech response)

Flow of the Program

  1. Initialization:
    • Generate an initial situational description and image based on a seed prompt.
  2. User Interaction:
    • The user records an audio response.
    • Transcribe the audio to text.
  3. Conversation Update:
    • Update the conversation history with the new user input.
    • Generate a new conversation response.
    • Update the combined history for future interactions.
  4. Visual and Audio Feedback:
    • Generate a new image based on the updated history.
    • Generate and play a new audio prompt from the conversation response.
  5. Outputs:
    • Display the updated image and transcribed text.
    • Display the new audio response.

State Preservation

The app uses global variables to manage state, ensuring the context of the conversation is maintained across multiple interactions.

See forum comments
Download course materials from Github
Previous: Demo of Generating Situational Prompts & Images Next: Demo of Building the User Interface with Gradio