File size: 948 Bytes
e7c6d66
 
 
 
 
321422d
 
 
e7c6d66
 
321422d
e7c6d66
 
321422d
e7c6d66
 
321422d
 
 
 
 
2f58778
321422d
6f1cd1d
 
321422d
e7c6d66
321422d
9e80eb2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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()  # Raises an HTTPError for bad responses (4xx or 5xx)
        return response.text
    except requests.exceptions.RequestException as e:
        return f"An error occurred: {e}"

# Define the Gradio interface
demo = gr.Interface(
    fn=fetch_content,
    inputs=gr.Textbox(label="URL", placeholder="https://www.google.com"),
    outputs=gr.Textbox(label="Page Content"),
    title="Fetch MCP",
    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)