Spaces:
Runtime error
Runtime error
!pip install gradio transformers torch | |
import gradio as gr | |
from transformers import pipeline | |
translator = pipeline("translation_en_to_fr",model="Mr-Vicky-01/Fine_tune_english_to_tamil") | |
sentiment_analyzer = pipeline("sentiment-analysis") | |
summerizer = pipeline("summarization",model = "facebook/bart-large-cnn") | |
def translate_text(text): | |
result = translator(text) | |
return result[0]['translation_text'] | |
def summarization(text): | |
result = summerizer(text) | |
return result[0]['summary_text'] | |
def analyze_sentiment(text): | |
result = sentiment_analyzer(text) | |
a = result[0]['label'] | |
b = round(result[0]['score'],3) | |
if (a == 'POSITIVE'): | |
return 'Happy' | |
elif(a == 'negative'): | |
return 'Unhappy' | |
with gr.Blocks() as demo: | |
gr.Markdown("Text Pipeline : Translation,summarization, and Sentiemnt Analysis") | |
#TRANSLATION TAB | |
with gr.Tab("Translation"): | |
input_text = gr.Textbox(label = "Enter text for translation") | |
output_text = gr.Textbox(label = "Translated text") | |
translate_button = gr.Button("Translate") | |
translate_button.click(fn=translate_text,inputs = input_text,outputs = output_text) | |
#SUMMARIZATION TAB | |
with gr.Tab("Summarization"): | |
input_summary = gr.Textbox(label = "Enter text for Summarization") | |
output_summary = gr.Textbox(label = "Summarized text") | |
summarize_button = gr.Button("Summarize") | |
summarize_button.click(fn=summarization,inputs = input_summary,outputs = output_summary) | |
with gr.Tab("Sentiment Analysis"): | |
input_sentiment = gr.Textbox(label = "Enter text for Sentiment Analysis") | |
output_sentiement = gr.Textbox(label = "Sentiment Analysis Result") | |
sentiment_button = gr.Button("Sentiment Analysis") | |
sentiment_button.click(fn=analyze_sentiment,inputs = input_sentiment,outputs = output_sentiement) | |
demo.launch() |