Spaces:
Running
Running
Create simple Gradio app to fix JSON schema issues
Browse files- Add simple_app.py with minimal Gradio interface
- Downgrade to Gradio 4.32.0 for better stability
- Use basic components to avoid complex type inference
- Focus on core functionality: background removal, upscaling, generation
- Update README.md to use simple_app.py as main app file
- README.md +2 -2
- requirements.txt +1 -1
- simple_app.py +182 -0
README.md
CHANGED
|
@@ -4,8 +4,8 @@ emoji: π€
|
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version: 4.
|
| 8 |
-
app_file:
|
| 9 |
pinned: false
|
| 10 |
license: mit
|
| 11 |
tags:
|
|
|
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 4.32.0
|
| 8 |
+
app_file: simple_app.py
|
| 9 |
pinned: false
|
| 10 |
license: mit
|
| 11 |
tags:
|
requirements.txt
CHANGED
|
@@ -1,2 +1,2 @@
|
|
| 1 |
-
gradio==4.
|
| 2 |
requests>=2.31.0
|
|
|
|
| 1 |
+
gradio==4.32.0
|
| 2 |
requests>=2.31.0
|
simple_app.py
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Simple A1D MCP Server with Gradio - Minimal version to avoid type inference issues
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import gradio as gr
|
| 7 |
+
import os
|
| 8 |
+
from utils import A1DAPIClient, prepare_request_data, format_response_with_preview
|
| 9 |
+
from config import TOOLS_CONFIG
|
| 10 |
+
|
| 11 |
+
def get_api_client():
|
| 12 |
+
"""Get API client with current API key"""
|
| 13 |
+
api_key = os.getenv("A1D_API_KEY")
|
| 14 |
+
if not api_key:
|
| 15 |
+
raise ValueError("A1D_API_KEY environment variable is required")
|
| 16 |
+
return A1DAPIClient(api_key)
|
| 17 |
+
|
| 18 |
+
def remove_bg_simple(image_url):
|
| 19 |
+
"""Remove background from images using AI"""
|
| 20 |
+
try:
|
| 21 |
+
if not image_url or not image_url.strip():
|
| 22 |
+
return "β Error: Please provide an image URL", None
|
| 23 |
+
|
| 24 |
+
client = get_api_client()
|
| 25 |
+
data = prepare_request_data("remove_bg", image_url=image_url)
|
| 26 |
+
response = client.make_request_with_result(
|
| 27 |
+
TOOLS_CONFIG["remove_bg"]["api_endpoint"],
|
| 28 |
+
data,
|
| 29 |
+
timeout=120
|
| 30 |
+
)
|
| 31 |
+
message, media_url = format_response_with_preview(response, "remove_bg")
|
| 32 |
+
return message, media_url
|
| 33 |
+
except Exception as e:
|
| 34 |
+
return f"β Error: {str(e)}", None
|
| 35 |
+
|
| 36 |
+
def image_upscaler_simple(image_url, scale):
|
| 37 |
+
"""Upscale images using AI"""
|
| 38 |
+
try:
|
| 39 |
+
if not image_url or not image_url.strip():
|
| 40 |
+
return "β Error: Please provide an image URL", None
|
| 41 |
+
|
| 42 |
+
client = get_api_client()
|
| 43 |
+
data = prepare_request_data("image_upscaler", image_url=image_url, scale=scale)
|
| 44 |
+
response = client.make_request_with_result(
|
| 45 |
+
TOOLS_CONFIG["image_upscaler"]["api_endpoint"],
|
| 46 |
+
data,
|
| 47 |
+
timeout=120
|
| 48 |
+
)
|
| 49 |
+
message, media_url = format_response_with_preview(response, "image_upscaler")
|
| 50 |
+
return message, media_url
|
| 51 |
+
except Exception as e:
|
| 52 |
+
return f"β Error: {str(e)}", None
|
| 53 |
+
|
| 54 |
+
def image_generator_simple(prompt):
|
| 55 |
+
"""Generate images using AI from text prompts"""
|
| 56 |
+
try:
|
| 57 |
+
if not prompt or not prompt.strip():
|
| 58 |
+
return "β Error: Please provide a text prompt", None
|
| 59 |
+
|
| 60 |
+
client = get_api_client()
|
| 61 |
+
data = prepare_request_data("image_generator", prompt=prompt)
|
| 62 |
+
response = client.make_request_with_result(
|
| 63 |
+
TOOLS_CONFIG["image_generator"]["api_endpoint"],
|
| 64 |
+
data,
|
| 65 |
+
timeout=120
|
| 66 |
+
)
|
| 67 |
+
message, media_url = format_response_with_preview(response, "image_generator")
|
| 68 |
+
return message, media_url
|
| 69 |
+
except Exception as e:
|
| 70 |
+
return f"β Error: {str(e)}", None
|
| 71 |
+
|
| 72 |
+
def create_simple_app():
|
| 73 |
+
"""Create a simple Gradio app"""
|
| 74 |
+
|
| 75 |
+
with gr.Blocks(title="A1D MCP Server - Universal AI Tools") as demo:
|
| 76 |
+
gr.Markdown("# π€ A1D MCP Server - Universal AI Tools")
|
| 77 |
+
gr.Markdown("Powerful AI image and video processing tools for any MCP-compatible client.")
|
| 78 |
+
|
| 79 |
+
with gr.Tab("π Background Removal"):
|
| 80 |
+
with gr.Row():
|
| 81 |
+
with gr.Column():
|
| 82 |
+
bg_input = gr.Textbox(
|
| 83 |
+
label="Image URL",
|
| 84 |
+
placeholder="https://example.com/image.jpg"
|
| 85 |
+
)
|
| 86 |
+
bg_button = gr.Button("Remove Background", variant="primary")
|
| 87 |
+
with gr.Column():
|
| 88 |
+
bg_output = gr.Textbox(label="Result")
|
| 89 |
+
bg_image = gr.Image(label="Preview")
|
| 90 |
+
|
| 91 |
+
bg_button.click(
|
| 92 |
+
fn=remove_bg_simple,
|
| 93 |
+
inputs=[bg_input],
|
| 94 |
+
outputs=[bg_output, bg_image]
|
| 95 |
+
)
|
| 96 |
+
|
| 97 |
+
with gr.Tab("π Image Upscaler"):
|
| 98 |
+
with gr.Row():
|
| 99 |
+
with gr.Column():
|
| 100 |
+
up_input = gr.Textbox(
|
| 101 |
+
label="Image URL",
|
| 102 |
+
placeholder="https://example.com/image.jpg"
|
| 103 |
+
)
|
| 104 |
+
up_scale = gr.Dropdown(
|
| 105 |
+
choices=[2, 4, 8, 16],
|
| 106 |
+
value=2,
|
| 107 |
+
label="Scale Factor"
|
| 108 |
+
)
|
| 109 |
+
up_button = gr.Button("Upscale Image", variant="primary")
|
| 110 |
+
with gr.Column():
|
| 111 |
+
up_output = gr.Textbox(label="Result")
|
| 112 |
+
up_image = gr.Image(label="Preview")
|
| 113 |
+
|
| 114 |
+
up_button.click(
|
| 115 |
+
fn=image_upscaler_simple,
|
| 116 |
+
inputs=[up_input, up_scale],
|
| 117 |
+
outputs=[up_output, up_image]
|
| 118 |
+
)
|
| 119 |
+
|
| 120 |
+
with gr.Tab("π¨ Image Generator"):
|
| 121 |
+
with gr.Row():
|
| 122 |
+
with gr.Column():
|
| 123 |
+
gen_input = gr.Textbox(
|
| 124 |
+
label="Text Prompt",
|
| 125 |
+
placeholder="A beautiful sunset over mountains...",
|
| 126 |
+
lines=3
|
| 127 |
+
)
|
| 128 |
+
gen_button = gr.Button("Generate Image", variant="primary")
|
| 129 |
+
with gr.Column():
|
| 130 |
+
gen_output = gr.Textbox(label="Result")
|
| 131 |
+
gen_image = gr.Image(label="Preview")
|
| 132 |
+
|
| 133 |
+
gen_button.click(
|
| 134 |
+
fn=image_generator_simple,
|
| 135 |
+
inputs=[gen_input],
|
| 136 |
+
outputs=[gen_output, gen_image]
|
| 137 |
+
)
|
| 138 |
+
|
| 139 |
+
gr.Markdown("""
|
| 140 |
+
## π§ MCP Client Configuration
|
| 141 |
+
|
| 142 |
+
Add this to your Claude Desktop configuration:
|
| 143 |
+
|
| 144 |
+
```json
|
| 145 |
+
{
|
| 146 |
+
"mcpServers": {
|
| 147 |
+
"a1d-hosted": {
|
| 148 |
+
"command": "npx",
|
| 149 |
+
"args": [
|
| 150 |
+
"mcp-remote@latest",
|
| 151 |
+
"https://aigchacker-a1d-mcp-server.hf.space/gradio_api/mcp/sse",
|
| 152 |
+
"--header",
|
| 153 |
+
"API_KEY:${MCP_API_KEY}"
|
| 154 |
+
],
|
| 155 |
+
"env": {
|
| 156 |
+
"MCP_API_KEY": "your_a1d_api_key_here"
|
| 157 |
+
}
|
| 158 |
+
}
|
| 159 |
+
}
|
| 160 |
+
}
|
| 161 |
+
```
|
| 162 |
+
""")
|
| 163 |
+
|
| 164 |
+
return demo
|
| 165 |
+
|
| 166 |
+
if __name__ == "__main__":
|
| 167 |
+
# Check for API key
|
| 168 |
+
if not os.getenv("A1D_API_KEY"):
|
| 169 |
+
print("β Error: A1D_API_KEY environment variable is required")
|
| 170 |
+
print("Please set your API key in the Space settings")
|
| 171 |
+
exit(1)
|
| 172 |
+
|
| 173 |
+
print("π Starting A1D MCP Server (Simple Version)...")
|
| 174 |
+
print("β
API key found")
|
| 175 |
+
|
| 176 |
+
# Create and launch the app
|
| 177 |
+
demo = create_simple_app()
|
| 178 |
+
demo.launch(
|
| 179 |
+
server_name="0.0.0.0",
|
| 180 |
+
server_port=7860,
|
| 181 |
+
share=False
|
| 182 |
+
)
|