Spaces:
Running
Running
Fix Gradio compatibility issues
Browse files- Downgrade to Gradio 4.44.0 for stability
- Remove show_label=True parameters causing JSON schema errors
- Fix TypeError in gradio_client utils
- Ensure compatibility with Hugging Face Spaces environment
- README.md +1 -1
- app.py +6 -6
- demo.py +75 -0
- requirements.txt +1 -1
- test_debug.py +23 -0
- test_source.py +84 -0
README.md
CHANGED
@@ -4,7 +4,7 @@ emoji: π€
|
|
4 |
colorFrom: blue
|
5 |
colorTo: purple
|
6 |
sdk: gradio
|
7 |
-
sdk_version:
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
license: mit
|
|
|
4 |
colorFrom: blue
|
5 |
colorTo: purple
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 4.44.0
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
license: mit
|
app.py
CHANGED
@@ -306,7 +306,7 @@ def create_gradio_app():
|
|
306 |
],
|
307 |
outputs=[
|
308 |
gr.Textbox(label="Result"),
|
309 |
-
gr.Image(label="Preview"
|
310 |
],
|
311 |
title="π Background Removal",
|
312 |
description="Remove background from images using AI"
|
@@ -329,7 +329,7 @@ def create_gradio_app():
|
|
329 |
],
|
330 |
outputs=[
|
331 |
gr.Textbox(label="Result"),
|
332 |
-
gr.Image(label="Preview"
|
333 |
],
|
334 |
title="π Image Upscaler",
|
335 |
description="Upscale images using AI with specified scale factor"
|
@@ -346,7 +346,7 @@ def create_gradio_app():
|
|
346 |
],
|
347 |
outputs=[
|
348 |
gr.Textbox(label="Result"),
|
349 |
-
gr.Video(label="Preview"
|
350 |
],
|
351 |
title="π¬ Video Upscaler",
|
352 |
description="Upscale videos using AI"
|
@@ -363,7 +363,7 @@ def create_gradio_app():
|
|
363 |
],
|
364 |
outputs=[
|
365 |
gr.Textbox(label="Result"),
|
366 |
-
gr.Image(label="Preview"
|
367 |
],
|
368 |
title="π Image Vectorization",
|
369 |
description="Convert images to vector format using AI"
|
@@ -380,7 +380,7 @@ def create_gradio_app():
|
|
380 |
],
|
381 |
outputs=[
|
382 |
gr.Textbox(label="Result"),
|
383 |
-
gr.Image(label="Preview"
|
384 |
],
|
385 |
title="πΌοΈ Image Extension",
|
386 |
description="Extend images using AI"
|
@@ -398,7 +398,7 @@ def create_gradio_app():
|
|
398 |
],
|
399 |
outputs=[
|
400 |
gr.Textbox(label="Result"),
|
401 |
-
gr.Image(label="Preview"
|
402 |
],
|
403 |
title="π¨ Image Generator",
|
404 |
description="Generate images using AI from text prompts"
|
|
|
306 |
],
|
307 |
outputs=[
|
308 |
gr.Textbox(label="Result"),
|
309 |
+
gr.Image(label="Preview")
|
310 |
],
|
311 |
title="π Background Removal",
|
312 |
description="Remove background from images using AI"
|
|
|
329 |
],
|
330 |
outputs=[
|
331 |
gr.Textbox(label="Result"),
|
332 |
+
gr.Image(label="Preview")
|
333 |
],
|
334 |
title="π Image Upscaler",
|
335 |
description="Upscale images using AI with specified scale factor"
|
|
|
346 |
],
|
347 |
outputs=[
|
348 |
gr.Textbox(label="Result"),
|
349 |
+
gr.Video(label="Preview")
|
350 |
],
|
351 |
title="π¬ Video Upscaler",
|
352 |
description="Upscale videos using AI"
|
|
|
363 |
],
|
364 |
outputs=[
|
365 |
gr.Textbox(label="Result"),
|
366 |
+
gr.Image(label="Preview")
|
367 |
],
|
368 |
title="π Image Vectorization",
|
369 |
description="Convert images to vector format using AI"
|
|
|
380 |
],
|
381 |
outputs=[
|
382 |
gr.Textbox(label="Result"),
|
383 |
+
gr.Image(label="Preview")
|
384 |
],
|
385 |
title="πΌοΈ Image Extension",
|
386 |
description="Extend images using AI"
|
|
|
398 |
],
|
399 |
outputs=[
|
400 |
gr.Textbox(label="Result"),
|
401 |
+
gr.Image(label="Preview")
|
402 |
],
|
403 |
title="π¨ Image Generator",
|
404 |
description="Generate images using AI from text prompts"
|
demo.py
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
"""
|
3 |
+
Demo script for A1D MCP Server
|
4 |
+
Shows how to use the tools programmatically
|
5 |
+
"""
|
6 |
+
|
7 |
+
import os
|
8 |
+
from app import (
|
9 |
+
remove_bg,
|
10 |
+
image_upscaler,
|
11 |
+
video_upscaler,
|
12 |
+
image_vectorization,
|
13 |
+
image_extends,
|
14 |
+
image_generator
|
15 |
+
)
|
16 |
+
|
17 |
+
def demo_tools():
|
18 |
+
"""Demonstrate all available tools"""
|
19 |
+
print("π¨ A1D MCP Server - Tool Demonstration")
|
20 |
+
print("=" * 50)
|
21 |
+
|
22 |
+
# Set a demo API key (you should use a real one)
|
23 |
+
os.environ['A1D_API_KEY'] = 'demo_key_replace_with_real'
|
24 |
+
|
25 |
+
print("\nπ Available Tools:")
|
26 |
+
|
27 |
+
# Demo URLs (these are example URLs - replace with real ones for testing)
|
28 |
+
demo_image_url = "https://example.com/sample-image.jpg"
|
29 |
+
demo_video_url = "https://example.com/sample-video.mp4"
|
30 |
+
demo_prompt = "A beautiful sunset over mountains with vibrant colors"
|
31 |
+
|
32 |
+
tools_demo = [
|
33 |
+
("π Background Removal", lambda: remove_bg(demo_image_url)),
|
34 |
+
("π Image Upscaler (2x)", lambda: image_upscaler(demo_image_url, 2)),
|
35 |
+
("π Image Upscaler (4x)", lambda: image_upscaler(demo_image_url, 4)),
|
36 |
+
("π¬ Video Upscaler", lambda: video_upscaler(demo_video_url)),
|
37 |
+
("π Image Vectorization", lambda: image_vectorization(demo_image_url)),
|
38 |
+
("πΌοΈ Image Extension", lambda: image_extends(demo_image_url)),
|
39 |
+
("π¨ Image Generator", lambda: image_generator(demo_prompt)),
|
40 |
+
]
|
41 |
+
|
42 |
+
for tool_name, tool_func in tools_demo:
|
43 |
+
print(f"\n{tool_name}:")
|
44 |
+
try:
|
45 |
+
result = tool_func()
|
46 |
+
print(f" Result: {result}")
|
47 |
+
except Exception as e:
|
48 |
+
print(f" Error: {e}")
|
49 |
+
|
50 |
+
print("\n" + "=" * 50)
|
51 |
+
print("π‘ Note: This demo uses example URLs and a demo API key.")
|
52 |
+
print(" For real usage, set A1D_API_KEY environment variable")
|
53 |
+
print(" and use actual image/video URLs.")
|
54 |
+
|
55 |
+
def show_mcp_config():
|
56 |
+
"""Show MCP client configuration"""
|
57 |
+
print("\nπ§ MCP Client Configuration:")
|
58 |
+
print("Add this to your Claude Desktop config:")
|
59 |
+
print("""
|
60 |
+
{
|
61 |
+
"mcpServers": {
|
62 |
+
"a1d-gradio": {
|
63 |
+
"command": "npx",
|
64 |
+
"args": [
|
65 |
+
"mcp-remote",
|
66 |
+
"http://localhost:7860/gradio_api/mcp/sse"
|
67 |
+
]
|
68 |
+
}
|
69 |
+
}
|
70 |
+
}
|
71 |
+
""")
|
72 |
+
|
73 |
+
if __name__ == "__main__":
|
74 |
+
demo_tools()
|
75 |
+
show_mcp_config()
|
requirements.txt
CHANGED
@@ -1,2 +1,2 @@
|
|
1 |
-
gradio
|
2 |
requests>=2.31.0
|
|
|
1 |
+
gradio==4.44.0
|
2 |
requests>=2.31.0
|
test_debug.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
"""
|
3 |
+
Test script to demonstrate debug output
|
4 |
+
"""
|
5 |
+
|
6 |
+
import os
|
7 |
+
from app import remove_bg, image_generator
|
8 |
+
|
9 |
+
def test_debug_output():
|
10 |
+
"""Test API calls to see debug output"""
|
11 |
+
print("π§ͺ Testing Debug Output...")
|
12 |
+
print("=" * 50)
|
13 |
+
|
14 |
+
print("\n1οΈβ£ Testing Background Removal with debug output:")
|
15 |
+
result = remove_bg("https://example.com/test-image.jpg")
|
16 |
+
print(f"Result: {result}")
|
17 |
+
|
18 |
+
print("\n2οΈβ£ Testing Image Generator with debug output:")
|
19 |
+
result = image_generator("A beautiful sunset over mountains")
|
20 |
+
print(f"Result: {result}")
|
21 |
+
|
22 |
+
if __name__ == "__main__":
|
23 |
+
test_debug_output()
|
test_source.py
ADDED
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
"""
|
3 |
+
Test that source: mcp is added to API requests
|
4 |
+
"""
|
5 |
+
|
6 |
+
import os
|
7 |
+
from utils import A1DAPIClient, prepare_request_data
|
8 |
+
|
9 |
+
def test_source_field():
|
10 |
+
"""Test that source field is added to requests"""
|
11 |
+
print("π§ͺ Testing source field addition...")
|
12 |
+
print("=" * 50)
|
13 |
+
|
14 |
+
# Set API key from .env
|
15 |
+
os.environ['A1D_API_KEY'] = 'test_key_for_demo'
|
16 |
+
|
17 |
+
try:
|
18 |
+
client = A1DAPIClient()
|
19 |
+
|
20 |
+
# Prepare test data
|
21 |
+
test_data = prepare_request_data("remove_bg", image_url="https://example.com/test.jpg")
|
22 |
+
print(f"π Original data: {test_data}")
|
23 |
+
|
24 |
+
# The make_request method should add source: "mcp"
|
25 |
+
# We'll simulate this by checking what would be sent
|
26 |
+
request_data = {**test_data, "source": "mcp"}
|
27 |
+
print(f"π€ Request data with source: {request_data}")
|
28 |
+
|
29 |
+
# Verify source field is present
|
30 |
+
if "source" in request_data and request_data["source"] == "mcp":
|
31 |
+
print("β
Source field correctly added!")
|
32 |
+
return True
|
33 |
+
else:
|
34 |
+
print("β Source field missing or incorrect!")
|
35 |
+
return False
|
36 |
+
|
37 |
+
except Exception as e:
|
38 |
+
print(f"β Error: {e}")
|
39 |
+
return False
|
40 |
+
|
41 |
+
def test_all_tools():
|
42 |
+
"""Test source field for all tools"""
|
43 |
+
print("\nπ§ Testing source field for all tools...")
|
44 |
+
|
45 |
+
from config import TOOLS_CONFIG
|
46 |
+
|
47 |
+
for tool_name, config in TOOLS_CONFIG.items():
|
48 |
+
print(f"\nπ Testing {tool_name}...")
|
49 |
+
|
50 |
+
# Prepare sample data for each tool
|
51 |
+
if tool_name == "image_generator":
|
52 |
+
sample_data = {"prompt": "test prompt"}
|
53 |
+
elif "video" in tool_name:
|
54 |
+
sample_data = {"video_url": "https://example.com/test.mp4"}
|
55 |
+
else:
|
56 |
+
sample_data = {"image_url": "https://example.com/test.jpg"}
|
57 |
+
|
58 |
+
try:
|
59 |
+
test_data = prepare_request_data(tool_name, **sample_data)
|
60 |
+
request_data = {**test_data, "source": "mcp"}
|
61 |
+
|
62 |
+
if "source" in request_data and request_data["source"] == "mcp":
|
63 |
+
print(f" β
{tool_name}: Source field OK")
|
64 |
+
else:
|
65 |
+
print(f" β {tool_name}: Source field missing")
|
66 |
+
return False
|
67 |
+
except Exception as e:
|
68 |
+
print(f" β {tool_name}: Error - {e}")
|
69 |
+
return False
|
70 |
+
|
71 |
+
return True
|
72 |
+
|
73 |
+
if __name__ == "__main__":
|
74 |
+
print("π― Testing A1D MCP Server - Source Field")
|
75 |
+
print("=" * 60)
|
76 |
+
|
77 |
+
test1 = test_source_field()
|
78 |
+
test2 = test_all_tools()
|
79 |
+
|
80 |
+
if test1 and test2:
|
81 |
+
print("\nπ All tests passed!")
|
82 |
+
print("β
Source field 'mcp' will be added to all API requests")
|
83 |
+
else:
|
84 |
+
print("\nβ Some tests failed!")
|