Hobson commited on
Commit
5930a87
1 Parent(s): a6e0470

package mathtext for pip install -e .

Browse files
app.py CHANGED
@@ -1,108 +1,103 @@
1
  import gradio as gr
2
  import spacy # noqa
3
- from transformers import pipeline
4
 
5
- from mathtext.nlutils import text2int
6
-
7
-
8
- sentiment = pipeline(task="sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
9
-
10
-
11
- def get_sentiment(text):
12
- return sentiment(text)
13
-
14
-
15
- with gr.Blocks() as html_block:
16
- gr.Markdown("# Rori - Mathbot")
17
-
18
- with gr.Tab("Text to integer"):
19
- inputs_text2int = [gr.Text(
20
- placeholder="Type a number as text or a sentence",
21
- label="Text to process",
22
- value="forty two")]
23
-
24
- outputs_text2int = gr.Textbox(label="Output integer")
25
-
26
- button_text2int = gr.Button("text2int")
27
-
28
- button_text2int.click(
29
- fn=text2int,
30
- inputs=inputs_text2int,
31
- outputs=outputs_text2int,
32
- api_name="text2int",
33
- )
34
-
35
- examples_text2int = [
36
- "one thousand forty seven",
37
- "one hundred",
38
- ]
39
-
40
- gr.Examples(examples=examples_text2int, inputs=inputs_text2int)
41
-
42
- gr.Markdown(r"""
43
- ## API
44
- ```python
45
- import requests
46
-
47
- requests.post(
48
- url="https://tangibleai-mathtext.hf.space/run/text2int", json={"data": ["one hundred forty five"]}
49
- ).json()
50
- ```
51
-
52
- Or using `curl`:
53
-
54
- ```bash
55
- curl -X POST https://tangibleai-mathtext.hf.space/run/text2int -H 'Content-Type: application/json' -d '{"data": ["one hundred forty five"]}'
56
- ```
57
- """)
58
-
59
- with gr.Tab("Sentiment Analysis"):
60
- inputs_sentiment = [
61
- gr.Text(placeholder="Type a number as text or a sentence", label="Text to process",
62
- value="I really like it!"),
63
- ]
64
-
65
- outputs_sentiment = gr.Textbox(label="Sentiment result")
66
-
67
- button_sentiment = gr.Button("sentiment analysis")
68
-
69
- button_sentiment.click(
70
- get_sentiment,
71
- inputs=inputs_sentiment,
72
- outputs=outputs_sentiment,
73
- api_name="sentiment-analysis"
74
- )
75
-
76
- examples_sentiment = [
77
- ["Totally agree!"],
78
- ["Sorry, I can not accept this!"],
79
- ]
80
-
81
- gr.Examples(examples=examples_sentiment, inputs=inputs_sentiment)
82
-
83
- gr.Markdown(r"""
84
- ## API
85
- ```python
86
- import requests
87
-
88
- requests.post(
89
- url="https://tangibleai-mathtext.hf.space/run/sentiment-analysis", json={"data": ["You are right!"]}
90
- ).json()
91
- ```
92
-
93
- Or using `curl`:
94
-
95
- ```bash
96
- curl -X POST https://tangibleai-mathtext.hf.space/run/sentiment-analysis -H 'Content-Type: application/json' -d '{"data": ["You are right!"]}'
97
- ```
98
- """)
99
 
100
  # interface = gr.Interface(lambda x: x, inputs=["text"], outputs=["text"])
101
  # html_block.input_components = interface.input_components
102
  # html_block.output_components = interface.output_components
103
  # html_block.examples = None
 
104
 
105
- html_block.predict_durations = []
106
 
107
  if __name__ == "__main__":
 
108
  html_block.launch()
 
1
  import gradio as gr
2
  import spacy # noqa
 
3
 
4
+ from mathtext.nlutils import text2int, get_sentiment
5
+
6
+
7
+ def build_html_block():
8
+ with gr.Blocks() as html_block:
9
+ gr.Markdown("# Rori - Mathbot")
10
+
11
+ with gr.Tab("Text to integer"):
12
+ inputs_text2int = [gr.Text(
13
+ placeholder="Type a number as text or a sentence",
14
+ label="Text to process",
15
+ value="forty two")]
16
+
17
+ outputs_text2int = gr.Textbox(label="Output integer")
18
+
19
+ button_text2int = gr.Button("text2int")
20
+
21
+ button_text2int.click(
22
+ fn=text2int,
23
+ inputs=inputs_text2int,
24
+ outputs=outputs_text2int,
25
+ api_name="text2int",
26
+ )
27
+
28
+ examples_text2int = [
29
+ "one thousand forty seven",
30
+ "one hundred",
31
+ ]
32
+
33
+ gr.Examples(examples=examples_text2int, inputs=inputs_text2int)
34
+
35
+ gr.Markdown(r"""
36
+ ## API
37
+ ```python
38
+ import requests
39
+
40
+ requests.post(
41
+ url="https://tangibleai-mathtext.hf.space/run/text2int", json={"data": ["one hundred forty five"]}
42
+ ).json()
43
+ ```
44
+
45
+ Or using `curl`:
46
+
47
+ ```bash
48
+ curl -X POST https://tangibleai-mathtext.hf.space/run/text2int -H 'Content-Type: application/json' -d '{"data": ["one hundred forty five"]}'
49
+ ```
50
+ """)
51
+
52
+ with gr.Tab("Sentiment Analysis"):
53
+ inputs_sentiment = [
54
+ gr.Text(placeholder="Type a number as text or a sentence", label="Text to process",
55
+ value="I really like it!"),
56
+ ]
57
+
58
+ outputs_sentiment = gr.Textbox(label="Sentiment result")
59
+
60
+ button_sentiment = gr.Button("sentiment analysis")
61
+
62
+ button_sentiment.click(
63
+ get_sentiment,
64
+ inputs=inputs_sentiment,
65
+ outputs=outputs_sentiment,
66
+ api_name="sentiment-analysis"
67
+ )
68
+
69
+ examples_sentiment = [
70
+ ["Totally agree!"],
71
+ ["Sorry, I can not accept this!"],
72
+ ]
73
+
74
+ gr.Examples(examples=examples_sentiment, inputs=inputs_sentiment)
75
+
76
+ gr.Markdown(r"""
77
+ ## API
78
+ ```python
79
+ import requests
80
+
81
+ requests.post(
82
+ url="https://tangibleai-mathtext.hf.space/run/sentiment-analysis", json={"data": ["You are right!"]}
83
+ ).json()
84
+ ```
85
+
86
+ Or using `curl`:
87
+
88
+ ```bash
89
+ curl -X POST https://tangibleai-mathtext.hf.space/run/sentiment-analysis -H 'Content-Type: application/json' -d '{"data": ["You are right!"]}'
90
+ ```
91
+ """)
92
+ return html_block
 
 
 
 
 
93
 
94
  # interface = gr.Interface(lambda x: x, inputs=["text"], outputs=["text"])
95
  # html_block.input_components = interface.input_components
96
  # html_block.output_components = interface.output_components
97
  # html_block.examples = None
98
+ # html_block.predict_durations = []
99
 
 
100
 
101
  if __name__ == "__main__":
102
+ html_block = build_html_block()
103
  html_block.launch()
api_scaling.py → mathtext/api_scaling.py RENAMED
File without changes
nlutils.py → mathtext/nlutils.py RENAMED
@@ -1,6 +1,7 @@
1
  import spacy # noqa
2
  import time
3
  from editdistance import eval as edit_dist
 
4
 
5
  # import os
6
  # os.environ['KMP_DUPLICATE_LIB_OK']='True'
@@ -318,6 +319,13 @@ def correct_number_text(text):
318
  # TODO
319
 
320
 
 
 
 
 
 
 
 
321
  def robust_text2int(text):
322
  """ Correct spelling of number words in text before using text2int """
323
  try:
 
1
  import spacy # noqa
2
  import time
3
  from editdistance import eval as edit_dist
4
+ from transformers import pipeline
5
 
6
  # import os
7
  # os.environ['KMP_DUPLICATE_LIB_OK']='True'
 
319
  # TODO
320
 
321
 
322
+ sentiment = pipeline(task="sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
323
+
324
+
325
+ def get_sentiment(text):
326
+ return sentiment(text)
327
+
328
+
329
  def robust_text2int(text):
330
  """ Correct spelling of number words in text before using text2int """
331
  try:
plot_calls.py → mathtext/plot_calls.py RENAMED
File without changes
pyproject.toml CHANGED
@@ -1,28 +1,15 @@
1
- [build-system]
2
- requires = ["setuptools>=40.8.0", "wheel"]
3
- build-backend = "setuptools.build_meta:__legacy__"
4
-
5
- [project]
6
  name = "MathText"
7
- packages = {find = "mathtext"}
8
  version = "0.0.3"
9
  authors = [
10
- {name="Sebastian Larsen", email="[email protected]"},
11
- {name="Çetin ÇAKIR", email="[email protected]"},
12
- {name="Hobson Lane", email="[email protected]"},
13
  ]
14
  description = "Natural Language Understanding (text processing) for math symbols, digits, and words with a Gradio user interface and REST API."
15
  readme = "README.md"
16
- requires-python = ">=3.7"
17
- license = {file = "LICENSE.md"}
18
- classifiers = [
19
- "Programming Language :: Python :: 3",
20
- # "License :: OSI Approved :: MIT License",
21
- "License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)",
22
- "Operating System :: OS Independent",
23
- ]
24
 
25
- [dependencies]
26
  python = "^3.7"
27
  editdistance = "*"
28
  gradio = "3.14.*"
@@ -33,14 +20,20 @@ pandas-gbq = "0.19.*"
33
  pytest = "7.2.*"
34
  python-dotenv = "0.21.*"
35
  scikit-learn = "^1.2"
 
36
  spacy = "3.4.*"
37
  torch = "1.12.*"
38
  transformers = "4.24.*"
39
 
 
 
 
 
 
 
 
40
  # [build-system]
41
  # requires = ["hatchling"]
42
  # build-backend = "hatchling.build"
43
 
44
- [tool.poetry.dev-dependencies]
45
- pytest = "^7.2"
46
-
 
1
+ [tool.poetry]
 
 
 
 
2
  name = "MathText"
 
3
  version = "0.0.3"
4
  authors = [
5
+ "Sebastian Larsen <[email protected]>",
6
+ "Çetin ÇAKIR <[email protected]>",
7
+ "Hobson Lane <[email protected]>",
8
  ]
9
  description = "Natural Language Understanding (text processing) for math symbols, digits, and words with a Gradio user interface and REST API."
10
  readme = "README.md"
 
 
 
 
 
 
 
 
11
 
12
+ [tool.poetry.dependencies]
13
  python = "^3.7"
14
  editdistance = "*"
15
  gradio = "3.14.*"
 
20
  pytest = "7.2.*"
21
  python-dotenv = "0.21.*"
22
  scikit-learn = "^1.2"
23
+ scikit-image = "^0.17"
24
  spacy = "3.4.*"
25
  torch = "1.12.*"
26
  transformers = "4.24.*"
27
 
28
+ [tool.poetry.group.dev.dependencies]
29
+ pytest = "^7.2.1"
30
+
31
+ [build-system]
32
+ requires = ["poetry-core"]
33
+ build-backend = "poetry.core.masonry.api"
34
+
35
  # [build-system]
36
  # requires = ["hatchling"]
37
  # build-backend = "hatchling.build"
38
 
39
+ # repository = "https://gitlab.com/tangibleai/community/mathtext"
 
 
requirements.txt CHANGED
@@ -1,10 +1,12 @@
1
- spacy==3.4.*
2
- pandas==1.5.*
3
- pandas-gbq==0.19.*
4
  gradio==3.14.*
5
- python-dotenv==0.21.*
6
- transformers==4.24.*
7
- torch==1.12.*
8
  httpx==0.23.*
9
  matplotlib==3.6.*
 
 
10
  pytest==7.2.*
 
 
 
 
 
 
1
+ editdistance
 
 
2
  gradio==3.14.*
 
 
 
3
  httpx==0.23.*
4
  matplotlib==3.6.*
5
+ pandas==1.5.*
6
+ pandas-gbq==0.19.*
7
  pytest==7.2.*
8
+ python-dotenv==0.21.*
9
+ scikit-learn
10
+ spacy==3.4.*
11
+ torch==1.12.*
12
+ transformers==4.24.*