Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,12 @@
|
|
1 |
# app.py
|
2 |
# =============
|
3 |
-
# This is a complete app.py file for a web scraping and text-to-speech app using gTTS and
|
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)
|
@@ -16,17 +17,22 @@ def get_text_from_webpage(url):
|
|
16 |
def text_to_speech(text, lang='en'):
|
17 |
tts = gTTS(text=text, lang=lang)
|
18 |
tts.save("output.mp3")
|
19 |
-
|
20 |
|
21 |
-
def
|
22 |
-
url = input("Enter the URL of the webpage: ")
|
23 |
text = get_text_from_webpage(url)
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
if __name__ == "__main__":
|
29 |
-
|
30 |
|
31 |
# Dependencies
|
32 |
# =============
|
@@ -34,6 +40,7 @@ if __name__ == "__main__":
|
|
34 |
# - requests
|
35 |
# - beautifulsoup4
|
36 |
# - gtts
|
|
|
37 |
#
|
38 |
# You can install these dependencies using pip:
|
39 |
-
# pip install requests beautifulsoup4 gtts
|
|
|
1 |
# app.py
|
2 |
# =============
|
3 |
+
# This is a complete app.py file for a web scraping and text-to-speech app using gTTS, BeautifulSoup, and Gradio.
|
4 |
|
5 |
import requests
|
6 |
from bs4 import BeautifulSoup
|
7 |
from gtts import gTTS
|
8 |
import os
|
9 |
+
import gradio as gr
|
10 |
|
11 |
def get_text_from_webpage(url):
|
12 |
response = requests.get(url)
|
|
|
17 |
def text_to_speech(text, lang='en'):
|
18 |
tts = gTTS(text=text, lang=lang)
|
19 |
tts.save("output.mp3")
|
20 |
+
return "output.mp3"
|
21 |
|
22 |
+
def process_url(url):
|
|
|
23 |
text = get_text_from_webpage(url)
|
24 |
+
audio_file = text_to_speech(text)
|
25 |
+
return audio_file, text
|
26 |
+
|
27 |
+
# Create Gradio interface
|
28 |
+
iface = gr.Interface(
|
29 |
+
fn=process_url,
|
30 |
+
inputs=gr.inputs.Textbox(lines=1, placeholder="Enter the URL of the webpage..."),
|
31 |
+
outputs=[gr.outputs.Audio(type="filepath"), gr.outputs.Textbox(lines=10, label="Extracted Text")]
|
32 |
+
)
|
33 |
|
34 |
if __name__ == "__main__":
|
35 |
+
iface.launch()
|
36 |
|
37 |
# Dependencies
|
38 |
# =============
|
|
|
40 |
# - requests
|
41 |
# - beautifulsoup4
|
42 |
# - gtts
|
43 |
+
# - gradio
|
44 |
#
|
45 |
# You can install these dependencies using pip:
|
46 |
+
# pip install requests beautifulsoup4 gtts gradio
|