Skip to content

Private space with python client API returning 404 #6388

Closed
@muhammadumair894

Description

@muhammadumair894

Describe the bug

I have created a sample private gradio space, and called it with HF token, but got an error in response, meanwhile works fine if the change space visibility to public.
Need help to resolve this issue. Thanks in advance.

from gradio_client import Client

client = Client("https://gic-qa.hf.space/--replicas/qfd/", hf_token="hf_umXwOeMSkURPBTFWD....")
result = client.predict("my name is abc ",3999,api_name="/predict")	

print(result)

Error

[/usr/local/lib/python3.10/dist-packages/gradio_client/utils.py](https://localhost:8080/#) in stream_sse(client, data, hash_data, helper, sse_url, sse_data_url, cookies)
    408                         return resp["output"]
    409                 else:
--> 410                     raise ValueError(f"Unexpected message: {line}")
    411         raise ValueError("Did not receive process_completed message.")
    412     except asyncio.CancelledError:

ValueError: Unexpected message:

Have you searched existing issues? 🔎

  • I have searched and found no existing issues

Reproduction

import gradio as gr

def process_input(text, number):

  | # You can perform any processing or computation here
  | # For simplicity, this example just combines the inputs into a dictionary
  | result = {'input_text': text, 'input_number': number}
  | return result
  |  
  | iface = gr.Interface(
  | fn=process_input,
  | inputs=["text", "number"],
  | outputs="json"
  | )
  |  
  | iface.launch()

Screenshot

No response

Logs

Loaded as API: https://orblogic-qa-ui-api.hf.space/--replicas/qfm9d/ ✔
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-24-270722ffafe2> in <cell line: 4>()
      2 
      3 client = Client("https://orblogic-qa-ui-api.hf.space/--replicas/qfm9d/", hf_token="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")
----> 4 result = client.predict("my name is khan ",3999,api_name="/predict")
      5 
      6 print(result)

12 frames
/usr/local/lib/python3.10/dist-packages/gradio_client/client.py in predict(self, api_name, fn_index, *args)
    303                 "Cannot call predict on this function as it may run forever. Use submit instead."
    304             )
--> 305         return self.submit(*args, api_name=api_name, fn_index=fn_index).result()
    306 
    307     def new_helper(self, fn_index: int) -> Communicator:

/usr/local/lib/python3.10/dist-packages/gradio_client/client.py in result(self, timeout)
   1454             >> 9
   1455         """
-> 1456         return super().result(timeout=timeout)
   1457 
   1458     def outputs(self) -> list[tuple | Any]:

/usr/lib/python3.10/concurrent/futures/_base.py in result(self, timeout)
    456                     raise CancelledError()
    457                 elif self._state == FINISHED:
--> 458                     return self.__get_result()
    459                 else:
    460                     raise TimeoutError()

/usr/lib/python3.10/concurrent/futures/_base.py in __get_result(self)
    401         if self._exception:
    402             try:
--> 403                 raise self._exception
    404             finally:
    405                 # Break a reference cycle with the exception in self._exception

/usr/lib/python3.10/concurrent/futures/thread.py in run(self)
     56 
     57         try:
---> 58             result = self.fn(*self.args, **self.kwargs)
     59         except BaseException as exc:
     60             self.future.set_exception(exc)

/usr/local/lib/python3.10/dist-packages/gradio_client/client.py in _inner(*data)
    867             if self.client.serialize:
    868                 data = self.serialize(*data)
--> 869             predictions = _predict(*data)
    870             predictions = self.process_predictions(*predictions)
    871             # Append final output only if not already present

/usr/local/lib/python3.10/dist-packages/gradio_client/client.py in _predict(*data)
    892             }
    893 
--> 894             result = utils.synchronize_async(self._sse_fn, data, hash_data, helper)
    895             if "error" in result:
    896                 raise ValueError(result["error"])

/usr/local/lib/python3.10/dist-packages/gradio_client/utils.py in synchronize_async(func, *args, **kwargs)
    662         **kwargs:
    663     """
--> 664     return fsspec.asyn.sync(fsspec.asyn.get_loop(), func, *args, **kwargs)  # type: ignore
    665 
    666 

/usr/local/lib/python3.10/dist-packages/fsspec/asyn.py in sync(loop, func, timeout, *args, **kwargs)
    104         raise FSTimeoutError from return_result
    105     elif isinstance(return_result, BaseException):
--> 106         raise return_result
    107     else:
    108         return return_result

/usr/local/lib/python3.10/dist-packages/fsspec/asyn.py in _runner(event, coro, result, timeout)
     59         coro = asyncio.wait_for(coro, timeout=timeout)
     60     try:
---> 61         result[0] = await coro
     62     except Exception as ex:
     63         result[0] = ex

/usr/local/lib/python3.10/dist-packages/gradio_client/client.py in _sse_fn(self, data, hash_data, helper)
   1073     async def _sse_fn(self, data: dict, hash_data: dict, helper: Communicator):
   1074         async with httpx.AsyncClient(timeout=httpx.Timeout(timeout=None)) as client:
-> 1075             return await utils.get_pred_from_sse(
   1076                 client,
   1077                 data,

/usr/local/lib/python3.10/dist-packages/gradio_client/utils.py in get_pred_from_sse(client, data, hash_data, helper, sse_url, sse_data_url, cookies)
    339     assert len(done) == 1
    340     for task in done:
--> 341         return task.result()
    342 
    343 

/usr/local/lib/python3.10/dist-packages/gradio_client/utils.py in stream_sse(client, data, hash_data, helper, sse_url, sse_data_url, cookies)
    408                         return resp["output"]
    409                 else:
--> 410                     raise ValueError(f"Unexpected message: {line}")
    411         raise ValueError("Did not receive process_completed message.")
    412     except asyncio.CancelledError:

ValueError: Unexpected message: <!DOCTYPE html>
<html class="">
<head>
    <meta charset="utf-8"/>
    <meta
            name="viewport"
            content="width=device-width, initial-scale=1.0, user-scalable=no"
    />
    <meta
            name="description"
            content="We’re on a journey to advance and democratize artificial intelligence through open source and open science."
    />
    <meta property="fb:app_id" content="1321688464574422"/>
    <meta name="twitter:card" content="summary_large_image"/>
    <meta name="twitter:site" content="@huggingface"/>
    <meta
            property="og:title"
            content="Hugging Face – The AI community building the future."
    />
    <meta property="og:type" content="website"/>

    <title>Hugging Face – The AI community building the future.</title>
    <style>
        body {
            margin: 0;
        }

        main {
            background-color: white;
            min-height: 100vh;
            padding: 7rem 1rem 8rem 1rem;
            text-align: center;
            font-family: Source Sans Pro, ui-sans-serif, system-ui, -apple-system,
            BlinkMacSystemFont, Segoe UI, Roboto, Helvetica Neue, Arial, Noto Sans,
            sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol,
            Noto Color Emoji;
        }

        img {
            width: 6rem;
            height: 6rem;
            margin: 0 auto 1rem;
        }

        h1 {
            font-size: 3.75rem;
            line-height: 1;
            color: rgba(31, 41, 55, 1);
            font-weight: 700;
            box-sizing: border-box;
            margin: 0 auto;
        }

        p {
            color: rgba(107, 114, 128, 1);
            font-size: 1.125rem;
            line-height: 1.75rem;
            max-width: 28rem;
            box-sizing: border-box;
            margin: 0 auto;
        }

        .dark main {
            background-color: rgb(11, 15, 25);
        }

        .dark h1 {
            color: rgb(209, 213, 219);
        }

        .dark p {
            color: rgb(156, 163, 175);
        }
    </style>
    <script>
        // On page load or when changing themes, best to add inline in `head` to avoid FOUC
        const key = "_tb_global_settings";
        let theme = window.matchMedia("(prefers-color-scheme: dark)").matches
            ? "dark"
            : "light";
        try {
            const storageTheme = JSON.parse(window.localStorage.getItem(key)).theme;
            if (storageTheme) {
                theme = storageTheme === "dark" ? "dark" : "light";
            }
        } catch (e) {
        }
        if (theme === "dark") {
            document.documentElement.classList.add("dark");
        } else {
            document.documentElement.classList.remove("dark");
        }
    </script>
</head>

<body>
<main>
    <img
            src="https://huggingface.co/front/assets/huggingface_logo.svg"
            alt=""
    />
    <div>
        <h1>404</h1>
        <p>Sorry, we can’t find the page you are looking for.</p>
    </div>
</main>
</body>
</html>

System Info

HF Spaces

Severity

Blocking usage of gradio

Metadata

Metadata

Assignees

Labels

RegressionBugs did not exist in previous versions of GradiobugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions