Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# app.py
|
2 |
+
# =============
|
3 |
+
# This is a complete app.py file for a web scraping and text-to-speech app using gTTS and BeautifulSoup.
|
4 |
+
|
5 |
+
import requests
|
6 |
+
from bs4 import BeautifulSoup
|
7 |
+
from gtts import gTTS
|
8 |
+
import os
|
9 |
+
|
10 |
+
def get_text_from_webpage(url):
|
11 |
+
response = requests.get(url)
|
12 |
+
soup = BeautifulSoup(response.text, 'html.parser')
|
13 |
+
text = soup.get_text()
|
14 |
+
return text
|
15 |
+
|
16 |
+
def text_to_speech(text, lang='en'):
|
17 |
+
tts = gTTS(text=text, lang=lang)
|
18 |
+
tts.save("output.mp3")
|
19 |
+
os.system("start output.mp3")
|
20 |
+
|
21 |
+
def main():
|
22 |
+
url = input("Enter the URL of the webpage: ")
|
23 |
+
text = get_text_from_webpage(url)
|
24 |
+
print("Extracted text from the webpage:")
|
25 |
+
print(text)
|
26 |
+
text_to_speech(text)
|
27 |
+
|
28 |
+
if __name__ == "__main__":
|
29 |
+
main()
|
30 |
+
|
31 |
+
# Dependencies
|
32 |
+
# =============
|
33 |
+
# The following dependencies are required to run this app:
|
34 |
+
# - requests
|
35 |
+
# - beautifulsoup4
|
36 |
+
# - gtts
|
37 |
+
#
|
38 |
+
# You can install these dependencies using pip:
|
39 |
+
# pip install requests beautifulsoup4 gtts
|