File size: 1,457 Bytes
2fa8cee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# -*- coding: utf-8 -*-
"""gradio-implementation.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1sWjE9rMmM4iMx2Gy5880k53D7yaRfDge
"""

pip install gradio

pip install gTTS

pip install translate

pip install transformers

import gradio as gr
from transformers import pipeline
from gtts import gTTS
from translate import Translator

# Initialize the text summarization pipeline
summarizer = pipeline("summarization")

# Define the Gradio interface
def summarize_and_translate(article, target_language):
    # Summarize the input article
    summary = summarizer(article, max_length=130, min_length=30, do_sample=False)[0]['summary_text']

    # Translate the summary to the target language
    translator = Translator(to_lang=target_language)
    translated_summary = translator.translate(summary)

    # Convert the translated summary to speech
    tts = gTTS(text=translated_summary, lang=target_language)
    tts.save("speech.mp3")

    # Return the summarized text and the path to the generated speech
    return translated_summary, "speech.mp3"

# Create a Gradio interface
iface = gr.Interface(
    fn=summarize_and_translate,
    inputs=["text", "text"],
    outputs=["text", "audio"],
    layout="vertical",
    title="Text Summarization and Translation",
    description="Summarize text and translate it into another language.",
)

# Start the Gradio interface
iface.launch()