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
32.54k stars 2.45k forks source link

Build desktop apps with Gradio #2257

Open divamgupta opened 2 years ago

divamgupta commented 2 years ago

Would be cool for developers to create desktop apps using Gradio!

abidlabs commented 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?

divamgupta commented 2 years ago

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.

pngwn commented 1 year ago

What if you could package a gradio app as a desktop app?

petrov826 commented 1 year ago

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.

lvelvee commented 1 year ago

LGTM. The pywebview library will be very helpful.

abidlabs commented 1 year ago

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?

petrov826 commented 1 year ago

@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.

abidlabs commented 1 year ago

Sorry @petrov826 I meant that this is the proposed approach. It’s not currently implemented in gradio

petrov826 commented 1 year ago

@abidlabs I'm sorry too. I was jumping to a hasty conclusion.πŸ˜… Implementing new gradio command gradio package is a great idea!!

CreaperLost commented 1 year ago

Yes, this is the most common and simple way to do.

thunder-007 commented 1 year ago

Is this feature available now?

thunder-007 commented 1 year ago

I'm trying something like putting it inside electron but the above idea will be cool gradio package

abidlabs commented 1 year ago

Not yet!

nayan924 commented 1 year ago

will the pyinstaller method used to convert pyqt work on gradio? Till the gradio package app.py command is built?

nayan924 commented 1 year ago

today marks official 1 year+ of this thread life. Deliver web apps which use user's pc resources still remains a dream.

es617 commented 11 months ago

+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?

hypoechoic commented 9 months ago

@abidlabs This is a great feature that can increase the reach of Gradio. Is this in the roadmap?

abidlabs commented 9 months ago

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

thunder-007 commented 9 months ago

@abidlabs I'm interested in contributing with some guidance I'm new to complex opensource projects.

abidlabs commented 9 months ago

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.

qasimk30 commented 7 months ago

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

freddyaboulton commented 7 months ago

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

borisalmonacid commented 4 months ago

up

borisalmonacid commented 2 months ago

up :D

abidlabs commented 2 months ago

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

rafaeljcd commented 6 days ago

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

image

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)
abidlabs commented 6 days ago

Cool! Cc @whitphx something to explore after 5.0 launch