Spaces:
Running
Running
File size: 1,422 Bytes
2976b80 3d44584 2976b80 4d1489a 3d44584 2976b80 262720b 2976b80 4d1489a 2976b80 262720b 2976b80 262720b 4d1489a bdf7117 262720b 2976b80 bdf7117 2976b80 3d44584 4d1489a 2976b80 3d44584 |
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 |
# app.py
# =============
# This is a complete app.py file for a web scraping and text-to-speech app using gTTS, BeautifulSoup, langdetect, and Gradio.
import requests
from bs4 import BeautifulSoup
from gtts import gTTS
import os
import gradio as gr
from langdetect import detect
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)
lang = detect(text)
audio_file = text_to_speech(text, lang)
return audio_file, text
# Create Gradio interface
with gr.Blocks() as demo:
url_input = gr.Textbox(lines=1, placeholder="Enter the URL of the webpage...")
audio_output = gr.Audio(label="Generated Speech")
text_output = gr.Textbox(lines=10, label="Extracted Text")
greet_btn = gr.Button("Submit")
greet_btn.click(fn=process_url, inputs=url_input, outputs=[audio_output, text_output])
if __name__ == "__main__":
demo.launch()
# Dependencies
# =============
# The following dependencies are required to run this app:
# - requests
# - beautifulsoup4
# - gtts
# - langdetect
# - gradio
#
# You can install these dependencies using pip:
# pip install requests beautifulsoup4 gtts langdetect gradio
|