Spaces:
Runtime error
Runtime error
hobs
commited on
Commit
·
aafc5b3
1
Parent(s):
f15ddc1
works for forty2
Browse files
app.py
CHANGED
@@ -17,8 +17,9 @@ CHAR_MAPPING = {
|
|
17 |
"-": " ",
|
18 |
"_": " ",
|
19 |
}
|
|
|
20 |
|
21 |
-
TOKEN_MAPPING = dict(enumerate(ONES))
|
22 |
|
23 |
|
24 |
def tokenize(text):
|
@@ -37,10 +38,6 @@ def replace_chars(text, char_mapping=CHAR_MAPPING):
|
|
37 |
return ''.join((char_mapping.get(c, c) for c in text))
|
38 |
|
39 |
|
40 |
-
def preprocess(text):
|
41 |
-
return text.replace('-', ' ')
|
42 |
-
|
43 |
-
|
44 |
def tokens2int(tokens, numwords={}):
|
45 |
""" Convert an English str containing number words into an int
|
46 |
|
@@ -106,49 +103,50 @@ def get_types(cls_set: List[Type], component: str):
|
|
106 |
return docset, types
|
107 |
|
108 |
|
109 |
-
|
110 |
|
|
|
111 |
|
112 |
-
with gr.Blocks() as html_block:
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
|
128 |
-
## API
|
129 |
|
130 |
-
You can select which function to run using the `fn_index` argument:
|
131 |
|
132 |
-
```python
|
133 |
-
import requests
|
134 |
|
135 |
-
requests.post(
|
136 |
-
|
137 |
-
).json()
|
138 |
-
```
|
139 |
|
140 |
-
Or using `curl`:
|
141 |
|
142 |
-
```bash
|
143 |
-
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}'
|
144 |
-
```
|
145 |
-
""")
|
146 |
|
147 |
-
interface = gr.Interface(lambda: None, inputs=[textbox_input], outputs=[textbox_output])
|
148 |
|
149 |
-
html_block.input_components = interface.input_components
|
150 |
-
html_block.output_components = interface.output_components
|
151 |
-
html_block.examples = None
|
152 |
-
html_block.predict_durations = []
|
153 |
|
154 |
-
bapp = html_block.launch()
|
|
|
17 |
"-": " ",
|
18 |
"_": " ",
|
19 |
}
|
20 |
+
CHAR_MAPPING.update((str(i), word) for i, word in enumerate([" " + s + " " for s in ONES]))
|
21 |
|
22 |
+
TOKEN_MAPPING = dict(enumerate([" " + s + " " for s in ONES]))
|
23 |
|
24 |
|
25 |
def tokenize(text):
|
|
|
38 |
return ''.join((char_mapping.get(c, c) for c in text))
|
39 |
|
40 |
|
|
|
|
|
|
|
|
|
41 |
def tokens2int(tokens, numwords={}):
|
42 |
""" Convert an English str containing number words into an int
|
43 |
|
|
|
103 |
return docset, types
|
104 |
|
105 |
|
106 |
+
if __name__ == '__main__':
|
107 |
|
108 |
+
routes.get_types = get_types
|
109 |
|
110 |
+
with gr.Blocks() as html_block:
|
111 |
+
gr.Markdown("# Gradio Blocks (3.0) with REST API")
|
112 |
+
textbox_input = gr.Textbox(
|
113 |
+
value="forty-two",
|
114 |
+
label="Input number words:",
|
115 |
+
)
|
116 |
+
button_text2int = gr.Button("text2int")
|
117 |
+
button_text2int_preprocessed = gr.Button("text2int with preprocessing")
|
118 |
+
textbox_output = gr.Textbox(
|
119 |
+
value="42",
|
120 |
+
label="Output integer:"
|
121 |
+
)
|
122 |
+
button_text2int.click(text2int, inputs=[textbox_input], outputs=[textbox_output])
|
123 |
+
button_text2int_preprocessed.click(text2int_preprocessed, inputs=[textbox_input], outputs=[textbox_output])
|
124 |
+
gr.Markdown(r"""
|
125 |
|
126 |
+
## API
|
127 |
|
128 |
+
You can select which function to run using the `fn_index` argument:
|
129 |
|
130 |
+
```python
|
131 |
+
import requests
|
132 |
|
133 |
+
requests.post(
|
134 |
+
url="https://Hobson-gradio-rest-api.hf.space/api/predict/", json={"data": ["one hundred forty-two"], "fn_index": 0}
|
135 |
+
).json()
|
136 |
+
```
|
137 |
|
138 |
+
Or using `curl`:
|
139 |
|
140 |
+
```bash
|
141 |
+
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}'
|
142 |
+
```
|
143 |
+
""")
|
144 |
|
145 |
+
interface = gr.Interface(lambda: None, inputs=[textbox_input], outputs=[textbox_output])
|
146 |
|
147 |
+
html_block.input_components = interface.input_components
|
148 |
+
html_block.output_components = interface.output_components
|
149 |
+
html_block.examples = None
|
150 |
+
html_block.predict_durations = []
|
151 |
|
152 |
+
bapp = html_block.launch()
|