Code lab – Adding a Gradio interface
This code picks up right where we left off in Chapter 5, except for the last set of lines representing the prompt probe attack. As we have at the beginning of all of our code labs, we are going to start with installing a new package, which is, of course, Gradio! We are also going to uninstall uvloop, because of a conflict with our other packages:
%pip install gradio %pip uninstall uvloop -y
This installs the gradio package and removes the conflicting uvloop package.
Next, we will add multiple packages to the list of imports:
import asyncio import nest_asyncio asyncio.set_event_loop_policy(asyncio.DefaultEventLoopPolicy()) nest_asyncio.apply() import gradio as gr
These lines import the asyncio and nest_asyncio libraries and set up the event loop policy. asyncio is a library for writing concurrent code using coroutines and event loops. nest_asyncio is a library that allows nested event loops in Jupyter notebook. The asyncio.set_event_loop_policy...