Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -56,7 +56,7 @@ import gradio as gr
|
|
56 |
gr.load_openapi(
|
57 |
openapi_spec=\"{}\",
|
58 |
base_url=\"{}\",
|
59 |
-
paths
|
60 |
methods={},
|
61 |
).launch(mcp_server=True)
|
62 |
"""
|
@@ -81,7 +81,7 @@ def create_hf_space(token, space_name, app_code):
|
|
81 |
space_id = f"{username}/{space_name}"
|
82 |
|
83 |
try:
|
84 |
-
gr.Info(f"Creating space {space_id}...")
|
85 |
space_info = api.create_repo(
|
86 |
repo_id=space_id,
|
87 |
repo_type="space",
|
@@ -96,7 +96,7 @@ def create_hf_space(token, space_name, app_code):
|
|
96 |
commit_message="Add app.py"
|
97 |
)
|
98 |
space_url = f"https://huggingface.co/spaces/{space_id}"
|
99 |
-
gr.Success(f"π Your space
|
100 |
return space_info
|
101 |
|
102 |
except Exception as e:
|
@@ -105,13 +105,17 @@ def create_hf_space(token, space_name, app_code):
|
|
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 |
create_hf_space(
|
109 |
oauth_token.token,
|
110 |
space_name_box,
|
111 |
gradio_app_code.format(
|
112 |
openapi_spec_url,
|
113 |
api_base_url,
|
114 |
-
paths
|
115 |
methods
|
116 |
)
|
117 |
)
|
@@ -127,7 +131,7 @@ with gr.Blocks(theme="ocean") as demo:
|
|
127 |
with gr.Column():
|
128 |
openapi_spec_url = gr.Textbox(label="OpenAPI Spec URL", value="https://petstore3.swagger.io/api/v3/openapi.json")
|
129 |
api_base_url = gr.Textbox(label="API Base URL", value="https://petstore3.swagger.io/api/v3/")
|
130 |
-
paths = gr.Textbox(label="Optional
|
131 |
methods = gr.CheckboxGroup(label="Methods", choices=["GET", "POST", "PUT", "DELETE"], value=["GET", "POST", "PUT", "DELETE"])
|
132 |
find_endpoints_button = gr.Button("π Find Endpoints")
|
133 |
with gr.Column():
|
|
|
56 |
gr.load_openapi(
|
57 |
openapi_spec=\"{}\",
|
58 |
base_url=\"{}\",
|
59 |
+
paths={},
|
60 |
methods={},
|
61 |
).launch(mcp_server=True)
|
62 |
"""
|
|
|
81 |
space_id = f"{username}/{space_name}"
|
82 |
|
83 |
try:
|
84 |
+
gr.Info(f"Creating space {space_id}...", duration=20)
|
85 |
space_info = api.create_repo(
|
86 |
repo_id=space_id,
|
87 |
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
|
101 |
|
102 |
except Exception as e:
|
|
|
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
|
110 |
+
else:
|
111 |
+
paths = f"[\"{paths}\"]"
|
112 |
create_hf_space(
|
113 |
oauth_token.token,
|
114 |
space_name_box,
|
115 |
gradio_app_code.format(
|
116 |
openapi_spec_url,
|
117 |
api_base_url,
|
118 |
+
paths,
|
119 |
methods
|
120 |
)
|
121 |
)
|
|
|
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():
|