Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Gradio inspection and type to documentation #2541

Merged
merged 5 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that python-gradio wasn't listed here to enforce that the python section was required if the type = '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
Loading