Upload 2 files
Browse files- MultilinguaSummarizer.ipynb +0 -0
- gradio_implementation.py +53 -0
MultilinguaSummarizer.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
gradio_implementation.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""gradio-implementation.ipynb
|
| 3 |
+
|
| 4 |
+
Automatically generated by Colaboratory.
|
| 5 |
+
|
| 6 |
+
Original file is located at
|
| 7 |
+
https://colab.research.google.com/drive/1sWjE9rMmM4iMx2Gy5880k53D7yaRfDge
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
pip install gradio
|
| 11 |
+
|
| 12 |
+
pip install gTTS
|
| 13 |
+
|
| 14 |
+
pip install translate
|
| 15 |
+
|
| 16 |
+
pip install transformers
|
| 17 |
+
|
| 18 |
+
import gradio as gr
|
| 19 |
+
from transformers import pipeline
|
| 20 |
+
from gtts import gTTS
|
| 21 |
+
from translate import Translator
|
| 22 |
+
|
| 23 |
+
# Initialize the text summarization pipeline
|
| 24 |
+
summarizer = pipeline("summarization")
|
| 25 |
+
|
| 26 |
+
# Define the Gradio interface
|
| 27 |
+
def summarize_and_translate(article, target_language):
|
| 28 |
+
# Summarize the input article
|
| 29 |
+
summary = summarizer(article, max_length=130, min_length=30, do_sample=False)[0]['summary_text']
|
| 30 |
+
|
| 31 |
+
# Translate the summary to the target language
|
| 32 |
+
translator = Translator(to_lang=target_language)
|
| 33 |
+
translated_summary = translator.translate(summary)
|
| 34 |
+
|
| 35 |
+
# Convert the translated summary to speech
|
| 36 |
+
tts = gTTS(text=translated_summary, lang=target_language)
|
| 37 |
+
tts.save("speech.mp3")
|
| 38 |
+
|
| 39 |
+
# Return the summarized text and the path to the generated speech
|
| 40 |
+
return translated_summary, "speech.mp3"
|
| 41 |
+
|
| 42 |
+
# Create a Gradio interface
|
| 43 |
+
iface = gr.Interface(
|
| 44 |
+
fn=summarize_and_translate,
|
| 45 |
+
inputs=["text", "text"],
|
| 46 |
+
outputs=["text", "audio"],
|
| 47 |
+
layout="vertical",
|
| 48 |
+
title="Text Summarization and Translation",
|
| 49 |
+
description="Summarize text and translate it into another language.",
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
# Start the Gradio interface
|
| 53 |
+
iface.launch()
|