Team Ai
Apppublic

TangibleAI/mathtext

sourceHugging Faceagpl-3.0updated 4y agoView on Hugging Face
1likes
app.py104 linesDownload Raw Back to root
1import gradio as gr2import spacy  # noqa3 4from mathtext.nlutils import text2int, get_sentiment5 6 7def 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            ## API37            ```python38            import requests39 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            ```bash48            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            ## API78            ```python79            import requests80            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            ```bash89            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_block93 94# interface = gr.Interface(lambda x: x, inputs=["text"], outputs=["text"])95# html_block.input_components = interface.input_components96# html_block.output_components = interface.output_components97# html_block.examples = None98# html_block.predict_durations = []99 100 101if __name__ == "__main__":102    html_block = build_html_block()103    html_block.launch()104