gradio-app / gradio

Build and share delightful machine learning apps, all in Python. 🌟 Star to support our work!
http://www.gradio.app
Apache License 2.0
29.49k stars 2.19k forks source link

Gradio Client package for NodeJS not connecting to HF Space, but Python one works normally. #8213

Closed mahiatlinux closed 1 week ago

mahiatlinux commented 2 weeks ago

Describe the bug

Hey guys. The Gradio Client package for NodeJS doesn't seem to be working correctly. It does not connect to the Space.

NodeJS:

import { client } from "@gradio/client";

const app = await client("mahiatlinux/MasherAI-v6-7B-Chat");
const result = await app.predict("/chat", [        
                "Hello!!", // string  in 'Message' Textbox component        
                "Hello!!", // string  in 'System prompt' Textbox component        
                1, // number (numeric value between 1 and 2048) in 'Max new tokens' Slider component        
                0.1, // number (numeric value between 0.1 and 4.0) in 'Temperature' Slider component        
                0.05, // number (numeric value between 0.05 and 1.0) in 'Top-p (nucleus sampling)' Slider component        
                1, // number (numeric value between 1 and 1000) in 'Top-k' Slider component        
                1, // number (numeric value between 1.0 and 2.0) in 'Repetition penalty' Slider component
    ]);

console.log(result.data);

Output:

maheswar@linuxboi4:~$ node app.mjs
Cannot connect to SSE endpoint: https://mahiatlinux-masherai-v6-7b-chat.hf.space/queue/data?session_hash=zcpzs1ec9kk

The Python one works normally and connects to the Space. For eg Python:

from gradio_client import Client

client = Client("mahiatlinux/MasherAI-v6-7B-Chat")
result = client.predict(
    "Hello!!",  # str in 'Message' Textbox component
    "Hello!!",  # str in 'System prompt' Textbox component
    200,  # float (numeric value between 1 and 2048) in 'Max new tokens' Slider component
    0.7,  # float (numeric value between 0.1 and 4.0) in 'Temperature' Slider component
    0.05,  # float (numeric value between 0.05 and 1.0) in 'Top-p (nucleus sampling)' Slider component
    1,  # float (numeric value between 1 and 1000) in 'Top-k' Slider component
    1,  # float (numeric value between 1.0 and 2.0) in 'Repetition penalty' Slider component
    api_name="/chat"
)
print(result)

Output:

maheswar@linuxboi4:~$ python3 app.py
Loaded as API: https://mahiatlinux-masherai-v6-7b-chat.hf.space ✔
Hey there! How can I make your day better?

Have you searched existing issues? 🔎

Reproduction

import { client } from "@gradio/client";

const app = await client("mahiatlinux/MasherAI-v6-7B-Chat");
const result = await app.predict("/chat", [        
                "Hello!!", // string  in 'Message' Textbox component        
                "Hello!!", // string  in 'System prompt' Textbox component        
                1, // number (numeric value between 1 and 2048) in 'Max new tokens' Slider component        
                0.1, // number (numeric value between 0.1 and 4.0) in 'Temperature' Slider component        
                0.05, // number (numeric value between 0.05 and 1.0) in 'Top-p (nucleus sampling)' Slider component        
                1, // number (numeric value between 1 and 1000) in 'Top-k' Slider component        
                1, // number (numeric value between 1.0 and 2.0) in 'Repetition penalty' Slider component
    ]);

console.log(result.data);

Screenshot

No response

Logs

No response

System Info

maheswar@linuxboi4:~$ gradio environment
Gradio Environment Information:
------------------------------
Operating System: Linux
gradio version: 4.21.0
gradio_client version: 0.12.0

------------------------------------------------
gradio dependencies in your environment:

aiofiles: 23.2.1
altair: 5.2.0
fastapi: 0.109.2
ffmpy: 0.3.2
gradio-client==0.12.0 is not installed.
httpx: 0.27.0
huggingface-hub: 0.20.3
importlib-resources: 6.3.0
jinja2: 3.1.3
markupsafe: 2.1.5
matplotlib: 3.5.1
numpy: 1.26.4
orjson: 3.10.3
packaging: 23.2
pandas: 2.2.0
pillow: 9.0.1
pydantic: 2.6.0
pydub: 0.25.1
python-multipart: 0.0.9
pyyaml: 5.4.1
ruff: 0.3.2
semantic-version: 2.10.0
tomlkit==0.12.0 is not installed.
typer: 0.9.0
typing-extensions: 4.11.0
uvicorn: 0.27.1
authlib; extra == 'oauth' is not installed.
itsdangerous; extra == 'oauth' is not installed.

gradio_client dependencies in your environment:

fsspec: 2023.10.0
httpx: 0.27.0
huggingface-hub: 0.20.3
packaging: 23.2
typing-extensions: 4.11.0
websockets: 11.0.3

Severity

Blocking usage of gradio

pngwn commented 2 weeks ago

What version of @gradio/client do you have installed?

mahiatlinux commented 2 weeks ago

What version of @gradio/client do you have installed?

@pngwn image

It's the latest one.

image

pngwn commented 2 weeks ago

Thank you! I shall take a look.

fwag commented 2 weeks ago

I have the same issue with version 0.18.0.

Anyway I've tried with version 0.17.0 but I never receive "on data" and the status callback gave me an "error"

image

<input id="photo" type="file">
 <div id="results"></div>

 <script type="module">
        import { Client } from "https://cdn.jsdelivr.net/npm/@gradio/client@0.17.0/dist/index.min.js";

    async function loaded(reader) {

        const app = await Client.connect('ratotna/unconscious');

        const result =app.submit('/predict', [
                                        reader.result,   // blob in 'img' Image component
                ]).on("data", (data) => console.log("data " + data))
                .on("status", (status) => console.log(status));

    }
    function read() {
        const reader = new FileReader();
        reader.addEventListener('load', () => loaded(reader))
        reader.readAsDataURL(photo.files[0]);
    }
    photo.addEventListener('input', read);
    </script>
mahiatlinux commented 1 week ago

@pngwn Any updates?

I have tested some of the older versions like 0.17.0 and 0.16.0. A new Window not defined error in the older versions.

pngwn commented 1 week ago

We will need to release a new version get a fix out unfortunately. Early next week.

mahiatlinux commented 1 week ago

We will need to release a new version get a fix out unfortunately. Early next week.

Hmmm... OK Thanks! Could you please give me a specific date? It is pretty urgent for me sorry.

sharkqwy commented 1 week ago

Met same bug...Been debugging for a while... Really tried couple different ways in JS to call SSE. It's wired none of the audio ASR model is working for me. Hope to see the fix out soon

mahiatlinux commented 1 week ago

@pngwn How to install for NPM? Thanks!

pngwn commented 1 week ago

We will release this fix later today.

aigchacker commented 1 week ago

Hey @mahiatlinux , I tried to call your model using the latest 0.19.0. It's giving out different error msg but still not working on model with Sever Sent Events. Becuase it's not working on my model either. I just wanna check if this is error in my config or the SDK is still generally off. @pngwn Error message like:

client.predict Error:  {
  type: 'status',
  endpoint: '/chat',
  fn_index: 9,
  time: 2024-05-11T16:08:13.032Z,
  queue: true,
  message: null,
  stage: 'error',
  code: undefined,
  success: false
}
Error Message: null