import gradio as gr from transformers import pipeline classifier = pipeline('sentiment-analysis') # classifier('We are very happy to show you the 🤗 Transformers library.') #1: Sentiment Analysis def get_sentiment(input_text): return classifier(input_text) sentiment_demo= gr.Interface(fn=get_sentiment, inputs = 'text',outputs=['text'],title = 'Sentiment Analysis', description = "Enter a sentence and know about it's sentiment",examples = [ ["We are very happy to show you the 🤗 Transformers library."], ["I am happy with the performance of Indian Hockey team"], ["Pizza was not at all hot and restaurant was having the pathetic service"] ]) #sentiment_demo.launch(inline = False) #2: Text to Speech #import gradio as gr title = "Text to Speech Translation" tts_examples = [ "I love learning machine learning", "How do you do?", ] tts_demo = gr.Interface.load( "huggingface/facebook/fastspeech2-en-ljspeech", title = title, examples=tts_examples, description="Give me something to say!", ) #3 POS Tagging import nltk nltk.download('punkt') nltk.download('averaged_perceptron_tagger') def get_POS(input_text): sent_tag = nltk.word_tokenize(input_text) for token in sent_tag: return nltk.pos_tag([token]) title = 'Know about Parts of Speech (POS) Tags' examples = [ ["We are very happy to show you the 🤗 Transformers library."], ["I am happy with the performance of Indian Hockey team"], ["Pizza was not at all hot and restaurant was having the pathetic service"] ] POS_demo = gr.Interface(fn=get_POS, inputs = 'text',outputs=['text'],title = title,description = 'Get POS tags',examples = examples) #POS_demo.launch(debug=True) import language_translation.py from language_translation import translation_demo ######################################################################################################## demo = gr.TabbedInterface([tts_demo, sentiment_demo,POS_demo,translation_demo], ["Text-to-speech","Sentiment Analysis","POS findings", "Language Translation"]) if __name__ == "__main__": demo.launch()