Repository: gradio-app/gradio

Issue:
Add testing to make sure share=True, iframe, and Spaces don't break on release



Discussion:
What we need is a GitHub action that runs *after* the pypi package is deployed and programmatically tests:
* That `share=True` is working with the latest release
* That demos appears properly in iframes with the latest release
I think we should do a pre-release prior to the official release to make sure we don't publish a broken version.
Ah yeah that’s much better!


Resolving patch:
diff --git a/demo/kitchen_sink/run.py b/demo/kitchen_sink/run.py
--- a/demo/kitchen_sink/run.py
+++ b/demo/kitchen_sink/run.py
@@ -152,6 +152,7 @@ def fn(
     * 3,
     theme="default",
     title="Kitchen Sink",
+    cache_examples=False,
     description="Try out all the components!",
     article="Learn more about [Gradio](http://gradio.app)",
 )
diff --git a/scripts/upload_demo_to_space.py b/scripts/upload_demo_to_space.py
new file mode 100644
--- /dev/null
+++ b/scripts/upload_demo_to_space.py
@@ -0,0 +1,78 @@
+import argparse
+import pathlib
+import shutil
+import tempfile
+import textwrap
+from typing import Optional
+
+import huggingface_hub
+
+
+def upload_demo_to_space(
+    demo_name: str, space_id: str, hf_token: str, gradio_version: Optional[str]
+):
+    """Upload a demo in the demo directory to a huggingface space.
+    Args:
+        demo_name: The name of the demo to upload.
+        space_id: The id of the space to upload the demo to.
+        hf_token: HF api token. Need to have permission to write to space_id for this to work.
+        gradio_version: If not None, will set the gradio version in the created space to the given version.
+    """
+
+    with tempfile.TemporaryDirectory() as tmpdir:
+        demo_path = pathlib.Path(pathlib.Path().absolute(), f"demo/{demo_name}")
+        shutil.copytree(demo_path, tmpdir, dirs_exist_ok=True)
+        app_file = pathlib.Path(tmpdir, "run.py")
+        # Rename the app file to be app.py
+        app_file.rename(app_file.with_stem("app"))
+        if gradio_version:
+            readme = pathlib.Path(tmpdir, "README.md")
+            readme_content = f"""
+                                ---
+                                title: {space_id.split("/")[-1]} 
+                                emoji: 💩
+                                colorFrom: indigo
+                                colorTo: indigo
+                                sdk: gradio
+                                sdk_version: {gradio_version}
+                                app_file: app.py
+                                pinned: false
+                                ---
+                                """
+            readme.open("w").write(textwrap.dedent(readme_content))
+
+        api = huggingface_hub.HfApi()
+        huggingface_hub.create_repo(
+            space_id,
+            space_sdk="gradio",
+            repo_type="space",
+            token=hf_token,
+            exist_ok=True,
+        )
+        api.upload_folder(
+            token=hf_token,
+            repo_id=space_id,
+            repo_type="space",
+            folder_path=tmpdir,
+            path_in_repo="",
+        )
+    return f"https://huggingface.co/spaces/{space_id}"
+
+
+if __name__ == "__main__":
+    parser = argparse.ArgumentParser(description="Upload a demo to a space")
+    parser.add_argument("demo_name", type=str, help="Name of demo to upload")
+    parser.add_argument(
+        "space_id", type=str, help="Name of the space to upload the demo to"
+    )
+    parser.add_argument("hf_token", type=str, help="HF API token")
+    parser.add_argument(
+        "--gradio-version",
+        type=str,
+        help="If not None, will set the gradio version in the created space to the given version.",
+    )
+    args = parser.parse_args()
+    new_space = upload_demo_to_space(
+        args.demo_name, args.space_id, args.hf_token, args.gradio_version
+    )
+    print(new_space)


Test patch: