Spaces:
Sleeping
Sleeping
File size: 1,986 Bytes
a9641b4 ddaa07d a9641b4 |
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 |
# -*- coding: utf-8 -*-
# !pip install gradio --quiet
# !pip install transformers --quiet
"""<h1> 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:')])
"""<h1> 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:"))
"""<h1> 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")
"""<h1> 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:"))
"""<h1> 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() |