simran40 commited on
Commit
d33b81f
·
verified ·
1 Parent(s): 6635033

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -13
app.py CHANGED
@@ -1,16 +1,23 @@
1
- from flask import Flask, render_template, request
2
- from scraper import scrape_blog
3
 
4
- app = Flask(__name__)
 
 
 
 
5
 
6
- @app.route('/', methods=['GET', 'POST'])
7
- def home():
8
- if request.method == 'POST':
9
- url = request.form.get('url')
10
- tag = request.form.get('tag') or 'h2'
11
- data = scrape_blog(url, tag)
12
- return render_template('result.html', titles=data, url=url, tag=tag)
13
- return render_template('index.html')
 
 
 
14
 
15
- if __name__ == '__main__':
16
- app.run(debug=True)
 
1
+ import gradio as gr
2
+ from scraper import scrape_blog # your existing scraper function
3
 
4
+ # Define a function to scrape and return results
5
+ def scrape(url, tag='h2'):
6
+ data = scrape_blog(url, tag)
7
+ # Join the results into a string for display in Gradio
8
+ return "\n".join(data)
9
 
10
+ # Create Gradio interface
11
+ iface = gr.Interface(
12
+ fn=scrape,
13
+ inputs=[
14
+ gr.Textbox(label="Enter URL"),
15
+ gr.Textbox(label="Enter HTML Tag (default: h2)", value="h2")
16
+ ],
17
+ outputs=gr.Textbox(label="Scraped Titles"),
18
+ title="Blog Scraper",
19
+ description="Enter a URL and an HTML tag to scrape titles or headings from a blog."
20
+ )
21
 
22
+ # Launch the interface
23
+ iface.launch()