|
import gradio as gr |
|
import requests |
|
|
|
def fetch_content(url): |
|
""" |
|
This function takes a URL as input, fetches its HTML content, |
|
and returns it as a string. It includes error handling for common |
|
request issues. |
|
""" |
|
try: |
|
response = requests.get(url, headers={'User-Agent': 'Mozilla/5.0'}) |
|
response.raise_for_status() |
|
return response.text |
|
except requests.exceptions.RequestException as e: |
|
return f"An error occurred: {e}" |
|
|
|
|
|
demo = gr.Interface( |
|
fn=fetch_content, |
|
inputs=gr.Textbox(label="URL", placeholder="https://www.google.com"), |
|
outputs=gr.Textbox(label="Page Content"), |
|
title="Fetch", |
|
description="Enter a URL to fetch the full HTML content of the web page.", |
|
allow_flagging="never", |
|
theme="Nymbo/Nymbo_Theme" |
|
) |
|
|
|
if __name__ == "__main__": |
|
demo.launch(mcp_server=True) |