Files changed (1) hide show
  1. app.py +37 -7
app.py CHANGED
@@ -1,14 +1,44 @@
1
  import gradio as gr
 
 
2
 
3
- def simple_search(query):
4
- return f"You searched for: {query}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- # Gradio Interface
7
  with gr.Blocks() as demo:
8
- query = gr.Textbox(label="Search the web")
9
- output = gr.Textbox(label="Results")
10
- submit_btn = gr.Button("Submit")
 
11
 
12
- submit_btn.click(simple_search, query, output)
 
13
 
14
  demo.launch()
 
 
1
  import gradio as gr
2
+ import requests
3
+ from bs4 import BeautifulSoup
4
 
5
+ # Function to scrape a specific website (https://chatgpt.com/)
6
+ def scrape_website(url):
7
+ try:
8
+ # Send a request to the website
9
+ response = requests.get(url, allow_redirects=True) # This will handle redirects automatically
10
+
11
+ # Check if the response was successful
12
+ if response.status_code == 200:
13
+ # Parse the page content
14
+ soup = BeautifulSoup(response.content, 'html.parser')
15
+
16
+ # Extract the title of the webpage
17
+ title = soup.find('title').get_text()
18
+
19
+ # Extract the meta description if available
20
+ meta_description = soup.find('meta', attrs={'name': 'description'})
21
+ if meta_description:
22
+ meta_description = meta_description.get('content')
23
+ else:
24
+ meta_description = "No meta description available"
25
+
26
+ return f"Title: {title}\nMeta Description: {meta_description}"
27
+ else:
28
+ return f"Failed to access {url} (status code: {response.status_code})"
29
+
30
+ except Exception as e:
31
+ return f"An error occurred: {str(e)}"
32
 
33
+ # Gradio interface to input URL and display scraped content
34
  with gr.Blocks() as demo:
35
+ url_input = gr.Textbox(value="https://chatgpt.com", label="URL", placeholder="Enter URL")
36
+ output = gr.Textbox(label="Scraped Data")
37
+
38
+ submit_btn = gr.Button("Scrape Website")
39
 
40
+ # Set the button action
41
+ submit_btn.click(scrape_website, url_input, output)
42
 
43
  demo.launch()
44
+