Spaces:
Runtime error
Runtime error
hobs
commited on
Commit
·
bf32265
1
Parent(s):
ea86819
no __main__
Browse files
app.py
CHANGED
@@ -103,50 +103,48 @@ def get_types(cls_set: List[Type], component: str):
|
|
103 |
return docset, types
|
104 |
|
105 |
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
bapp = html_block.launch(share=True)
|
|
|
103 |
return docset, types
|
104 |
|
105 |
|
106 |
+
routes.get_types = get_types
|
107 |
+
|
108 |
+
with gr.Blocks() as html_block:
|
109 |
+
gr.Markdown("# Gradio Blocks (3.0) with REST API")
|
110 |
+
textbox_input = gr.Textbox(
|
111 |
+
value="forty-two",
|
112 |
+
label="Input number words:",
|
113 |
+
)
|
114 |
+
button_text2int = gr.Button("text2int")
|
115 |
+
button_text2int_preprocessed = gr.Button("text2int with preprocessing")
|
116 |
+
textbox_output = gr.Textbox(
|
117 |
+
value="42",
|
118 |
+
label="Output integer:"
|
119 |
+
)
|
120 |
+
button_text2int.click(text2int, inputs=[textbox_input], outputs=[textbox_output])
|
121 |
+
button_text2int_preprocessed.click(text2int_preprocessed, inputs=[textbox_input], outputs=[textbox_output])
|
122 |
+
gr.Markdown(r"""
|
123 |
+
|
124 |
+
## API
|
125 |
+
|
126 |
+
You can select which function to run using the `fn_index` argument:
|
127 |
+
|
128 |
+
```python
|
129 |
+
import requests
|
130 |
+
|
131 |
+
requests.post(
|
132 |
+
url="https://Hobson-gradio-rest-api.hf.space/api/predict/", json={"data": ["one hundred forty-two"], "fn_index": 0}
|
133 |
+
).json()
|
134 |
+
```
|
135 |
+
|
136 |
+
Or using `curl`:
|
137 |
+
|
138 |
+
```bash
|
139 |
+
curl -X POST https://Hobson-gradio-rest-api.hf.space/api/predict/ -H 'Content-Type: application/json' -d '{"data": ["one hundred forty-two"], "fn_index": 0}'
|
140 |
+
```
|
141 |
+
""")
|
142 |
+
|
143 |
+
interface = gr.Interface(lambda: None, inputs=[textbox_input], outputs=[textbox_output])
|
144 |
+
|
145 |
+
html_block.input_components = interface.input_components
|
146 |
+
html_block.output_components = interface.output_components
|
147 |
+
html_block.examples = None
|
148 |
+
html_block.predict_durations = []
|
149 |
+
|
150 |
+
bapp = html_block.launch(share=True)
|
|
|
|