Skip to content

Commit

Permalink
Merge pull request #2541 from posit-dev/dotnomad/gradio
Browse files Browse the repository at this point in the history
Add Gradio inspection and type to documentation
  • Loading branch information
dotNomad authored Jan 22, 2025
2 parents 3f043f3 + 2940ba9 commit 5dc3269
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 1 deletion.
3 changes: 2 additions & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ Indicates the type of content being deployed. Valid values are:
- `python-bokeh`
- `python-dash`
- `python-fastapi`
- `pyhon-flask`
- `python-flask`
- `python-gradio`
- `python-shiny`
- `python-streamlit`
- `quarto-shiny`
Expand Down
1 change: 1 addition & 0 deletions internal/inspect/detectors/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func NewContentTypeDetector(log logging.Logger) *ContentTypeDetector {
NewFastAPIDetector(),
NewFlaskDetector(),
NewDashDetector(),
NewGradioDetector(),
NewStreamlitDetector(),
NewBokehDetector(),
NewStaticHTMLDetector(),
Expand Down
6 changes: 6 additions & 0 deletions internal/inspect/detectors/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ func NewDashDetector() *PythonAppDetector {
})
}

func NewGradioDetector() *PythonAppDetector {
return NewPythonAppDetector(config.ContentTypePythonGradio, []string{
"gradio",
})
}

func NewStreamlitDetector() *PythonAppDetector {
return NewPythonAppDetector(config.ContentTypePythonStreamlit, []string{
"streamlit",
Expand Down
24 changes: 24 additions & 0 deletions internal/inspect/detectors/python_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,27 @@ func (s *PythonSuite) TestInferTypeWithEntrypoint() {
Python: &config.Python{},
}, configs[0])
}

func (s *PythonSuite) TestInferTypeGradio() {
base := util.NewAbsolutePath("/project", afero.NewMemMapFs())
err := base.MkdirAll(0777)
s.NoError(err)

filename := "app.py"
err = base.Join(filename).WriteFile([]byte("import gradio\n"), 0600)
s.Nil(err)

detector := NewGradioDetector()
configs, err := detector.InferType(base, util.RelativePath{})
s.Nil(err)
s.Len(configs, 1)

s.Equal(&config.Config{
Schema: schema.ConfigSchemaURL,
Type: config.ContentTypePythonGradio,
Entrypoint: filename,
Validate: true,
Files: []string{},
Python: &config.Python{},
}, configs[0])
}
1 change: 1 addition & 0 deletions internal/schema/schemas/posit-publishing-schema-v3.json
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@
"python-dash",
"python-fastapi",
"python-flask",
"python-gradio",
"python-shiny",
"python-streamlit"
]
Expand Down
1 change: 1 addition & 0 deletions test/sample-content/gradio/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.venv
12 changes: 12 additions & 0 deletions test/sample-content/gradio/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import gradio as gr

def greet(name, intensity):
return "Hello, " + name + "!" * int(intensity)

demo = gr.Interface(
fn=greet,
inputs=["text", "slider"],
outputs=["text"],
)

demo.launch()
1 change: 1 addition & 0 deletions test/sample-content/gradio/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gradio==5.12.0

0 comments on commit 5dc3269

Please sign in to comment.