Spaces:
Runtime error
Runtime error
hobs
commited on
Commit
·
6cb7f39
1
Parent(s):
459027d
text2int
Browse files
app.py
CHANGED
@@ -3,7 +3,50 @@ import inspect
|
|
3 |
from gradio import routes
|
4 |
from typing import List, Type
|
5 |
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
def get_types(cls_set: List[Type], component: str):
|
8 |
docset = []
|
9 |
types = []
|
@@ -20,14 +63,18 @@ def get_types(cls_set: List[Type], component: str):
|
|
20 |
docset.append(doc_lines[-1].split(":")[-1])
|
21 |
types.append(doc_lines[-1].split(")")[0].split("(")[-1])
|
22 |
return docset, types
|
|
|
|
|
23 |
routes.get_types = get_types
|
24 |
|
25 |
-
|
26 |
def hallo(x):
|
27 |
-
return f"
|
|
|
28 |
|
29 |
def hadet(x):
|
30 |
-
return f"
|
|
|
31 |
|
32 |
with gr.Blocks() as blk:
|
33 |
gr.Markdown("# Gradio Blocks (3.0) with REST API")
|
@@ -65,4 +112,4 @@ blk.output_components = ifa.output_components
|
|
65 |
blk.examples = None
|
66 |
blk.predict_durations = []
|
67 |
|
68 |
-
bapp = blk.launch()
|
|
|
3 |
from gradio import routes
|
4 |
from typing import List, Type
|
5 |
|
6 |
+
|
7 |
+
def text2int(text, numwords={}):
|
8 |
+
""" Convert an English str containing number words into an int
|
9 |
+
|
10 |
+
>>> text2int("nine")
|
11 |
+
9
|
12 |
+
>>> text2int("forty two")
|
13 |
+
42
|
14 |
+
>>> text2int("1 2 three")
|
15 |
+
123
|
16 |
+
"""
|
17 |
+
if not numwords:
|
18 |
+
units = [
|
19 |
+
"zero", "one", "two", "three", "four", "five", "six", "seven", "eight",
|
20 |
+
"nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen",
|
21 |
+
"sixteen", "seventeen", "eighteen", "nineteen",
|
22 |
+
]
|
23 |
+
|
24 |
+
tens = ["", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"]
|
25 |
+
|
26 |
+
scales = ["hundred", "thousand", "million", "billion", "trillion"]
|
27 |
+
|
28 |
+
numwords["and"] = (1, 0)
|
29 |
+
for idx, word in enumerate(units):
|
30 |
+
numwords[word] = (1, idx)
|
31 |
+
for idx, word in enumerate(tens):
|
32 |
+
numwords[word] = (1, idx * 10)
|
33 |
+
for idx, word in enumerate(scales):
|
34 |
+
numwords[word] = (10 ** (idx * 3 or 2), 0)
|
35 |
+
|
36 |
+
current = result = 0
|
37 |
+
for word in text.split():
|
38 |
+
if word not in numwords:
|
39 |
+
raise Exception("Illegal word: " + word)
|
40 |
+
|
41 |
+
scale, increment = numwords[word]
|
42 |
+
current = current * scale + increment
|
43 |
+
if scale > 100:
|
44 |
+
result += current
|
45 |
+
current = 0
|
46 |
+
|
47 |
+
return result + current
|
48 |
+
|
49 |
+
|
50 |
def get_types(cls_set: List[Type], component: str):
|
51 |
docset = []
|
52 |
types = []
|
|
|
63 |
docset.append(doc_lines[-1].split(":")[-1])
|
64 |
types.append(doc_lines[-1].split(")")[0].split("(")[-1])
|
65 |
return docset, types
|
66 |
+
|
67 |
+
|
68 |
routes.get_types = get_types
|
69 |
|
70 |
+
|
71 |
def hallo(x):
|
72 |
+
return f"{text2int(x)}"
|
73 |
+
|
74 |
|
75 |
def hadet(x):
|
76 |
+
return f"{text2int(x)}"
|
77 |
+
|
78 |
|
79 |
with gr.Blocks() as blk:
|
80 |
gr.Markdown("# Gradio Blocks (3.0) with REST API")
|
|
|
112 |
blk.examples = None
|
113 |
blk.predict_durations = []
|
114 |
|
115 |
+
bapp = blk.launch()
|