Spaces:
Runtime error
Runtime error
File size: 3,018 Bytes
d625a73 8c4b92d 90009ee 9b8bd50 d5d83ae 43ac953 bf32265 90009ee bf32265 05b4410 bf32265 05b4410 e33c2d8 d5d83ae bf32265 05b4410 bf32265 05b4410 bf32265 05b4410 43ac953 05b4410 bf32265 05b4410 43ac953 05b4410 43ac953 bf32265 90009ee bf32265 db3317c |
1 2 3 4 5 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 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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
import gradio as gr
import spacy # noqa
from transformers import pipeline
from mathtext.nlutils import text2int
sentiment = pipeline(task="sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
def get_sentiment(text):
return sentiment(text)
with gr.Blocks() as html_block:
gr.Markdown("# Rori - Mathbot")
with gr.Tab("Text to integer"):
inputs_text2int = [gr.Text(
placeholder="Type a number as text or a sentence",
label="Text to process",
value="forty two")]
outputs_text2int = gr.Textbox(label="Output integer")
button_text2int = gr.Button("text2int")
button_text2int.click(
fn=text2int,
inputs=inputs_text2int,
outputs=outputs_text2int,
api_name="text2int",
)
examples_text2int = [
"one thousand forty seven",
"one hundred",
]
gr.Examples(examples=examples_text2int, inputs=inputs_text2int)
gr.Markdown(r"""
## API
```python
import requests
requests.post(
url="https://tangibleai-mathtext.hf.space/run/text2int", json={"data": ["one hundred forty five"]}
).json()
```
Or using `curl`:
```bash
curl -X POST https://tangibleai-mathtext.hf.space/run/text2int -H 'Content-Type: application/json' -d '{"data": ["one hundred forty five"]}'
```
""")
with gr.Tab("Sentiment Analysis"):
inputs_sentiment = [
gr.Text(placeholder="Type a number as text or a sentence", label="Text to process",
value="I really like it!"),
]
outputs_sentiment = gr.Textbox(label="Sentiment result")
button_sentiment = gr.Button("sentiment analysis")
button_sentiment.click(
get_sentiment,
inputs=inputs_sentiment,
outputs=outputs_sentiment,
api_name="sentiment-analysis"
)
examples_sentiment = [
["Totally agree!"],
["Sorry, I can not accept this!"],
]
gr.Examples(examples=examples_sentiment, inputs=inputs_sentiment)
gr.Markdown(r"""
## API
```python
import requests
requests.post(
url="https://tangibleai-mathtext.hf.space/run/sentiment-analysis", json={"data": ["You are right!"]}
).json()
```
Or using `curl`:
```bash
curl -X POST https://tangibleai-mathtext.hf.space/run/sentiment-analysis -H 'Content-Type: application/json' -d '{"data": ["You are right!"]}'
```
""")
# interface = gr.Interface(lambda x: x, inputs=["text"], outputs=["text"])
# html_block.input_components = interface.input_components
# html_block.output_components = interface.output_components
# html_block.examples = None
html_block.predict_durations = []
if __name__ == "__main__":
html_block.launch()
|