mirror of
https://github.com/gradio-app/gradio.git
synced 2025-04-18 12:50:30 +08:00
Jupyter extension for easier development with Blocks (#1321)
* jupyter magic * formatting * test fix * formatting * simplifications * formatting
This commit is contained in:
parent
096f4b5b56
commit
2adb841316
@ -49,9 +49,24 @@ from gradio.flagging import (
|
||||
SimpleCSVLogger,
|
||||
)
|
||||
from gradio.interface import Interface, TabbedInterface, close_all
|
||||
from gradio.ipython_ext import load_ipython_extension
|
||||
from gradio.layouts import Box, Column, Group, Row, TabItem, Tabs
|
||||
from gradio.mix import Parallel, Series
|
||||
from gradio.templates import *
|
||||
from gradio.templates import (
|
||||
Files,
|
||||
Highlight,
|
||||
List,
|
||||
Matrix,
|
||||
Mic,
|
||||
Microphone,
|
||||
Numpy,
|
||||
Pil,
|
||||
PlayableVideo,
|
||||
Sketchpad,
|
||||
Text,
|
||||
TextArea,
|
||||
Webcam,
|
||||
)
|
||||
|
||||
current_pkg_version = pkg_resources.require("gradio")[0].version
|
||||
__version__ = current_pkg_version
|
||||
|
@ -415,6 +415,7 @@ class Blocks(BlockContext):
|
||||
ssl_keyfile: Optional[str] = None,
|
||||
ssl_certfile: Optional[str] = None,
|
||||
ssl_keyfile_password: Optional[str] = None,
|
||||
quiet: bool = False,
|
||||
_frontend: bool = True,
|
||||
) -> Tuple[FastAPI, str, str]:
|
||||
"""
|
||||
@ -440,6 +441,7 @@ class Blocks(BlockContext):
|
||||
ssl_keyfile (str | None): If a path to a file is provided, will use this as the private key file to create a local server running on https.
|
||||
ssl_certfile (str | None): If a path to a file is provided, will use this as the signed certificate for https. Needs to be provided if ssl_keyfile is provided.
|
||||
ssl_keyfile_password (str | None): If a password is provided, will use this with the ssl certificate for https.
|
||||
quiet (bool): If True, suppresses most print statements.
|
||||
Returns:
|
||||
app (FastAPI): FastAPI app object that is running the demo
|
||||
local_url (str): Locally accessible link to the demo
|
||||
@ -474,9 +476,10 @@ class Blocks(BlockContext):
|
||||
|
||||
if self.is_running:
|
||||
self.server_app.launchable = self
|
||||
print(
|
||||
"Rerunning server... use `close()` to stop if you need to change `launch()` parameters.\n----"
|
||||
)
|
||||
if not (quiet):
|
||||
print(
|
||||
"Rerunning server... use `close()` to stop if you need to change `launch()` parameters.\n----"
|
||||
)
|
||||
else:
|
||||
server_port, path_to_local_server, app, server = networking.start_server(
|
||||
self,
|
||||
@ -517,7 +520,8 @@ class Blocks(BlockContext):
|
||||
share_url = networking.setup_tunnel(self.server_port, None)
|
||||
self.share_url = share_url
|
||||
print(strings.en["SHARE_LINK_DISPLAY"].format(self.share_url))
|
||||
print(strings.en["SHARE_LINK_MESSAGE"])
|
||||
if not (quiet):
|
||||
print(strings.en["SHARE_LINK_MESSAGE"])
|
||||
except RuntimeError:
|
||||
if self.analytics_enabled:
|
||||
utils.error_analytics(self.ip_address, "Not able to set up tunnel")
|
||||
@ -525,7 +529,8 @@ class Blocks(BlockContext):
|
||||
share = False
|
||||
print(strings.en["COULD_NOT_GET_SHARE_LINK"])
|
||||
else:
|
||||
print(strings.en["PUBLIC_SHARE_TRUE"])
|
||||
if not (quiet):
|
||||
print(strings.en["PUBLIC_SHARE_TRUE"])
|
||||
self.share_url = None
|
||||
|
||||
if inbrowser:
|
||||
|
16
gradio/ipython_ext.py
Normal file
16
gradio/ipython_ext.py
Normal file
@ -0,0 +1,16 @@
|
||||
try:
|
||||
from IPython.core.magic import register_cell_magic
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
import gradio
|
||||
|
||||
|
||||
def load_ipython_extension(ipython):
|
||||
demo = gradio.Blocks()
|
||||
|
||||
@register_cell_magic
|
||||
def blocks(line, cell):
|
||||
with demo.clear():
|
||||
exec(cell)
|
||||
demo.launch(quiet=True)
|
@ -40,10 +40,7 @@ class TestBlocks(unittest.TestCase):
|
||||
with gr.Row():
|
||||
xray_scan = gr.components.Image()
|
||||
xray_results = gr.components.JSON()
|
||||
xray_run = gr.Button(
|
||||
"Run",
|
||||
css={"background-color": "red", "--hover-color": "orange"},
|
||||
)
|
||||
xray_run = gr.Button("Run")
|
||||
xray_run.click(
|
||||
xray_model, inputs=[disease, xray_scan], outputs=xray_results
|
||||
)
|
||||
@ -58,7 +55,6 @@ class TestBlocks(unittest.TestCase):
|
||||
)
|
||||
textbox = gr.components.Textbox()
|
||||
demo.load(fake_func, [], [textbox])
|
||||
print(demo.get_config_file())
|
||||
self.assertEqual(XRAY_CONFIG, demo.get_config_file())
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
Loading…
x
Reference in New Issue
Block a user