0

I am using Visual Studio Code with Pylance I am trying with the following program, the local host is being created, the gradio function also generates a link which when you physically enter in the browser opens the gradio program properly but is there any way that the gradio program can open in a new browser tab/window on clicking on the button.

import gradio as gr
import webbrowser
import tkinter as tk
import threading

# Define the Gradio program
def greet(name):
    return "Hello, " + name + "!"

iface = gr.Interface(greet, "text", "text", title="Greeting App", description="Enter your name to get a greeting")

# Define the function that launches the Gradio program in a browser
def launch_gradio():
    def run_gradio():
        iface.launch()

    thread = threading.Thread(target=run_gradio)
    thread.start()
    print("Click")

# Create a Tkinter window with a button
window = tk.Tk()
window.title("Gradio Launcher")
button = tk.Button(window, text="Launch Gradio", command=launch_gradio)
button.pack()

# Start the Tkinter event loop
window.mainloop()

I also tried 'webbrowser' module to open the link but it opens file explorer of the file that contains the program

  • 1
    See [ask]. Do a preliminary research. See the ```inbrowser``` option at [the reference](https://gradio.app/docs/#interface-launch-header). – relent95 Mar 22 '23 at 02:10

1 Answers1

0

Just set the inbrowser option to True when launching the interface:

def run_gradio():
    iface.launch(inbrowser=True)

This automatically launches the interface in a new tab on the default browser.

Yannick Funk
  • 1,319
  • 10
  • 23