Skip to content
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

Build desktop apps with Gradio #2257

Open
divamgupta opened this issue Sep 13, 2022 · 31 comments
Open

Build desktop apps with Gradio #2257

divamgupta opened this issue Sep 13, 2022 · 31 comments
Labels
brainstorming Brainstorming issue enhancement New feature or request

Comments

@divamgupta
Copy link

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

@abidlabs
Copy link
Member

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?

@abidlabs abidlabs added the enhancement New feature or request label Sep 13, 2022
@divamgupta
Copy link
Author

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
Copy link
Member

pngwn commented Nov 15, 2022

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

@petrov826
Copy link
Contributor

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
Copy link

lvelvee commented Feb 24, 2023

LGTM. The pywebview library will be very helpful.

@abidlabs
Copy link
Member

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
Copy link
Contributor

petrov826 commented Jul 29, 2023

@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
Copy link
Member

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

@petrov826
Copy link
Contributor

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

@CreaperLost
Copy link

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

@thunder-007
Copy link

Is this feature available now?

@thunder-007
Copy link

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

@abidlabs
Copy link
Member

Not yet!

@nayan924
Copy link

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

@nayan924
Copy link

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

@es617
Copy link

es617 commented Nov 10, 2023

+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
Copy link

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

@abidlabs
Copy link
Member

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
Copy link

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

@abidlabs
Copy link
Member

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.

@abidlabs abidlabs changed the title Feature Request : Gradio for desktop apps Build desktop apps with Gradio Jan 10, 2024
@qasimk30
Copy link

qasimk30 commented Mar 5, 2024

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
Copy link
Collaborator

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
Copy link

up

@borisalmonacid
Copy link

up :D

@abidlabs
Copy link
Member

abidlabs commented Aug 7, 2024

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
Copy link

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
Copy link
Member

abidlabs commented Oct 1, 2024

Cool! Cc @whitphx something to explore after 5.0 launch

@csanadpoda
Copy link

csanadpoda commented Oct 22, 2024

UP!

I'm also trying to do this with PyInstaller and no matter what I do, I can't seem to add every package needed. Latest is a missing blocks_events.py.

@Purvarth
Copy link

UP! :)

@alexeygridnev
Copy link

alexeygridnev commented Nov 5, 2024

@csanadpoda , I did manage to build a pretty complex cross-platform desktop app using Gradio and Pyinstaller. I solved the issues with packaging Gradio thanks to the comments under this issue from Pyinstaller repository.

@whitphx
Copy link
Member

whitphx commented Nov 27, 2024

I'm working on packaging Gradio + PyWebView with PyInstaller to create an executable that launches a Gradio app and opens a webview window.
Here is the sample and how-to: https://github.com/whitphx/gradio-pyinstaller-example
CleanShot 2024-11-27 at 22 42 53@2x

Also thinking of making a one-stop command to do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
brainstorming Brainstorming issue enhancement New feature or request
Projects
None yet
Development

No branches or pull requests