VishnuPottabatthini commited on
Commit
9b4af57
·
verified ·
1 Parent(s): 6b69b2b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -0
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from newspaper import Article
3
+
4
+ # Function to scrape the article from a given URL
5
+ def scrape_article(url):
6
+ try:
7
+ # Create an Article object
8
+ article = Article(url)
9
+
10
+ # Download and parse the article
11
+ article.download()
12
+ article.parse()
13
+
14
+ # Extract the title and text content
15
+ title = article.title
16
+ content = article.text
17
+
18
+ if not content:
19
+ return "Failed to scrape content. Please check the URL."
20
+
21
+ return f"Title: {title}\n\nContent:\n{content}"
22
+ except Exception as e:
23
+ return f"Error: {str(e)}"
24
+
25
+ # Gradio interface
26
+ def main():
27
+ # Define the Gradio input-output interface
28
+ with gr.Blocks() as interface:
29
+ gr.Markdown("""## Article Scraper using Newspaper3k
30
+ Enter a URL to scrape the article content.""")
31
+
32
+ # Input and output widgets
33
+ url_input = gr.Textbox(label="Enter the Article URL")
34
+ output = gr.Textbox(label="Scraped Article", lines=15)
35
+
36
+ # Button to trigger scraping
37
+ scrape_button = gr.Button("Scrape Article")
38
+
39
+ # Button functionality
40
+ scrape_button.click(scrape_article, inputs=[url_input], outputs=[output])
41
+
42
+ return interface
43
+
44
+ if __name__ == "__main__":
45
+ interface = main()
46
+ interface.launch()