link-to-text / app.py
Ivan000's picture
Update app.py
4d1489a verified
raw
history blame
1.2 kB
# app.py
# =============
# This is a complete app.py file for a web scraping and text-to-speech app using gTTS, BeautifulSoup, and Gradio.
import requests
from bs4 import BeautifulSoup
from gtts import gTTS
import os
import gradio as gr
def get_text_from_webpage(url):
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
text = soup.get_text()
return text
def text_to_speech(text, lang='en'):
tts = gTTS(text=text, lang=lang)
tts.save("output.mp3")
return "output.mp3"
def process_url(url):
text = get_text_from_webpage(url)
audio_file = text_to_speech(text)
return audio_file, text
# Create Gradio interface
iface = gr.Interface(
fn=process_url,
inputs=gr.inputs.Textbox(lines=1, placeholder="Enter the URL of the webpage..."),
outputs=[gr.outputs.Audio(type="filepath"), gr.outputs.Textbox(lines=10, label="Extracted Text")]
)
if __name__ == "__main__":
iface.launch()
# Dependencies
# =============
# The following dependencies are required to run this app:
# - requests
# - beautifulsoup4
# - gtts
# - gradio
#
# You can install these dependencies using pip:
# pip install requests beautifulsoup4 gtts gradio