Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -58,9 +58,28 @@ gr.load_openapi(
|
|
| 58 |
base_url=\"{}\",
|
| 59 |
paths={},
|
| 60 |
methods={},
|
|
|
|
| 61 |
).launch(mcp_server=True)
|
| 62 |
"""
|
| 63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
def create_hf_space(token, space_name, app_code):
|
| 65 |
"""
|
| 66 |
Create a new Hugging Face Space with optional app.py file
|
|
@@ -95,6 +114,21 @@ def create_hf_space(token, space_name, app_code):
|
|
| 95 |
repo_type="space",
|
| 96 |
commit_message="Add app.py"
|
| 97 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
space_url = f"https://huggingface.co/spaces/{space_id}"
|
| 99 |
gr.Success(f"π Your space will be available at: <a href='{space_url}' target='_blank'>{space_url} ‴</a>", duration=None)
|
| 100 |
return space_info
|
|
@@ -103,7 +137,7 @@ def create_hf_space(token, space_name, app_code):
|
|
| 103 |
gr.Error(f"β Error creating space: {str(e)}")
|
| 104 |
|
| 105 |
|
| 106 |
-
def launch_mcp_server(openapi_spec_url, api_base_url, paths, methods, space_name_box, oauth_token: gr.OAuthToken | None):
|
| 107 |
if oauth_token:
|
| 108 |
if not paths:
|
| 109 |
paths = None
|
|
@@ -116,7 +150,8 @@ def launch_mcp_server(openapi_spec_url, api_base_url, paths, methods, space_name
|
|
| 116 |
openapi_spec_url,
|
| 117 |
api_base_url,
|
| 118 |
paths,
|
| 119 |
-
methods
|
|
|
|
| 120 |
)
|
| 121 |
)
|
| 122 |
else:
|
|
@@ -131,8 +166,10 @@ with gr.Blocks(theme="ocean") as demo:
|
|
| 131 |
with gr.Column():
|
| 132 |
openapi_spec_url = gr.Textbox(label="OpenAPI Spec URL", value="https://petstore3.swagger.io/api/v3/openapi.json")
|
| 133 |
api_base_url = gr.Textbox(label="API Base URL", value="https://petstore3.swagger.io/api/v3/")
|
| 134 |
-
paths = gr.Textbox(label="Optional regex to filter paths by", placeholder=".*user.*")
|
| 135 |
methods = gr.CheckboxGroup(label="Methods", choices=["GET", "POST", "PUT", "DELETE"], value=["GET", "POST", "PUT", "DELETE"])
|
|
|
|
|
|
|
|
|
|
| 136 |
find_endpoints_button = gr.Button("π Find Endpoints")
|
| 137 |
with gr.Column():
|
| 138 |
endpoints = gr.JSON(label="π endpoints found", value=[], max_height=400)
|
|
@@ -159,7 +196,7 @@ with gr.Blocks(theme="ocean") as demo:
|
|
| 159 |
gr.on(
|
| 160 |
[launch_button.click],
|
| 161 |
launch_mcp_server,
|
| 162 |
-
inputs=[openapi_spec_url, api_base_url, paths, methods, space_name_box],
|
| 163 |
outputs=None
|
| 164 |
)
|
| 165 |
|
|
|
|
| 58 |
base_url=\"{}\",
|
| 59 |
paths={},
|
| 60 |
methods={},
|
| 61 |
+
auth_token=\"{}\"
|
| 62 |
).launch(mcp_server=True)
|
| 63 |
"""
|
| 64 |
|
| 65 |
+
readme_code = """
|
| 66 |
+
---
|
| 67 |
+
title: OpenAPI MCP Server
|
| 68 |
+
sdk: gradio
|
| 69 |
+
sdk_version: 5.38.2
|
| 70 |
+
app_file: app.py
|
| 71 |
+
pinned: false
|
| 72 |
+
tags:
|
| 73 |
+
- openapi2mcp
|
| 74 |
+
---
|
| 75 |
+
|
| 76 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
| 77 |
+
"""
|
| 78 |
+
|
| 79 |
+
requirements_code = """
|
| 80 |
+
https://gradio-pypi-previews.s3.amazonaws.com/86331cf36187d17a6d3ce26b01f28ea8dd5cbe35/gradio-5.38.2-py3-none-any.whl
|
| 81 |
+
"""
|
| 82 |
+
|
| 83 |
def create_hf_space(token, space_name, app_code):
|
| 84 |
"""
|
| 85 |
Create a new Hugging Face Space with optional app.py file
|
|
|
|
| 114 |
repo_type="space",
|
| 115 |
commit_message="Add app.py"
|
| 116 |
)
|
| 117 |
+
api.upload_file(
|
| 118 |
+
path_or_fileobj=readme_code.encode('utf-8'),
|
| 119 |
+
path_in_repo="README.md",
|
| 120 |
+
repo_id=space_id,
|
| 121 |
+
repo_type="space",
|
| 122 |
+
commit_message="Add README.md"
|
| 123 |
+
)
|
| 124 |
+
api.upload_file(
|
| 125 |
+
path_or_fileobj=requirements_code.encode('utf-8'),
|
| 126 |
+
path_in_repo="requirements.txt",
|
| 127 |
+
repo_id=space_id,
|
| 128 |
+
repo_type="space",
|
| 129 |
+
commit_message="Add requirements.txt"
|
| 130 |
+
)
|
| 131 |
+
|
| 132 |
space_url = f"https://huggingface.co/spaces/{space_id}"
|
| 133 |
gr.Success(f"π Your space will be available at: <a href='{space_url}' target='_blank'>{space_url} ‴</a>", duration=None)
|
| 134 |
return space_info
|
|
|
|
| 137 |
gr.Error(f"β Error creating space: {str(e)}")
|
| 138 |
|
| 139 |
|
| 140 |
+
def launch_mcp_server(openapi_spec_url, api_base_url, paths, methods, auth_token, space_name_box, oauth_token: gr.OAuthToken | None):
|
| 141 |
if oauth_token:
|
| 142 |
if not paths:
|
| 143 |
paths = None
|
|
|
|
| 150 |
openapi_spec_url,
|
| 151 |
api_base_url,
|
| 152 |
paths,
|
| 153 |
+
methods,
|
| 154 |
+
auth_token
|
| 155 |
)
|
| 156 |
)
|
| 157 |
else:
|
|
|
|
| 166 |
with gr.Column():
|
| 167 |
openapi_spec_url = gr.Textbox(label="OpenAPI Spec URL", value="https://petstore3.swagger.io/api/v3/openapi.json")
|
| 168 |
api_base_url = gr.Textbox(label="API Base URL", value="https://petstore3.swagger.io/api/v3/")
|
|
|
|
| 169 |
methods = gr.CheckboxGroup(label="Methods", choices=["GET", "POST", "PUT", "DELETE"], value=["GET", "POST", "PUT", "DELETE"])
|
| 170 |
+
with gr.Accordion("Optional Settings", open=False):
|
| 171 |
+
paths = gr.Textbox(label="Regex to filter paths by", placeholder=".*user.*", info="Only include API endpoints that match this regex")
|
| 172 |
+
auth_token = gr.Textbox(label="Auth token to include in API requests", info="This will be sent to the API endpoints as a Bearer token")
|
| 173 |
find_endpoints_button = gr.Button("π Find Endpoints")
|
| 174 |
with gr.Column():
|
| 175 |
endpoints = gr.JSON(label="π endpoints found", value=[], max_height=400)
|
|
|
|
| 196 |
gr.on(
|
| 197 |
[launch_button.click],
|
| 198 |
launch_mcp_server,
|
| 199 |
+
inputs=[openapi_spec_url, api_base_url, paths, methods, auth_token, space_name_box],
|
| 200 |
outputs=None
|
| 201 |
)
|
| 202 |
|