Repository: gradio-app/gradio

Issue:
Share Breaks In Spaces
### Describe the bug

share=True usage in launch gives error in spaces

### Reproduction

https://huggingface.co/spaces/ruhwang2001/wonder-app/blob/main/app.py

`interface.launch(debug=True, share=True)`

### Screenshot

_No response_

### Logs

```shell
Running on local URL:  http://localhost:7860/
█
*** Failed to connect to ec2.gradio.app:22: [Errno 110] Connection timed out
```


### System Info

```shell
Spaces
```


### Severity

critical


Discussion:
@aliabid94 @aliabd  @abidlabs As far as I can see in the codebase we are not aware if we are on HF Spaces in the interface class.
Shall we have a environment variable in spaces which will notify us we are using HF spaces? Just like utils.colab_check().

That makes sense. We can coordinate with the Spaces team to set up that environmental variable. 

My suggestion would be that if this environmental variable is set **and `share=True`**, then we print a helpful warning to the user saying that for Spaces, `share` should be set to `False`. 

(Instead of overriding `share` as I don't think we should override an explicit parameter with an implicit environmental variable)
Gonna make us of these env variables for this issue
good point! cc @cbensimon 

Resolving patch:
diff --git a/gradio/interface.py b/gradio/interface.py
--- a/gradio/interface.py
+++ b/gradio/interface.py
@@ -123,7 +123,7 @@ def __init__(
         css: Optional[str] = None,
         height=None,
         width=None,
-        allow_screenshot: bool = True,
+        allow_screenshot: bool = False,
         allow_flagging: Optional[str] = None,
         flagging_options: List[str] = None,
         encrypt=None,
@@ -135,7 +135,7 @@ def __init__(
         enable_queue=None,
         api_mode=None,
         flagging_callback: FlaggingCallback = CSVLogger(),
-    ):
+    ):  # TODO: (faruk) Let's remove depreceated parameters in the version 3.0.0
         """
         Parameters:
         fn (Union[Callable, List[Callable]]): the function to wrap an interface around.
@@ -155,7 +155,7 @@ def __init__(
         thumbnail (str): path to image or src to use as display picture for models listed in gradio.app/hub
         theme (str): Theme to use - one of "default", "huggingface", "seafoam", "grass", "peach". Add "dark-" prefix, e.g. "dark-peach" for dark theme (or just "dark" for the default dark theme).
         css (str): custom css or path to custom css file to use with interface.
-        allow_screenshot (bool): if False, users will not see a button to take a screenshot of the interface.
+        allow_screenshot (bool): DEPRECATED if False, users will not see a button to take a screenshot of the interface.
         allow_flagging (str): one of "never", "auto", or "manual". If "never" or "auto", users will not see a button to flag an input and output. If "manual", users will see a button to flag. If "auto", every prediction will be automatically flagged. If "manual", samples are flagged when the user clicks flag button. Can be set with environmental variable GRADIO_ALLOW_FLAGGING.
         flagging_options (List[str]): if provided, allows user to select from the list of options when flagging. Only applies if allow_flagging is "manual".
         encrypt (bool): DEPRECATED. If True, flagged data will be encrypted by key provided by creator at launch
@@ -217,6 +217,11 @@ def __init__(
                 "The `verbose` parameter in the `Interface`"
                 "is deprecated and has no effect."
             )
+        if allow_screenshot:
+            warnings.warn(
+                "The `allow_screenshot` parameter in the `Interface`"
+                "is deprecated and has no effect."
+            )
 
         self.status = "OFF"
         self.live = live
@@ -277,6 +282,7 @@ def clean_html(raw_html):
 
         self.thumbnail = thumbnail
         theme = theme if theme is not None else os.getenv("GRADIO_THEME", "default")
+        self.is_space = True if os.getenv("SYSTEM") == "spaces" else False
         DEPRECATED_THEME_MAP = {
             "darkdefault": "default",
             "darkhuggingface": "dark-huggingface",
@@ -731,6 +737,8 @@ def launch(
             share = True
 
         if share:
+            if self.is_space:
+                raise RuntimeError("Share is not supported when you are in Spaces")
             try:
                 share_url = networking.setup_tunnel(server_port, private_endpoint)
                 self.share_url = share_url
@@ -791,6 +799,7 @@ def launch(
             "api_mode": self.api_mode,
             "server_name": server_name,
             "server_port": server_port,
+            "is_spaces": self.is_space,
         }
         if self.analytics_enabled:
             utils.launch_analytics(data)


Test patch: