Spaces:
Runtime error
Runtime error
hobs
commited on
Commit
·
8c4b92d
1
Parent(s):
76db123
pin gradio ver
Browse files- app.py +31 -5
- requirements.txt +1 -0
app.py
CHANGED
@@ -1,11 +1,15 @@
|
|
1 |
import inspect
|
2 |
import json
|
|
|
3 |
import os
|
4 |
import gradio as gr
|
5 |
from gradio import routes
|
6 |
-
import spacy
|
7 |
from typing import List, Type
|
8 |
|
|
|
|
|
|
|
9 |
|
10 |
ONES = [
|
11 |
"zero", "one", "two", "three", "four", "five", "six", "seven", "eight",
|
@@ -84,8 +88,30 @@ def text2int(text):
|
|
84 |
return tokens2int(tokenize(replace_chars(text)))
|
85 |
|
86 |
|
87 |
-
def
|
88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
|
90 |
|
91 |
def get_types(cls_set: List[Type], component: str):
|
@@ -120,8 +146,8 @@ with gr.Blocks() as html_block:
|
|
120 |
value="42",
|
121 |
label="Output integer:"
|
122 |
)
|
123 |
-
button_text2int.click(
|
124 |
-
button_text2int_preprocessed.click(
|
125 |
gr.Markdown(r"""
|
126 |
|
127 |
## API
|
|
|
1 |
import inspect
|
2 |
import json
|
3 |
+
import logging
|
4 |
import os
|
5 |
import gradio as gr
|
6 |
from gradio import routes
|
7 |
+
import spacy # noqa
|
8 |
from typing import List, Type
|
9 |
|
10 |
+
TOKENS2INT_ERROR_INT = 32202
|
11 |
+
|
12 |
+
log = logging.getLogger()
|
13 |
|
14 |
ONES = [
|
15 |
"zero", "one", "two", "three", "four", "five", "six", "seven", "eight",
|
|
|
88 |
return tokens2int(tokenize(replace_chars(text)))
|
89 |
|
90 |
|
91 |
+
def try_text2int(text):
|
92 |
+
text = str(text)
|
93 |
+
try:
|
94 |
+
intstr = tokens2int(tokens2int(tokenize(replace_chars(text))))
|
95 |
+
except Exception as e:
|
96 |
+
log.error(str(e))
|
97 |
+
log.error(f'User input: {text}')
|
98 |
+
intstr = TOKENS2INT_ERROR_INT
|
99 |
+
return str(intstr)
|
100 |
+
|
101 |
+
|
102 |
+
def try_text2int_preprocessed(text):
|
103 |
+
text = str(text)
|
104 |
+
try:
|
105 |
+
tokens = replace_tokens(tokenize(replace_chars(str(text))))
|
106 |
+
except Exception as e:
|
107 |
+
log.error(str(e))
|
108 |
+
tokens = text.split()
|
109 |
+
try:
|
110 |
+
intstr = tokens2int(tokens)
|
111 |
+
except Exception as e:
|
112 |
+
log.error(str(e))
|
113 |
+
intstr = str(TOKENS2INT_ERROR_INT)
|
114 |
+
return intstr
|
115 |
|
116 |
|
117 |
def get_types(cls_set: List[Type], component: str):
|
|
|
146 |
value="42",
|
147 |
label="Output integer:"
|
148 |
)
|
149 |
+
button_text2int.click(try_text2int, inputs=[textbox_input], outputs=[textbox_output])
|
150 |
+
button_text2int_preprocessed.click(try_text2int_preprocessed, inputs=[textbox_input], outputs=[textbox_output])
|
151 |
gr.Markdown(r"""
|
152 |
|
153 |
## API
|
requirements.txt
CHANGED
@@ -1,3 +1,4 @@
|
|
1 |
spacy
|
2 |
pandas
|
3 |
pandas-gbq
|
|
|
|
1 |
spacy
|
2 |
pandas
|
3 |
pandas-gbq
|
4 |
+
gradio>=3.0.2,<3.1.0
|