Spaces:
Runtime error
Runtime error
hobs
commited on
Commit
·
5930a87
1
Parent(s):
a6e0470
package mathtext for pip install -e .
Browse files- app.py +91 -96
- api_scaling.py → mathtext/api_scaling.py +0 -0
- nlutils.py → mathtext/nlutils.py +8 -0
- plot_calls.py → mathtext/plot_calls.py +0 -0
- pyproject.toml +14 -21
- requirements.txt +8 -6
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 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
"
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
gr.
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 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 |
-
[
|
| 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 |
-
|
| 11 |
-
|
| 12 |
-
|
| 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 |
-
|
| 45 |
-
pytest = "^7.2"
|
| 46 |
-
|
|
|
|
| 1 |
+
[tool.poetry]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
name = "MathText"
|
|
|
|
| 3 |
version = "0.0.3"
|
| 4 |
authors = [
|
| 5 |
+
"Sebastian Larsen <sebastianlarson22@gmail.com>",
|
| 6 |
+
"Çetin ÇAKIR <cetincakirtr@gmail.com>",
|
| 7 |
+
"Hobson Lane <gitlab@totalgood.com>",
|
| 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 |
-
|
| 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.*
|