Skip to content

Commit

Permalink
gradio support
Browse files Browse the repository at this point in the history
  • Loading branch information
edavidaja committed Dec 6, 2024
1 parent 3f22dbb commit 0b43655
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 5 deletions.
3 changes: 3 additions & 0 deletions extensions/vscode/src/api/types/configurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export enum ContentType {
PYTHON_FLASK = "python-flask",
PYTHON_SHINY = "python-shiny",
PYTHON_STREAMLIT = "python-streamlit",
PYTHON_GRADIO = "python-gradio",
QUARTO_SHINY = "quarto-shiny",
QUARTO = "quarto",
QUARTO_STATIC = "quarto-static",
Expand All @@ -73,6 +74,7 @@ export const allValidContentTypes: ContentType[] = [
ContentType.PYTHON_FLASK,
ContentType.PYTHON_SHINY,
ContentType.PYTHON_STREAMLIT,
ContentType.PYTHON_GRADIO,
ContentType.QUARTO_SHINY,
ContentType.QUARTO,
ContentType.QUARTO_STATIC,
Expand All @@ -92,6 +94,7 @@ export const contentTypeStrings = {
[ContentType.PYTHON_FLASK]: "run with Flask",
[ContentType.PYTHON_SHINY]: "run with Python Shiny",
[ContentType.PYTHON_STREAMLIT]: "run with Streamlit",
[ContentType.PYTHON_GRADIO]: "run with Gradio",
[ContentType.QUARTO_SHINY]: "render with Quarto and run embedded Shiny app",
[ContentType.QUARTO]: "render with Quarto",
[ContentType.QUARTO_STATIC]: "render with Quarto",
Expand Down
18 changes: 15 additions & 3 deletions internal/clients/connect/apptypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const (
PythonStreamlitMode AppMode = "python-streamlit"
PythonBokehMode AppMode = "python-bokeh"
PythonFastAPIMode AppMode = "python-fastapi"
PythonGradioMode AppMode = "python-gradio"
ShinyQuartoMode AppMode = "quarto-shiny"
StaticQuartoMode AppMode = "quarto-static"
PythonShinyMode AppMode = "python-shiny"
Expand Down Expand Up @@ -61,6 +62,8 @@ func AppModeFromString(s string) (AppMode, error) {
return PythonBokehMode, nil
case "python-fastapi", "fastapi", "asgi":
return PythonFastAPIMode, nil
case "python-gradio", "gradio":
return PythonGradioMode, nil
case "python-shiny", "pyshiny":
return PythonShinyMode, nil
case "quarto-shiny":
Expand Down Expand Up @@ -88,7 +91,7 @@ func (mode *AppMode) UnmarshalText(text []byte) error {
// IsWorkerApp returns true for any content that is serviced by worker
// processes. This includes Shiny applications, interactive R Markdown
// documents, Plumber/Python (flask/fastapi) APIs, and Python apps
// (Dash, Streamlit, Bokeh, PyShiny, Voila).
// (Dash, Streamlit, Bokeh, PyShiny, Voila, Gradio).
func (mode AppMode) IsWorkerApp() bool {
return (mode.IsShinyApp() ||
mode.IsPythonApp() ||
Expand All @@ -113,7 +116,7 @@ func (mode AppMode) IsPythonAPI() bool {
// IsPythonApp returns true for Python applications (Dash, Streamlit, Bokeh, Voila)
func (mode AppMode) IsPythonApp() bool {
switch mode {
case PythonDashMode, PythonStreamlitMode, PythonShinyMode, PythonBokehMode, JupyterVoilaMode:
case PythonDashMode, PythonStreamlitMode, PythonGradioMode, PythonShinyMode, PythonBokehMode, JupyterVoilaMode:
return true
}
return false
Expand All @@ -140,6 +143,11 @@ func (t AppMode) IsBokehApp() bool {
return t == PythonBokehMode
}

// IsGradioApp returns true for Python Gradio applications
func (t AppMode) IsGradioApp() bool {
return t == PythonGradioMode
}

// IsFastAPIApp returns true for Python FastAPI applications
func (t AppMode) IsFastAPIApp() bool {
return t == PythonFastAPIMode
Expand Down Expand Up @@ -190,7 +198,7 @@ func (t AppMode) IsRContent() bool {
// content type.
func (t AppMode) IsPythonContent() bool {
switch t {
case StaticJupyterMode, PythonAPIMode, PythonDashMode, PythonStreamlitMode, PythonBokehMode, PythonFastAPIMode, PythonShinyMode, JupyterVoilaMode:
case StaticJupyterMode, PythonAPIMode, PythonDashMode, PythonStreamlitMode, PythonBokehMode, PythonFastAPIMode, PythonGradioMode, PythonShinyMode, JupyterVoilaMode:
return true
}
return false
Expand Down Expand Up @@ -232,6 +240,8 @@ func (t AppMode) Description() string {
return "Bokeh application"
case PythonFastAPIMode:
return "FastAPI application"
case PythonGradioMode:
return "Gradio application"
case PythonShinyMode:
return "Python Shiny application"
case ShinyQuartoMode:
Expand All @@ -255,6 +265,7 @@ var connectContentTypeMap = map[config.ContentType]AppMode{
config.ContentTypePythonFlask: PythonAPIMode,
config.ContentTypePythonShiny: PythonShinyMode,
config.ContentTypePythonStreamlit: PythonStreamlitMode,
config.ContentTypePythonGradio: PythonGradioMode,
config.ContentTypeQuartoShiny: ShinyQuartoMode,
config.ContentTypeQuartoDeprecated: StaticQuartoMode,
config.ContentTypeQuarto: StaticQuartoMode,
Expand All @@ -280,6 +291,7 @@ var contentTypeConnectMap = map[AppMode]config.ContentType{
PythonDashMode: config.ContentTypePythonDash,
PythonFastAPIMode: config.ContentTypePythonFastAPI,
PythonAPIMode: config.ContentTypePythonFlask,
PythonGradioMode: config.ContentTypePythonGradio,
PythonShinyMode: config.ContentTypePythonShiny,
PythonStreamlitMode: config.ContentTypePythonStreamlit,
ShinyQuartoMode: config.ContentTypeQuartoShiny,
Expand Down
42 changes: 42 additions & 0 deletions internal/clients/connect/apptypes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func (s *AppTypesSuite) TestAppMode() {
StreamlitApp bool
BokehApp bool
FastAPIApp bool
GradioApp bool
PyShinyApp bool
VoilaApp bool
StaticRmd bool
Expand All @@ -58,6 +59,7 @@ func (s *AppTypesSuite) TestAppMode() {
StreamlitApp: false,
BokehApp: false,
FastAPIApp: false,
GradioApp: false,
PyShinyApp: false,
VoilaApp: false,
StaticRmd: false,
Expand All @@ -79,6 +81,7 @@ func (s *AppTypesSuite) TestAppMode() {
StreamlitApp: false,
BokehApp: false,
FastAPIApp: false,
GradioApp: false,
PyShinyApp: false,
VoilaApp: false,
StaticRmd: false,
Expand All @@ -100,6 +103,7 @@ func (s *AppTypesSuite) TestAppMode() {
StreamlitApp: false,
BokehApp: false,
FastAPIApp: false,
GradioApp: false,
PyShinyApp: false,
VoilaApp: false,
StaticRmd: false,
Expand All @@ -121,6 +125,7 @@ func (s *AppTypesSuite) TestAppMode() {
StreamlitApp: false,
BokehApp: false,
FastAPIApp: false,
GradioApp: false,
PyShinyApp: false,
VoilaApp: false,
StaticRmd: true,
Expand All @@ -142,6 +147,7 @@ func (s *AppTypesSuite) TestAppMode() {
StreamlitApp: false,
BokehApp: false,
FastAPIApp: false,
GradioApp: false,
PyShinyApp: false,
VoilaApp: false,
StaticRmd: false,
Expand All @@ -163,6 +169,7 @@ func (s *AppTypesSuite) TestAppMode() {
StreamlitApp: false,
BokehApp: false,
FastAPIApp: false,
GradioApp: false,
PyShinyApp: false,
VoilaApp: false,
StaticRmd: false,
Expand All @@ -184,6 +191,7 @@ func (s *AppTypesSuite) TestAppMode() {
StreamlitApp: false,
BokehApp: false,
FastAPIApp: false,
GradioApp: false,
PyShinyApp: false,
VoilaApp: false,
StaticRmd: false,
Expand All @@ -205,6 +213,7 @@ func (s *AppTypesSuite) TestAppMode() {
StreamlitApp: false,
BokehApp: false,
FastAPIApp: false,
GradioApp: false,
PyShinyApp: false,
VoilaApp: false,
StaticRmd: false,
Expand All @@ -226,6 +235,7 @@ func (s *AppTypesSuite) TestAppMode() {
StreamlitApp: false,
BokehApp: false,
FastAPIApp: false,
GradioApp: false,
PyShinyApp: false,
VoilaApp: false,
StaticRmd: false,
Expand All @@ -247,6 +257,7 @@ func (s *AppTypesSuite) TestAppMode() {
StreamlitApp: true,
BokehApp: false,
FastAPIApp: false,
GradioApp: false,
PyShinyApp: false,
VoilaApp: false,
StaticRmd: false,
Expand All @@ -268,6 +279,7 @@ func (s *AppTypesSuite) TestAppMode() {
StreamlitApp: false,
BokehApp: true,
FastAPIApp: false,
GradioApp: false,
PyShinyApp: false,
VoilaApp: false,
StaticRmd: false,
Expand All @@ -289,6 +301,29 @@ func (s *AppTypesSuite) TestAppMode() {
StreamlitApp: false,
BokehApp: false,
FastAPIApp: true,
GradioApp: false,
PyShinyApp: false,
VoilaApp: false,
StaticRmd: false,
StaticJupyter: false,
StaticReport: false,
StaticContent: false,
}, {
Mode: PythonGradioMode,
RContent: false,
PythonContent: true,
QuartoContent: false,
WorkerApp: true,
APIApp: false,
PlumberAPI: false,
PythonAPI: false,
PythonApp: true,
ShinyApp: false,
DashApp: false,
StreamlitApp: false,
BokehApp: false,
FastAPIApp: false,
GradioApp: true,
PyShinyApp: false,
VoilaApp: false,
StaticRmd: false,
Expand All @@ -310,6 +345,7 @@ func (s *AppTypesSuite) TestAppMode() {
StreamlitApp: false,
BokehApp: false,
FastAPIApp: false,
GradioApp: false,
PyShinyApp: false,
VoilaApp: false,
StaticRmd: false,
Expand All @@ -331,6 +367,7 @@ func (s *AppTypesSuite) TestAppMode() {
StreamlitApp: false,
BokehApp: false,
FastAPIApp: false,
GradioApp: false,
PyShinyApp: false,
VoilaApp: false,
StaticRmd: false,
Expand All @@ -352,6 +389,7 @@ func (s *AppTypesSuite) TestAppMode() {
StreamlitApp: false,
BokehApp: false,
FastAPIApp: false,
GradioApp: false,
PyShinyApp: true,
VoilaApp: false,
StaticRmd: false,
Expand All @@ -373,6 +411,7 @@ func (s *AppTypesSuite) TestAppMode() {
StreamlitApp: false,
BokehApp: false,
FastAPIApp: false,
GradioApp: false,
PyShinyApp: false,
VoilaApp: true,
StaticRmd: false,
Expand All @@ -396,6 +435,7 @@ func (s *AppTypesSuite) TestAppMode() {
s.Equal(each.StreamlitApp, each.Mode.IsStreamlitApp(), comment)
s.Equal(each.BokehApp, each.Mode.IsBokehApp(), comment)
s.Equal(each.FastAPIApp, each.Mode.IsFastAPIApp(), comment)
s.Equal(each.GradioApp, each.Mode.IsGradioApp(), comment)
s.Equal(each.PyShinyApp, each.Mode.IsPyShinyApp(), comment)
s.Equal(each.VoilaApp, each.Mode.IsVoilaApp(), comment)
s.Equal(each.StaticRmd, each.Mode.IsStaticRmd(), comment)
Expand All @@ -422,6 +462,7 @@ func (s *AppTypesSuite) TestAppModeStrings() {
{PythonStreamlitMode, "python-streamlit"},
{PythonBokehMode, "python-bokeh"},
{PythonFastAPIMode, "python-fastapi"},
{PythonGradioMode, "python-gradio"},
{ShinyQuartoMode, "quarto-shiny"},
{StaticQuartoMode, "quarto-static"},
{PythonShinyMode, "python-shiny"},
Expand Down Expand Up @@ -476,6 +517,7 @@ func (s *AppTypesSuite) TestDescription() {
{PythonStreamlitMode, "Streamlit application"},
{PythonBokehMode, "Bokeh application"},
{PythonFastAPIMode, "FastAPI application"},
{PythonGradioMode, "Gradio application"},
{ShinyQuartoMode, "Shiny Quarto document"},
{StaticQuartoMode, "Quarto document"},
{PythonShinyMode, "Python Shiny application"},
Expand Down
4 changes: 4 additions & 0 deletions internal/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const (
ContentTypePythonFlask ContentType = "python-flask"
ContentTypePythonShiny ContentType = "python-shiny"
ContentTypePythonStreamlit ContentType = "python-streamlit"
ContentTypePythonGradio ContentType = "python-gradio"
ContentTypeQuartoShiny ContentType = "quarto-shiny"
ContentTypeQuartoDeprecated ContentType = "quarto"
ContentTypeQuarto ContentType = "quarto-static"
Expand All @@ -33,6 +34,7 @@ func AllValidContentTypeNames() []string {
string(ContentTypePythonDash),
string(ContentTypePythonFastAPI),
string(ContentTypePythonFlask),
string(ContentTypePythonGradio),
string(ContentTypePythonShiny),
string(ContentTypePythonStreamlit),
string(ContentTypeQuartoShiny),
Expand All @@ -55,6 +57,7 @@ func (t ContentType) IsPythonContent() bool {
ContentTypePythonDash,
ContentTypePythonFastAPI,
ContentTypePythonFlask,
ContentTypePythonGradio,
ContentTypePythonShiny,
ContentTypePythonStreamlit:
return true
Expand All @@ -78,6 +81,7 @@ func (t ContentType) IsAppContent() bool {
ContentTypeRShiny,
ContentTypePythonBokeh,
ContentTypePythonDash,
ContentTypePythonGradio,
ContentTypePythonStreamlit:
return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
},
"type": {
"type": "string",
"description": "Indicates the type of content. Valid values are: html, jupyter-notebook, jupyter-voila, python-bokeh, python-dash, python-fastapi, python-flask, python-shiny, python-streamlit, quarto-shiny, quarto-static, r-plumber, r-shiny, rmd-shiny, rmd",
"description": "Indicates the type of content. Valid values are: html, jupyter-notebook, jupyter-voila, python-bokeh, python-dash, python-fastapi, python-flask, python-gradio, python-shiny, python-streamlit, quarto-shiny, quarto-static, r-plumber, r-shiny, rmd-shiny, rmd",
"enum": [
"",
"html",
Expand All @@ -50,6 +50,7 @@
"python-dash",
"python-fastapi",
"python-flask",
"python-gradio",
"python-shiny",
"python-streamlit",
"quarto-shiny",
Expand Down
3 changes: 2 additions & 1 deletion internal/schema/schemas/posit-publishing-schema-v3.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"type": {
"type": "string",
"description": "Indicates the type of content being deployed. Valid values are: html, jupyter-notebook, jupyter-voila, python-bokeh, python-dash, python-fastapi, python-flask, python-shiny, python-streamlit, quarto-shiny, quarto-static, r-plumber, r-shiny, rmd-shiny, rmd",
"description": "Indicates the type of content being deployed. Valid values are: html, jupyter-notebook, jupyter-voila, python-bokeh, python-dash, python-fastapi, python-flask, python-gradio, python-shiny, python-streamlit, quarto-shiny, quarto-static, r-plumber, r-shiny, rmd-shiny, rmd",
"enum": [
"html",
"jupyter-notebook",
Expand All @@ -35,6 +35,7 @@
"python-dash",
"python-fastapi",
"python-flask",
"python-gradio",
"python-shiny",
"python-streamlit",
"quarto-shiny",
Expand Down

0 comments on commit 0b43655

Please sign in to comment.