How to install a specific version of gradio in Spaces?

Hi,

The last version of gradio (2.7.0) comes with a display bug (launch this notebook diff_texts.ipynb from gradio at HighlightedText).

With the version 2.6.4 of gradio, there was no display bug:

However, when you create an App with gradio, Hugging Face Spaces says that the gradio package comes pre-installed at version 2.2.6. I think this text needs an update. (cc @sgugger)

More, I did try to create a new Spaces App with gradio. In the requirements.txt file, I added gradio==2.6.4 but it did not work.

How can I install the gradio version of my choice for a Spaces App? Thank you.

Note: see this issue on gradio github about the version 2.7.0 and HighlightedText.

1 Like

Sorry about that! We’re fixing the bug but for now you can install a specific version of Gradio by adding lines like this at the top of your app.py file:

import os
os.system("pip uninstall -y gradio")
os.system("pip install gradio==2.6.4")
2 Likes

Is there still no better way to do this?

1 Like

Now you can specify the Gradio version you want with sdk_version in the README.md. Here is an example: README.md ¡ multimodalart/mindseye-lite at main

3 Likes

Great! Thanks!

While sdk_version can be used to specify an official version, can I use my own fork? In fact the version had been specified in the requirements.txt, I just want to suppress RUN pip install --no-cache-dir gradio==3.24.1 which canceled my installation.

hi @JanuaryDesk , you can’t change the base docker for Gradio SDK. however you could build your own Dockerfile for you app and use sdk:docker for example Dockerfile · sayakpaul/demo-docker-gradio at main

On another note, you can always specify a custom gradio package on the requirements.txt have you tried that?

git+https://github.com/username/gradio.git@branch#egg=gradio

SDK gradio installation is after the requirements.txt installation so it doesn’t work. As I don’t figure out how to install pnpm, my current hack is to upload a zip file gradio.zip containing the working directory of my fork, then extract and install it in the app.py, which looks like this:

import os

def p(command):
    print("EXEC: " + command)
    os.system(command)

p("mkdir _gradio")
p("mv gradio.zip _gradio")
os.chdir("_gradio")

from zipfile import ZipFile

z = ZipFile("gradio.zip")
z.extractall()
p("pip uninstall gradio")
p("pip install -e .")
print(os.getcwd())
import sys
sys.path.append(os.getcwd())
os.chdir("..")

Next time I need something like that I will try docker.

hi @JanuaryDesk great, point, I’m looking internally the possibility to change the order! thanks

Hi @radames was there any progress on changing the requirements installation order? (i.e. controlling when requirements.txt is called with reference to the final system pip install - “–> RUN pip install --no-cache-dir streamlit==1.28.2 “uvicorn>=0.14.0” spaces==0.18.0”). I’m aware this can be done by running os.system(“pip install …”), but this seems cumbersome.

I am facing an issue now with my apps that run on haystack, since the upgrade to spaces==0.18.0 (as this version requires pydantic==2.5.1)

hi @mtyrrell the Docker file for our predefined SDKs (Gradio/Streamlit) are a bit inflexible. However we now offer a pre-requirements.txt not sure if that would helpful. Another alternative is to use a custom Dockerfile, here is a Gradio example Dockerfile ¡ SpacesExamples/Gradio-Docker-Template at main

1 Like

On another note, you can always specify a custom gradio package on the requirements.txt have you tried that?

When I tried that after setting up Docker I got this error:

Did you install Gradio from source files? You need to build the frontend by running /scripts/build_frontend.sh

As I don’t figure out how to install pnpm , my current hack is to upload a zip file gradio.zip containing the working directory of my fork, then extract and install it in the app.py , which looks like this

When I tried this I got this error:

file:///home/user/app/_gradio does not appear to be a Python project: neither ‘setup.py’ nor ‘pyproject.toml’ found.

I haven’t found a way to use a gradio fork in huggingface spaces.

Hi @Yntec, Gradio has a complex build process. I recommend using any of the versions available on PyPI: gradio ¡ PyPI.

Thank you, but none of those versions work for me, as all the versions from 3.16.0 suffer from this bug:

Breaking my spaces.

Version 3.15.0 used to work, see this space built with it:

If you duplicate it, fetching models takes so long it goes over the 30 minutes limit and it won’t build.

I haven’t been able to update that space since January 25 because of this, and I need a custom gradio solution that is 3.15.0 but with gr.load implemented.

But it seems not possible, killing the space.

Update 2024/3/26: Everything working fine currently and I didn’t need to upgrade Gradio, yay!