Open divamgupta opened 2 years ago
Hey @divamgupta thanks for the suggestion! Will discuss this with the team. Can you tell me more about the motivation here? What are the use cases where the regular Gradio web app would not suffice and a desktop app would be more useful?
I feel there is a big demand for desktop applications. It running locally, it feels more natural to run a desktop application rather than an application opening in your web browser.
I had created a small application called diffusionbee, it got popular because of this reason. It would be been cool to use a framework like gradio to build it.
What if you could package a gradio app as a desktop app?
I agree with you @divamgupta !
With Gradio, you can create modern looking web pages with very short code. Potential users of Gradio might be developers who are creating interactive desktop applications using the Python GUI framework like PyQt, wxPython, Tkinter or something.
The use cases are many. Recently, digital transformation has increased the demand for commercial software. However, deploying commercial applications developed with Gradio to HuggingFace Spaces raises security and other concerns. And it is not practical to build a virtual environment on the user's computer so that the application can run on the user's local environment.
In summary, if we can build standalone desktop apps in Gradio, we developers can build high quality apps in a short amount of time and spend our time on more meaningful things.
LGTM. The pywebview
library will be very helpful.
One approach would be to make it possible to package a Gradio app as an executable. We could leverage pyinstaller
or a different library and expose it via the gradio
CLI.
For example, running:
gradio package app.py
would install pyinstaller (if needed) and then call it on the app.py
. We might need to make some tweaks so that the gradio app launches in a self-contained browser windows, but I think it should be pretty doable.
Would this address your use cases @divamgupta @petrov826 @lvelvee @CreaperLost?
@abidlabs Thank you for your information!
I tried gradio package app.py
, but got ERROR: Error loading ASGI app. Could not import module "package".
. It seems like package
is recognized as module.
I install gradio version 3.39.0 using pip. Here's my super simple app.py
below.
import gradio as gr
def greet(name):
return "Hello " + name + "!"
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
demo.launch()
Could you give me some more help?
Edit: There is a slightly related issue the 'package' argument is required to perform a relative import #3057 . It's already fixed.
Sorry @petrov826 I meant that this is the proposed approach. Itβs not currently implemented in gradio
@abidlabs I'm sorry too. I was jumping to a hasty conclusion.π
Implementing new gradio command gradio package
is a great idea!!
Yes, this is the most common and simple way to do.
Is this feature available now?
I'm trying something like putting it inside electron but the above idea will be cool gradio package
Not yet!
will the pyinstaller method used to convert pyqt work on gradio? Till the gradio package app.py command is built?
today marks official 1 year+ of this thread life. Deliver web apps which use user's pc resources still remains a dream.
+1. Having standalone desktop support would be huge!
Running on a standalone window is simple enough using pywebview. The real struggle seems to be the standalone packaging. Neither Pyinstaller nor Nuitka seem to work with basic configurations (some missing files or dependencies related to Gradio).
Has anyone successfully packaged a gradio app?
@abidlabs This is a great feature that can increase the reach of Gradio. Is this in the roadmap?
Thanks @hypoechoic I agree it could be interesting to explore. We've had some community contributors who are interested in this as well as are looking into it but don't really have an eta at this time. Happy to discuss more if you're interested in contributing in this direction
@abidlabs I'm interested in contributing with some guidance I'm new to complex opensource projects.
Hi @Thunder-007 thanks for your interest! This is a relatively complex issue so I'd suggest picking one of the issues labeled "good first issue" if you are new to complex opensource projects.
LGTM. The
pywebview
library will be very helpful.
Can you share basic code, how can this be done, im first time building desktop application and dont know how to integrate gradio with pywebview. Regards
Not sure about the third party solutions discussed in this thread but we are planning on supporting this in the future with gradio-lite see #7032 for more info
up
up :D
Hi @borisalmonacid this isn't on our immediate roadmap, although if you can share a little more about your use case, it might help us figure out how to prioritize this in our long-term plans
I managed to do a simple gradio with pywebview. It takes time for the initial launch though since it takes time for pywebview to open
import sys
from concurrent.futures import ProcessPoolExecutor
from pathlib import Path
import gradio as gr
import webview
def greet(name):
return "Hello " + name + "!"
def gui():
with gr.Blocks() as demo:
with gr.Tab(label="Tab 1"):
name = gr.Textbox(label="Name")
output = gr.Textbox(label="Output Box")
greet_btn = gr.Button("Greet")
greet_btn.click(fn=greet, inputs=name, outputs=output, api_name="greet")
with gr.Tab(label="Tab 2"):
name2 = gr.Textbox(label="Name", show_copy_button=True)
output2 = gr.Textbox(label="Output")
demo.launch(prevent_thread_lock=True)
def on_window_close():
sys.exit()
def launch_webview():
window = webview.create_window("App", "http://localhost:7860/")
window.events.closed += on_window_close
webview.start()
if __name__ == "__main__":
with ProcessPoolExecutor() as executor:
executor.submit(gui)
executor.submit(launch_webview)
Cool! Cc @whitphx something to explore after 5.0 launch
Would be cool for developers to create desktop apps using Gradio!