KSh100 commited on
Commit
bf6070d
·
verified ·
1 Parent(s): a7a0560

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -7
app.py CHANGED
@@ -81,7 +81,7 @@ def format_detailed_output(structured_data):
81
 
82
  # --- Web Page Processing Functions ---
83
 
84
- def download_and_process_web_page(url, clean=True):
85
  """Downloads a web page from a URL and processes its content."""
86
  if not url.startswith("http://") and not url.startswith("https://"):
87
  url = "http://" + url # Prepend "http://" if not present
@@ -89,7 +89,7 @@ def download_and_process_web_page(url, clean=True):
89
  try:
90
  response = get(url)
91
  if response.status_code != 200:
92
- return f"Error: Received status code {response.status_code}", 0
93
 
94
  soup = response.soup()
95
  structured_data = {
@@ -97,12 +97,12 @@ def download_and_process_web_page(url, clean=True):
97
  "Links": extract_links(soup, url),
98
  "Images": extract_images(soup, url)
99
  }
100
- return format_detailed_output(structured_data), 0
101
 
102
  except urllib3.exceptions.HTTPError as e:
103
- return f"Error: {e}", 0
104
  except Exception as e:
105
- return f"Error processing web page: {e}", 0
106
 
107
  # --- Gradio Interface ---
108
 
@@ -110,11 +110,9 @@ iface = gr.Interface(
110
  fn=download_and_process_web_page,
111
  inputs=[
112
  gr.Textbox(lines=1, placeholder="Enter URL of the web page"),
113
- gr.Checkbox(label="Clean Text", value=True),
114
  ],
115
  outputs=[
116
  gr.Markdown(label="Web Page Content"),
117
- gr.Number(label="Content Length (characters)"),
118
  ],
119
  title="Enhanced Web Page Processor for Hugging Face Chat Tools",
120
  description="Enter the URL of a web page. The tool will extract and format its content, including text, links, and images. This tool is designed for use with Hugging Face Chat Tools. \n [https://hf.co/chat/tools/66f1a8159d41ad4398ebb711](https://hf.co/chat/tools/66f1a8159d41ad4398ebb711)",
 
81
 
82
  # --- Web Page Processing Functions ---
83
 
84
+ def download_and_process_web_page(url):
85
  """Downloads a web page from a URL and processes its content."""
86
  if not url.startswith("http://") and not url.startswith("https://"):
87
  url = "http://" + url # Prepend "http://" if not present
 
89
  try:
90
  response = get(url)
91
  if response.status_code != 200:
92
+ return f"Error: Received status code {response.status_code}"
93
 
94
  soup = response.soup()
95
  structured_data = {
 
97
  "Links": extract_links(soup, url),
98
  "Images": extract_images(soup, url)
99
  }
100
+ return format_detailed_output(structured_data)
101
 
102
  except urllib3.exceptions.HTTPError as e:
103
+ return f"Error: {e}"
104
  except Exception as e:
105
+ return f"Error processing web page: {e}"
106
 
107
  # --- Gradio Interface ---
108
 
 
110
  fn=download_and_process_web_page,
111
  inputs=[
112
  gr.Textbox(lines=1, placeholder="Enter URL of the web page"),
 
113
  ],
114
  outputs=[
115
  gr.Markdown(label="Web Page Content"),
 
116
  ],
117
  title="Enhanced Web Page Processor for Hugging Face Chat Tools",
118
  description="Enter the URL of a web page. The tool will extract and format its content, including text, links, and images. This tool is designed for use with Hugging Face Chat Tools. \n [https://hf.co/chat/tools/66f1a8159d41ad4398ebb711](https://hf.co/chat/tools/66f1a8159d41ad4398ebb711)",