-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🚀 Migrating to Gradio 5 #9463
Comments
@blaisewf what version of Python are you running? Gradio 5 requires Python 3.10 or higher |
@abidlabs ow, seems that i was using 3.9, i'll try with 3.10, thanks! do you know why 3.9 isn't supported now? |
Hi @blaisewf we take advantage of certain typing features which were introduced in Python 3.10. Since Python 3.10 is about 3 years old at this point, we are asking users to upgrade to that version of Python. |
@abidlabs nice, thanks for the info and the great job! if i can provide some feedback, the new design of sliders are very strange, without the background would be better |
Thanks, it looks like that bug is specific to the soft theme in dark mode, but let me cc @hannahblair |
ah good catch, thanks @blaisewf! |
@abidlabs this new gradio version broken theme builder right? this fuction stuck on loading, and now my current theme that i made need be adjusted because somethings on css changed. |
hmm I don't think so, @aliabid94 can you confirm? |
Yep I'm seeing issues too, taking a look |
Congratulations on the release of gradio 5.0. I have created a web-ui using gradio. |
@aliabid94 i am facing some problems with themes after last update to gradio 5, problems with theme classes not being applied correctly, i opened a new issue for this. #9671 |
Dear @abidlabs , is it possible to use the old theme in gradio 4 with the theme setting? I myself really miss the old raised button style, the new style is too flat for me. |
Below are the issues I encountered when migrating the Gradio version from 3.50.2 to 5.0.2:
In the end, I had to downgrade to version 4.44.1 to get everything working again... |
Try setting |
Thank you so much! |
Thanks @avan06 for the detailed feedback. We're looking into fixing these issues. Just to understand a few things
Why do you need to assign an
You can just do
Yes, this is an intentional breaking change. See above:
Finally, you mention that 5.0.2 did not work for you on Spaces. Can you please link the Space here so we can take a look? |
Thank you, @abidlabs, for your response and explanation. I set the ...
translateInput = gr.State(value="...")
sourceInput = gr.State(value="...")
translateInput.elem_id = "translateInput"
sourceInput.elem_id = "sourceInput"
...
inputDict.update({translateInput, sourceInput})
submitBtn.click(fn=ui.transcribe_entry_progress, inputs=inputDict, outputs=outputs)
def transcribe_entry_progress(self, data: dict, progress=gr.Progress()):
dataDict = {}
for key, value in data.items():
dataDict.update({key.elem_id: value})
return self.transcribe_webui(dataDict, progress=progress) Below is the link to my spaces (currently downgraded to version 4.44.1): |
@abidlabs I have a problem. Not sure if it's only me or if it's been reported by others too. I am seeing a minor issue. Basically, when I click submit in my app, I earlier had a progress bar that showed how long it takes. It showed the progress or something of those sorts, so my users know they had to wait. After I updated to Gradio 5, I see that the app starts and processing happens in the background. However, I don't see any progress in the GUI itself. After I click submit, there is no feedback on the GUI. There is no feedback on the progress. Although when the app finishes running, it shows the appropriate output though. It is the during the processing stage where I have the problem. |
Hi @abidlabs, Congratulations on the great update to Gradio 5! I have an important question: some custom components, especially the Gradio ImageSlider, broke after the upgrade. I use this component in almost all my projects, and it's essential for me. Is there a plan to add an ImageSlider component directly in Gradio, or should I contact the creator of the ImageSlider to update it for Gradio 5 compatibility? |
Hi @MomenSirri, yes @pngwn (who is the developer of the ImageSlider custom component) will be rebuilding the custom component for Gradio 5. Should be out this week I believe, but if you need it sooner, you can also clone the files of the custom component and follow these steps to make it Gradio 5-compatible: |
Hi @abidlabs, in gradio 5 the authentication not working and keep reload and write incorrect credential while the app in gradio 4 is running right and nothing has changed to this version |
For some reason Gradio now adds "gradio_api" to the URLs of all files that it reads in temp. Is there any way to get rid of this? Also, the predictions api does not work anymore with blob files as the input images anymore. The old version of Gradio automatically extracted the images out of the blob files and saved them in another directory in the temp folder and used them for the predictions but in version 5 it is not working anymore. |
@abidlabs, This broke some real stuff.
@avan06, I have faced the same issue after bumping to Gradio 5.x.x and have figured out a temporary but costly workaround. |
@KingMahmud, you saved me! The information you provided was spot on, and after testing, I've successfully bumped to version 5.4.0. Thank you so much! |
You are welcome. |
@abidlabs @aliabid94 Guys, since the release of gradio 5 I haven't had much success running my application in this new version, so I think it's more appropriate for me to stay on version 4.44.1, I wanted to launch my new webui in the new version but I think it will be shot in the foot. However I am also working with dynamic components in version 4.44.1 and have reported some bugs about these components so that you can fix them (I noticed that few people use this feature, but I think you may have the opportunity for a real case to act on these bugs) I believe they could be happening in version 5 as well but as I wasn't able to run version 5 I can't confirm it yet. |
Hi @elismasilva because of our team’s limited bandwidth, we are not planning on issuing patches for 4.x. We are looking into the issues around dynamically rendered components, but the patches will be released as part of 5.x. We are happy to help you migrate to Gradio 5, please feel free to create issues based on the problems that you are seeing upgrading |
Waiting for PWA! This will be a game changer. Gradio could be used to make apps for all platforms! |
👋 Hi Gradio community,
We’ve been hard at work over the past few months, and we are excited to announce today the stable release of Gradio 5! Here's some high-level information about using Gradio 5
Major Features
Installation
Gradio 5 depends on Python 3.10 or higher, so if you are running Gradio locally, please ensure that you have Python 3.10 or higher, or download it here: https://www.python.org/downloads/
gradio
locally, simply install Gradio 5 withpip install gradio --upgrade
gradio
Space to use Gradio 5, you can simply update thesdk_version
to be5.0.0
inREADME.md
.In most cases, that’s all you have to do to run Gradio 5.0. If you start your Gradio application, you should see your Gradio app running, with a fresh new UI.
Server-Side Rendering (Optional)
Gradio 5 includes the capability to serve apps via server-side rendering (SSR), which includes SEO and performance improvements (e.g. much faster load times for the initial page — no more Gradio loading spinner!). To run in SSR mode, you’ll need to have Node 20+ installed. Please install it here: https://nodejs.org/en/download/package-manager. Node is not required to run Gradio, as Gradio will fall back on client-side rendering when Node is not found. You’ll need to also set the
ssr_mode=True
parameter in.launch()
or set the environment variable:GRADIO_SSR_MODE="true"
.SSR will automatically be enabled on Spaces for apps that run Gradio 5! If you would like to disable it, you can set
ssr_mode=False
inlaunch()
.Breaking Changes
Gradio 5 is a major release and we've made some breaking changes in order for security, performance, or a more consistent developer experience across the library. Here is a complete list of breaking changes:
Component-Specific Changes
gr.Audio
.wav
automaticallyPreviously, the default value of the
format
in the[gr.Audio](http://gr.audio/)
component was"wav"
, meaning that audio files would be converted to the.wav
format before being processed by a prediction function or being returned to the user. Now, the default value offormat
isNone
, which means any audio files that have an existing format are kept as is. We do not expect this change to affect most users, but if you want to recover the original behavior, please setformat="wav"
explicitly ingr.Audio
.gr.Code
gr.Code
is not supportedPreviously, passing a tuple to
gr.Code
would open the filepath corresponding to the first element of the tuple and display it in the front-end. For security reasons, this is no longer supported and thegr.Code
component will only display strings of code starting in version 5.0. Instead, you should read the file and return its contents. E.ggr.FileExplorer
root
parameter ingr.FileExplorer
has been removedIn Gradio 4, this parameter was already deprecated and was replaced with
root_dir
. In Gradio 5, this parameter has been removed altogether. Useroot_dir
instead.gr.LoginButton
andgr.LogoutButton
signed_in_value
parameter ingr.LoginButton
has been removedIn Gradio 4, this parameter was already deprecated and was replaced with
logout_value
. In Gradio 5, this parameter has been removed altogethergr.LogoutButton
component has been removedThis component is unnecessary as the
gr.LoginButton
now transforms into a logout button once a user logs ingr.Image
gr.Image
component unlesstype=filepath
Since SVGs cannot be converted to numpy arrays or PIL images natively, they could cause Gradio apps to break if they were passed as input images. Now, they are only accepted if
type="filepath"
, otherwise an error is displayed to the user.gr.DataFrame
height
parameter ingr.DataFrame
has been renamed tomax_height
The behavior of this parameter is exactly the same as before, but the new name better reflects its behavior, which is to set a maximum height before contents scroll.
.change()
event ingr.DataFrame
is now also triggered when header values changePreviously, the
.change()
event would only be triggered if the cell values changed, but since the “value” of agr.DataFrame
includes its headers, the new behavior is more appropriate.gr.Chatbot
likeable
parameter ofgr.Chatbot
has been removed. The chatbot will display like buttons whenever thelike
event is defined.This was generally intended to be an internal parameter, now it is no longer needed and removed from the constructor.
gr.Chatbot
.Previously, both bot messages and user messages could be liked; however, this led to a more cluttered UI. Now only bot messages are like-able by default. To display like buttons in the user message, set the
user_like_button
parameter of the.like()
event toTrue
.gr.ChatInterface
examples_per_page
parameter ofgr.ChatInterface
has been removed.Examples are now displayed within the chat interface window, and so there is no need for this parameter.
gr.Dropdown
choices
listPreviously, the
gr.Dropdown
would show an empty value as the default. However, this is not desirable, as user-defined functions may error out if aNone
value is passed in for theDropdown
. Nevertheless, if you would like the original behavior, set the value of theDropdown
component like this:gr.Row
equal_height
parameter has been set toFalse
.This means that components in a
gr.Row
will not be stretched to be of the equal height by default. To preserve this change, simply pass inequal_height=True
ingr.Row()
.Changes Affecting Multiple Components
file_type
parameter for various file-based input components (specifically,gr.File
,gr.Gallery
,gr.MultimodalTextbox
, andgr.UploadButton
is now enforced in the backend)Previously, the
file_type
parameter was not enforced in the backend. Meaning that if a user was able to submit an invalid filetype through their browser (or by using the clients), it would get passed into the prediction function. Now, the backend will raise an exception instead.info
parameter now accepts Markdown/HTMLAny string passed into the
info
parameter will be as Markdown and displayed accordingly, enabling developers to add links, emphasize text, etc.gr.Textbox
orgr.MultimodalTextbox
if they are emptyIf there is no text in a
gr.Textbox
, a user will not be able to submit it by pressing enter. Likewise, if there is no text and no files in agr.MultimodalTextbox
, a user will not be able to submit it.Security-related Changes
In Gradio 4.x, you can return any file on your machine from a function and Gradio will post-process it and display it in the UI. Starting with version 5.0, only files in the current working directory or temp directory will be post-processed for security reasons.
As an example, let’s say you have a text-to-image application that’s running from the
/app/text-to-image
directory. In Gradio 4.0, saving images to the/img/
directory would work:But in Gradio 5.0, you have to save the image in
/app/text-to-image
(or a subdirectory of it)We expect this change to impact a small number of applications but Gradio will output a helpful error message if you return an image outside the current working directory. If you have any questions on this change, please consult this [guil;de](https://307f1325.gradio-website.pages.dev/main/guides/file-access) first before reaching out on Github or Discord.
null
origin by defaultThis change is unlikely to have any impact on your Gradio app unless you are using web components to embed your Gradio app and you are testing your Gradio app in a local file through your browser. If that is the case, you can set
strict_cors=False
inlaunch()
.With the exception of audio, image, video, json, and text files, which are displayed in-browser, all other files that Gradio serves (e.g. using the
File
component) will be downloaded rather than opened in browser to reduce XSS.To prevent SSRF attacks, Gradio does not allow URLs that serve to [localhost](http://localhost) paths as values for components. This means that if you pass in a URL like
[http://127.0.0.1:7860/file=lion.jpg](http://127.0.0.1:7881/file=lion.jpg)
togr.Image
, it will raise a ValueError.Changes related to
gr.Interface
andgr.ChatInterface
undo_btn
,retry_btn
andclear_btn
parameters ofgr.ChatInterface
have been removed, and accepted types forsubmit_btn
andstop_btn
arguments have changedThe ChatInterface UI has been modernized! The row of buttons for undoing messages, retrying messages, or clearing the chat history has been removed entirely and instead these buttons are now built into the
gr.Chatbot
component. See below:Additionally, the accepted type for
submit_btn
andstop_btn
arguments has changed. Instead of specifying an instance of agr.Button
, these parameters now take a boolean or a string value. IfFalse
, the submit or stop buttons will not be displayed. If a string, that text will be displayed in the corresponding button.allow_flagging
parameter ingr.Interface
has been renamed toflagging_mode
Similarly, the environment variable GRADIO_ALLOW_FLAGGING has been renamed to GRADIO_FLAGGING_MODE
additional_inputs_accordion_name
parameter has been removed fromgr.ChatInterface
You can set this by passing in a custom
gr.Accordion
object intogr.ChatInterface
instead, e.g.thumbnail
parameter has been removed fromgr.Interface
In Gradio 4, this parameter was already deprecated and had no effect. In Gradio 5, this parameter has been removed altogether
css
,js
, andhead
parameters ingr.Interface
,gr.ChatInterface
, andgr.Blocks
no longer accept filepaths.Previously, you could provide either a code string or string filepaths in the
js
andcss
parameters and Gradio would try to determine if you meant a filepath or a code string. To avoid potential ambiguity and unexpected behavior, nowstr
is only interpreted as code. If you would like to pass in a filepath, you can use newcss_paths
orhead_paths
parameters.Miscellaneous Changes
every
parameter is no longer supported in event listenersPreviously, if you wanted to run an event “every” X seconds after a certain trigger, you could set
every=
in the event listener. This is no longer supported — if you see the following error:EventListener._setup.<locals>.event_trigger() got an unexpected keyword argument 'every'
, you’ll need to do the following instead:gr.Timer
component, and.tick()
method to trigger the event.E.g., replace something like this:
with:
This makes it easy to configure the timer as well to change its frequency or stop the event, e.g.
concurrency_count
parameter has been removed from.queue()
In Gradio 4, this parameter was already deprecated and had no effect. In Gradio 5, this parameter has been removed altogether.
gr.make_waveform
method has been removed from the libraryThe
gr.make_waveform
helper method, which was used to convert an audio file to a waveform overlaid on top of an image, has been removed fromgradio
since theAudio
component now supports waveforms natively. If you would like to use this method, you can find the source code here:gradio/gradio/helpers.py
Line 1022 in 0978de8
Previously, to lazy-cache examples, you would pass in “lazy” to the
cache_examples
parameter inInterface
,Chatinterface
, orExamples
. Now, there is a separatecache_mode
parameter, which governs whether caching should be"lazy"
or (by default)"eager"
. So if your code was previously:Now, the code above your code should look like this:
gr.load
method now creates a ChatInterface for conversational models that are loaded from Hugging FacePreviously, e.g.
alias
parameter has been removed fromgr.load
.To provide a title for your Gradio app constructed from
gr.load
, you can pass in atitle
instead since thegr.load
accepts arbitrary kwargs which are passed into the constructor for the Gradio app.button_shadow
have each been replacedThese variables have been replaced with ones that start with
button_primary_shadow
andbutton_secondary_shadow
. If your code sets button_shadow in themes explicitly, replace each of instances with these two./gradio_api/
route.All internal Gradio API routes are now prefixed with
/gradio_api/
. This is important if you directly reference static files in your Gradio app, e.g. in yourgr.HTML
component. Instead of accessing files using/file=
, you should use/gradio_api/file=
, like this:In general, custom css and js is not guaranteed to work across Gradio versions. Gradio 5 includes significant changes to the HTML for each component, and custom css/js may need to updated to reference the right query selectors, etc.
Custom Components
Custom components built with Gradio 5.0 should be compatible with Gradio 4.0.
If you built your custom component in Gradio 4.0 you will have to rebuild your component to be compatible with Gradio 5.0. Simply follow these steps:
@gradio/preview
package.cd
into thefrontend
directory and runnpx npm-check-updates -u
andnpm update
.exports
inpackage.json
and add agradio
key to.
and./example
exports. For example:dependencies
key inpyproject.toml
to pin the maximum allowed Gradio version at version 5, e.g.dependencies = ["gradio>=4.0,<6.0"]
.What’s next for Gradio?
Many of the changes we’ve made in Gradio 5 are designed to enable new functionality that we will be shipping in the coming weeks. Stay tuned for:
And much more! With Gradio 5 providing a robust foundation to build web applications, we’re excited to really get started letting developers build all sorts of ML apps with Gradio.
Try Gradio 5 right now
Here are some Hugging Face Spaces that are running Gradio 5:
The text was updated successfully, but these errors were encountered: