Playground exclude unavailable packages #9998
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
LLM can generate an app that imports Python standard libraries and the LLM-based requirement list generator can add even these package names, which causes the following error.
This PR fixes it by checking if the package exists on PyPI and removing unavailable ones from the generated requirements.
Example:
https://87fa2dfb.gradio-website.pages.dev/playground?demo=Hello_World&code=IyBTYW1wbGUgR3JhZGlvIGFwcCB1c2luZyB0aGUgcmFuZG9tIHBhY2thZ2UKaW1wb3J0IGdyYWRpbyBhcyBncgppbXBvcnQgcmFuZG9tCgojIERlZmluZSBhIGZ1bmN0aW9uIHRoYXQgZ2VuZXJhdGVzIGEgcmFuZG9tIGdyZWV0aW5nCmRlZiByYW5kb21fZ3JlZXQobmFtZSk6CiAgICBncmVldGluZ3MgPSBbIkhlbGxvIiwgIkhpIiwgIkhleSIsICJHcmVldGluZ3MiXQogICAgcmV0dXJuIGYie3JhbmRvbS5jaG9pY2UoZ3JlZXRpbmdzKX0ge25hbWV9ISIKCiMgQ3JlYXRlIGEgR3JhZGlvIGludGVyZmFjZSB0aGF0IHRha2VzIGEgdGV4dGJveCBpbnB1dCwgcnVucyBpdCB0aHJvdWdoIHRoZSByYW5kb21fZ3JlZXQgZnVuY3Rpb24sIGFuZCByZXR1cm5zIG91dHB1dCB0byBhIHRleHRib3guCmRlbW8gPSBnci5JbnRlcmZhY2UoZm49cmFuZG9tX2dyZWV0LCBpbnB1dHM9InRleHRib3giLCBvdXRwdXRzPSJ0ZXh0Ym94IikKCiMgTGF1bmNoIHRoZSBpbnRlcmZhY2UuCmlmIF9fbmFtZV9fID09ICJfX21haW5fXyI6CiAgICBkZW1vLmxhdW5jaChzaG93X2Vycm9yPVRydWUp&reqs=
The prompt that generated the example app above: