Spaces:
No application file
No application file
| # -*- 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() |