mirror of
https://github.com/gradio-app/gradio.git
synced 2024-12-21 02:19:59 +08:00
Gradio-Dashboard
- solve circular import - build frontend - format backend
This commit is contained in:
parent
3040d2b6f6
commit
5fe5fa0e33
@ -1,35 +1,38 @@
|
||||
import gradio as gr
|
||||
|
||||
import random
|
||||
xray_model = lambda diseases, img : {disease: random.random() for disease in diseases}
|
||||
ct_model = lambda diseases, img : {disease: random.random() for disease in diseases}
|
||||
|
||||
xray_model = lambda diseases, img: {disease: random.random() for disease in diseases}
|
||||
ct_model = lambda diseases, img: {disease: random.random() for disease in diseases}
|
||||
|
||||
xray_blocks = gr.Blocks()
|
||||
|
||||
with xray_blocks:
|
||||
gr.Markdown("""
|
||||
gr.Markdown("""
|
||||
# Detect Disease From Scan
|
||||
With this model you can lorem ipsum
|
||||
- ipsum 1
|
||||
- ipsum 2
|
||||
""")
|
||||
disease = gr.inputs.CheckboxGroup(["Covid", "Malaria", "Lung Cancer"],
|
||||
label="Disease to Scan For")
|
||||
disease = gr.inputs.CheckboxGroup(["Covid", "Malaria", "Lung Cancer"],
|
||||
label="Disease to Scan For")
|
||||
|
||||
with gr.Tab("X-ray"):
|
||||
with gr.Row():
|
||||
xray_scan = gr.inputs.Image()
|
||||
xray_results = gr.outputs.JSON()
|
||||
xray_run = gr.Button("Run")
|
||||
xray_run.click(xray_model, inputs=[disease, xray_scan] , outputs=xray_results)
|
||||
with gr.Tab("X-ray"):
|
||||
with gr.Row():
|
||||
xray_scan = gr.inputs.Image()
|
||||
xray_results = gr.outputs.JSON()
|
||||
xray_run = gr.Button("Run")
|
||||
xray_run.click(xray_model, inputs=[disease, xray_scan], outputs=xray_results)
|
||||
|
||||
with gr.Tab("CT Scan"):
|
||||
with gr.Row():
|
||||
ct_scan = gr.inputs.Image()
|
||||
ct_results = gr.outputs.JSON()
|
||||
ct_run = gr.Button("Run")
|
||||
ct_run.click(ct_model, inputs=[disease, ct_scan], outputs=ct_results)
|
||||
|
||||
overall_probability = gr.outputs.Textbox()
|
||||
with gr.Tab("CT Scan"):
|
||||
with gr.Row():
|
||||
ct_scan = gr.inputs.Image()
|
||||
ct_results = gr.outputs.JSON()
|
||||
ct_run = gr.Button("Run")
|
||||
ct_run.click(ct_model, inputs=[disease, ct_scan], outputs=ct_results)
|
||||
|
||||
xray_blocks.launch()
|
||||
overall_probability = gr.outputs.Textbox()
|
||||
|
||||
#TODO: remove later
|
||||
print(xray_blocks.get_config_file())
|
||||
xray_blocks.launch()
|
||||
|
@ -1,16 +1,16 @@
|
||||
import pkg_resources
|
||||
|
||||
from gradio.blocks import Blocks, Column, Row, Tab
|
||||
from gradio.flagging import (
|
||||
CSVLogger,
|
||||
FlaggingCallback,
|
||||
HuggingFaceDatasetSaver,
|
||||
SimpleCSVLogger,
|
||||
)
|
||||
from gradio.blocks import Blocks, Tab, Row, Column
|
||||
from gradio.interface import Interface, close_all, reset_all
|
||||
from gradio.mix import Parallel, Series
|
||||
from gradio.routes import get_state, set_state
|
||||
from gradio.static import Markdown, Button
|
||||
from gradio.static import Button, Markdown
|
||||
|
||||
current_pkg_version = pkg_resources.require("gradio")[0].version
|
||||
__version__ = current_pkg_version
|
||||
|
@ -1,6 +1,7 @@
|
||||
from gradio.launchable import Launchable
|
||||
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Tuple
|
||||
|
||||
from gradio import context, utils
|
||||
from typing import TYPE_CHECKING, Any, Callable, List, Optional, Tuple, Dict
|
||||
from gradio.launchable import Launchable
|
||||
|
||||
|
||||
class Block:
|
||||
@ -75,8 +76,8 @@ class Blocks(Launchable, BlockContext):
|
||||
self.blocks = {}
|
||||
self.fns = []
|
||||
self.dependencies = []
|
||||
|
||||
def process_api(self, data: Dict[str, Any], username: str=None) -> Dict[str, Any]:
|
||||
|
||||
def process_api(self, data: Dict[str, Any], username: str = None) -> Dict[str, Any]:
|
||||
raw_input = data["data"]
|
||||
fn_index = data["fn_index"]
|
||||
fn = self.fns[fn_index]
|
||||
@ -88,7 +89,7 @@ class Blocks(Launchable, BlockContext):
|
||||
]
|
||||
predictions = fn(*processed_input)
|
||||
if len(dependency["outputs"]) == 1:
|
||||
predictions = (predictions, )
|
||||
predictions = (predictions,)
|
||||
processed_output = [
|
||||
self.blocks[output_id].postprocess(predictions[i])
|
||||
if predictions[i] is not None
|
||||
@ -96,14 +97,16 @@ class Blocks(Launchable, BlockContext):
|
||||
for i, output_id in enumerate(dependency["outputs"])
|
||||
]
|
||||
return {"data": processed_output}
|
||||
|
||||
|
||||
def get_template_context(self):
|
||||
return {"type": "column"}
|
||||
|
||||
def get_config_file(self):
|
||||
from gradio.component import Component
|
||||
|
||||
config = {"mode": "blocks", "components": [], "theme": self.theme}
|
||||
for _id, block in self.blocks.items():
|
||||
if not isinstance(block, BlockContext):
|
||||
if isinstance(block, Component):
|
||||
config["components"].append(
|
||||
{
|
||||
"id": _id,
|
||||
@ -111,6 +114,7 @@ class Blocks(Launchable, BlockContext):
|
||||
"props": block.get_template_context(),
|
||||
}
|
||||
)
|
||||
|
||||
def getLayout(block_context):
|
||||
if not isinstance(block_context, BlockContext):
|
||||
return block_context._id
|
||||
@ -128,10 +132,8 @@ class Blocks(Launchable, BlockContext):
|
||||
if len(running_tabs):
|
||||
children.append({"type": "tabset", "children": running_tabs})
|
||||
running_tabs = []
|
||||
return {
|
||||
"children": children,
|
||||
**block_context.get_template_context()
|
||||
}
|
||||
return {"children": children, **block_context.get_template_context()}
|
||||
|
||||
config["layout"] = getLayout(self)
|
||||
config["dependencies"] = self.dependencies
|
||||
return config
|
||||
|
@ -5,6 +5,7 @@ from typing import Any, Dict
|
||||
from gradio import processing_utils
|
||||
from gradio.blocks import Block
|
||||
|
||||
|
||||
class Component(Block):
|
||||
"""
|
||||
A class for defining the methods that all gradio input and output components should have.
|
||||
|
@ -1,3 +1,3 @@
|
||||
root_block = None
|
||||
block = None
|
||||
id = 0
|
||||
id = 0
|
||||
|
@ -12,23 +12,23 @@ import re
|
||||
import time
|
||||
import warnings
|
||||
import weakref
|
||||
from typing import TYPE_CHECKING, Any, Callable, List, Optional, Tuple, Dict
|
||||
from gradio.routes import predict
|
||||
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Tuple
|
||||
|
||||
from markdown_it import MarkdownIt
|
||||
from mdit_py_plugins.footnote import footnote_plugin
|
||||
|
||||
from gradio import interpretation, utils
|
||||
from gradio.launchable import Launchable
|
||||
from gradio.external import load_from_pipeline, load_interface # type: ignore
|
||||
from gradio.flagging import CSVLogger, FlaggingCallback # type: ignore
|
||||
from gradio.inputs import InputComponent
|
||||
from gradio.inputs import State as i_State # type: ignore
|
||||
from gradio.inputs import get_input_instance
|
||||
from gradio.launchable import Launchable
|
||||
from gradio.outputs import OutputComponent
|
||||
from gradio.outputs import State as o_State # type: ignore
|
||||
from gradio.outputs import get_output_instance
|
||||
from gradio.process_examples import load_from_cache, process_example
|
||||
from gradio.routes import predict
|
||||
|
||||
if TYPE_CHECKING: # Only import for type checking (is False at runtime).
|
||||
import flask
|
||||
@ -538,7 +538,7 @@ class Interface(Launchable):
|
||||
else:
|
||||
return predictions
|
||||
|
||||
def process_api(self, data: Dict[str, Any], username: str=None) -> Dict[str, Any]:
|
||||
def process_api(self, data: Dict[str, Any], username: str = None) -> Dict[str, Any]:
|
||||
flag_index = None
|
||||
if data.get("example_id") is not None:
|
||||
example_id = data["example_id"]
|
||||
|
@ -7,18 +7,18 @@ import time
|
||||
import webbrowser
|
||||
from typing import TYPE_CHECKING, Any, Callable, List, Optional, Tuple
|
||||
|
||||
|
||||
from gradio import networking, queueing # type: ignore
|
||||
from gradio import encryptor, strings, utils
|
||||
from gradio import encryptor, networking, queueing, strings, utils # type: ignore
|
||||
from gradio.process_examples import cache_interface_examples
|
||||
|
||||
if TYPE_CHECKING: # Only import for type checking (is False at runtime).
|
||||
import flask
|
||||
|
||||
|
||||
class Launchable:
|
||||
"""
|
||||
Gradio launchables can be launched to serve content to a port.
|
||||
"""
|
||||
|
||||
def launch(
|
||||
self,
|
||||
inline: bool = None,
|
||||
@ -231,4 +231,3 @@ class Launchable:
|
||||
self.server.close()
|
||||
if self.enable_queue:
|
||||
queueing.close()
|
||||
|
||||
|
@ -195,9 +195,7 @@ def api_docs(request: Request):
|
||||
async def predict(request: Request, username: str = Depends(get_current_user)):
|
||||
body = await request.json()
|
||||
try:
|
||||
output = await run_in_threadpool(
|
||||
app.launchable.process_api, body, username
|
||||
)
|
||||
output = await run_in_threadpool(app.launchable.process_api, body, username)
|
||||
except BaseException as error:
|
||||
if app.launchable.show_error:
|
||||
traceback.print_exc()
|
||||
|
@ -2,6 +2,7 @@ from __future__ import annotations
|
||||
|
||||
from gradio.component import Component
|
||||
|
||||
|
||||
class StaticComponent(Component):
|
||||
def __init__(self, label: str):
|
||||
self.component_type = "static"
|
||||
@ -17,5 +18,6 @@ class StaticComponent(Component):
|
||||
class Markdown(StaticComponent):
|
||||
pass
|
||||
|
||||
|
||||
class Button(StaticComponent):
|
||||
pass
|
||||
pass
|
||||
|
@ -45,10 +45,10 @@
|
||||
</script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/iframe-resizer/4.3.1/iframeResizer.contentWindow.min.js"></script>
|
||||
<title>Gradio</title>
|
||||
<script type="module" crossorigin src="/assets/index.37f950c6.js"></script>
|
||||
<link rel="modulepreload" href="/assets/vendor.5cd8ecbe.js">
|
||||
<script type="module" crossorigin src="/assets/index.75e4bf7f.js"></script>
|
||||
<link rel="modulepreload" href="/assets/vendor.3cba5ef5.js">
|
||||
<link rel="stylesheet" href="/assets/vendor.327fceeb.css">
|
||||
<link rel="stylesheet" href="/assets/index.60a6bb20.css">
|
||||
<link rel="stylesheet" href="/assets/index.859c7146.css">
|
||||
</head>
|
||||
|
||||
<body style="height: 100%; margin: 0; padding: 0">
|
||||
|
@ -5,14 +5,14 @@
|
||||
"interpret": "Interpretar",
|
||||
"flag": "Avisar",
|
||||
"examples": "Ejemplos",
|
||||
"drop_image": "Coloque la Imagen Aquí",
|
||||
"drop_video": "Coloque la Video Aquí",
|
||||
"drop_audio": "Coloque la Audio Aquí",
|
||||
"drop_file": "Coloque la Archivo Aquí",
|
||||
"drop_csv": "Coloque el CSV Aquí",
|
||||
"drop_image": "Coloque la imagen aquí",
|
||||
"drop_video": "Coloque el video aquí",
|
||||
"drop_audio": "Coloque el audio aquí",
|
||||
"drop_file": "Coloque el archivo aquí",
|
||||
"drop_csv": "Coloque el CSV aquí",
|
||||
"or": "o",
|
||||
"click_to_upload": "Haga Clic para Cargar",
|
||||
"view_api": "Para ver la API",
|
||||
"click_to_upload": "Haga click para cargar",
|
||||
"view_api": "Ver la API",
|
||||
"built_with_Gradio": "Construido con Gradio"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user