# -*- coding: utf-8 -*- # !pip install gradio --quiet # !pip install transformers --quiet """

Sentiment Analysis""" def get_sentiment(text): return sentiment(text)[0]['label'], sentiment(text)[0]['score'] from transformers import pipeline import gradio as gr sentiment = pipeline("sentiment-analysis", model='distilbert/distilbert-base-uncased-finetuned-sst-2-english') sentiment_analysis = gr.Interface(fn=get_sentiment, inputs=gr.Textbox(lines=1, label="Enter the review:"), outputs=[gr.Text(label='Sentiment:'), gr.Text(label='Score:')]) """

Summarization""" def get_summary(text): return summarizer(text, max_length=130, min_length=30, do_sample=False)[0]['summary_text'] summarizer = pipeline("summarization", model='sshleifer/distilbart-cnn-12-6') summarization = gr.Interface(fn=get_summary, inputs=gr.Textbox(lines=1, label="Enter the text:"), outputs=gr.Text(label="Summary:")) """

Speech To Text""" def speechToText(audio): extractTtext = pipeline(model='openai/whisper-tiny') return extractTtext(audio)['text'] speech_to_text = gr.Interface(fn=speechToText, inputs=gr.Audio(sources="upload", type="filepath"), outputs="text") """

ChatBot""" def get_chatbot(text): pipe = pipeline("text-generation", model="distilbert/distilgpt2") response = pipe(text) return response[0]['generated_text'] chatbot = gr.Interface(fn=get_chatbot, inputs=gr.Textbox(lines=1, label="Enter the text:"), outputs=gr.Text(label="Response:")) """

Creating the Tabbed Interface""" demo = gr.TabbedInterface([sentiment_analysis, summarization, speech_to_text, chatbot], ["Sentiment Analysis", "Summarization", 'Speech to Text', 'Chat Bot']) if __name__ == "__main__": demo.launch()