-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add curl Api Docs examples #4932
Comments
I strongly agree, we need to be able to support cURL -- not only for those users who want to use cURL but because cURL often serves as a template that people adapt into whatever language they are working with (Swift, Android Java, etc.). Because queuing is enabled by default in Spaces, and most interesting API routes are going to have queuing enabled, I would like to propose another option that would work with queueing:
|
That's a neat idea! I'm hesitant to hold onto the results in the server because that would break with replication (very viral demos) and is not REST-ful. Another crazy option is that we can refactor the queue to work with server-sent events and not websockets. Curl natively supports server-sent events. The good thing (outside of this issue) is that every request (regardless of queueing) is restful HTTPS but we would break two-way communication between client and server. However, all the communication we send from the client can be sent as soon as it connects. It should be possible. Anyway, just mentioning this since this kind of change could be possible with 4.0. For posterity, this is what ❯ websocat --text ws://127.0.0.1:7860/queue/join
{"msg":"send_hash"}
{"fn_index": 0, "session_hash": "12312"}
{"msg":"estimation","rank":0,"queue_size":1,"avg_event_process_time":0.0,"avg_event_concurrent_process_time":null,"rank_eta":null,"queue_eta":1.0}
{"msg":"send_data"}
{"data": ["0", "add", "5"], "fn_index": 0}
{"msg":"process_starts"}
{"msg":"process_completed","output":{"data":[5.0],"is_generating":false,"duration":0.00023818016052246094,"average_duration":0.00023818016052246094},"success":true} |
Server sent events are a worse solution imo. They have more overhead and more limitations. They don't support binary data (we don't currently need this but removing the option when our system supports it seems odd to me), number of open connections is limited (depending on protocol, tends to be more aggressive on mobile), they result in larger payloads in both directions (post and sse stream) and we actually sent a lot of updates, it would be difficult to figure out when to remove people from the queue. And all two way communication would need to be sent out of band and remapped by the server potentially increasing complexity. SSE isn't super simple to set up either you have to post an event and then setup some kind of subscription to an event source in whatever way that works for your language. You also need to do more work to map requests back to responses. I don't think this usecase is common enough for us to warrant rearchitecting, considering those limitations. I just think we should document the WebSocket contract and encourage people to create clients. I'm not against a 'submit' route but it would have limitations. |
(FWIW we use SSE for all other HF projects 😅 ) |
I don't think a submit route and a result route violate REST though. Submit is a request to start a job and result/id is a request for a resource. I would consider the result data that could be stored in a db and fetched by the get result route. Whether that is an in memory db or something is just an implementation detail. What I don't understand about /submit is how do they know when the job is complete? |
Are there any projects that implement a queue or handle binary data and use SSE? I'd be curious to know how those problems had been solved elsewhere. |
Yeah this is the main issue. Potentially
The We've discussed SSE before but it would require a massive refactor (plus might not support everything as @pngwn pointed out) so I think it should be done only if none of the other paths are viable :) |
There's native support for WebSockets inside Apple's networking framework, although I don't have direct experience with it. I think that cURL requests are more readable and can serve as documentation on their own, which is very valuable. However, if the cURL requests do not really represent the way things work (as shown by having to break things up into two new endpoints), then we may be adding more complexity and maintainability burden. If documentation is our main goal, I'd maybe use cURL requests for illustration purposes, stating that they are not compatible with the queue system, and direct users to the websockets spec to create apps in other languages. We can potentially keep an uncurated collection of community clients somewhere. I don't know the specifics or constraints surrounding this task, though. |
How do I use /api/submit and /api/result? I couldn't find any examples in the documentation. Can you provide an example to help me? |
Hi! I'm strongly in favor of this, and as I understand it, the switch to SSE with v4 should make this a lot easier. I'd be happy to contribute to the docs if I can actually figure out the usage patterns for the backend API. @abidlabs any chance these exist somewhere that I'm not seeing so far? |
Hi @mathematicalmichael we actually started implementing this before we realized that the curl syntax is not well-suited for sending json in SSE. The reason for this is SSE basically requires you to use a GET request to send the first message to establish the SSE, and so you need to encode the payload through GET's query parameters. This technically doable, but the syntax is just quite great with JSON, e.g. curl "http://localhost:7860/queue/join?fn_index=0&session_hash=1&data=%5B%22hello%22%5D" to send "hello" to a simple "hello world" gradio example: import gradio as gr
gr.Interface(lambda x:x, "textbox", "textbox").launch() In short, we won't add curl examples to all the Gradio demos since the syntax is quite ugly, particularly for more complex examples, but it is doable if you want to rig it up yourself for a particular demo. |
How do you queue join from curl API when you are sending a json payload? { |
hey i'm checking back since... gradio api on HF still doesn't work for me - hasn't since november or so. |
@yosun @freddyaboulton Any solution to this? I want to run a curl command. I get: |
Hi @ryanshrott , we have not prepared docs for Curl usage yet. |
Any fix for this? { |
@ryanshrott @shivmsingh I wrote a short curl how-to guide that should hold you over until we get the official docs in place |
@freddyaboulton Thanks alot, really appreciate it. |
@freddyaboulton When will the official docs be in place? I'd prefer just to do a simple post request if possible? Will the official docs be simpler to use? |
@abidlabs Do you know the timeline for adding back CURL examples to the gradio API docs? |
@ryanshrott in the next month or so |
Is your feature request related to a problem? Please describe.
We should add some curl examples to the ApiDocs like we used to have.
Some users don’t want to use python or JavaScript clients.
Describe the solution you'd like
The problem of course is that curl won’t respect the queue. So what should be do about apps that have queueing enabled?
Additional context
Add any other context
The text was updated successfully, but these errors were encountered: