Spaces:
Sleeping
Sleeping
Commit
·
b6bbe57
1
Parent(s):
acef901
Create minimal reproduction case to isolate Gradio schema error
Browse files- Temporarily disable heavy ML dependencies (transformers, torch, cv2)
- Replace complex processing with mock data for testing
- Remove show_progress parameter from click handler
- Add minimal test app for debugging
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
- app.py +21 -71
- test_minimal.py +23 -0
app.py
CHANGED
@@ -3,8 +3,8 @@ import json
|
|
3 |
import os
|
4 |
from PIL import Image
|
5 |
import tempfile
|
6 |
-
from utils.extractor import DesignTokenExtractor
|
7 |
-
from utils.token_generator import TokenCodeGenerator
|
8 |
|
9 |
|
10 |
def create_token_preview(tokens):
|
@@ -90,82 +90,33 @@ def process_screenshot(image, output_format, progress=None):
|
|
90 |
if image is None:
|
91 |
return None, "Please upload a screenshot", None
|
92 |
|
93 |
-
|
94 |
-
generator = TokenCodeGenerator()
|
95 |
-
|
96 |
try:
|
97 |
-
|
98 |
-
progress(0.1, desc="Initializing extraction...")
|
99 |
-
|
100 |
-
# Resize image if needed
|
101 |
-
image = extractor.resize_for_processing(image)
|
102 |
-
|
103 |
-
# Save temporary file for colorgram
|
104 |
-
with tempfile.NamedTemporaryFile(suffix='.png', delete=False) as tmp:
|
105 |
-
temp_path = tmp.name
|
106 |
-
image.save(temp_path)
|
107 |
-
|
108 |
-
if progress:
|
109 |
-
progress(0.3, desc="Extracting colors...")
|
110 |
-
colors = extractor.extract_colors(temp_path)
|
111 |
-
|
112 |
-
if progress:
|
113 |
-
progress(0.5, desc="Detecting spacing...")
|
114 |
-
spacing = extractor.detect_spacing(image)
|
115 |
-
|
116 |
-
if progress:
|
117 |
-
progress(0.6, desc="Analyzing typography...")
|
118 |
-
typography = extractor.detect_typography(image)
|
119 |
-
|
120 |
-
if progress:
|
121 |
-
progress(0.7, desc="Analyzing components...")
|
122 |
-
components = extractor.analyze_components(image)
|
123 |
-
|
124 |
-
# Combine all tokens
|
125 |
tokens = {
|
126 |
-
"colors":
|
127 |
-
|
128 |
-
|
129 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
}
|
131 |
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
# Generate output based on selected format
|
136 |
-
if output_format == "CSS Variables":
|
137 |
-
code_output = generator.generate_css_variables(tokens)
|
138 |
-
file_ext = "css"
|
139 |
-
elif output_format == "Tailwind Config":
|
140 |
-
code_output = generator.generate_tailwind_config(tokens)
|
141 |
-
file_ext = "js"
|
142 |
-
elif output_format == "JSON Tokens":
|
143 |
-
code_output = generator.generate_json_tokens(tokens)
|
144 |
-
file_ext = "json"
|
145 |
-
elif output_format == "Style Dictionary":
|
146 |
-
code_output = generator.generate_style_dictionary(tokens)
|
147 |
-
file_ext = "json"
|
148 |
-
elif output_format == "SCSS Variables":
|
149 |
-
code_output = generator.generate_scss_variables(tokens)
|
150 |
-
file_ext = "scss"
|
151 |
-
else:
|
152 |
-
code_output = json.dumps(tokens, indent=2)
|
153 |
-
file_ext = "json"
|
154 |
|
155 |
# Save output file
|
156 |
-
output_filename =
|
157 |
with open(output_filename, "w") as f:
|
158 |
f.write(code_output)
|
159 |
|
160 |
-
# Clean up temp file
|
161 |
-
try:
|
162 |
-
os.unlink(temp_path)
|
163 |
-
except:
|
164 |
-
pass
|
165 |
-
|
166 |
-
if progress:
|
167 |
-
progress(1.0, desc="Complete!")
|
168 |
-
|
169 |
# Create preview visualization
|
170 |
preview_html = create_token_preview(tokens)
|
171 |
|
@@ -273,8 +224,7 @@ def create_gradio_app():
|
|
273 |
extract_btn.click(
|
274 |
fn=process_screenshot,
|
275 |
inputs=[input_image, output_format],
|
276 |
-
outputs=[preview, code_output, download_file]
|
277 |
-
show_progress=True
|
278 |
)
|
279 |
|
280 |
# Add footer
|
|
|
3 |
import os
|
4 |
from PIL import Image
|
5 |
import tempfile
|
6 |
+
# from utils.extractor import DesignTokenExtractor
|
7 |
+
# from utils.token_generator import TokenCodeGenerator
|
8 |
|
9 |
|
10 |
def create_token_preview(tokens):
|
|
|
90 |
if image is None:
|
91 |
return None, "Please upload a screenshot", None
|
92 |
|
93 |
+
# Temporary stub implementation for testing
|
|
|
|
|
94 |
try:
|
95 |
+
# Mock tokens for testing
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
tokens = {
|
97 |
+
"colors": {
|
98 |
+
"primary": {"hex": "#3B82F6", "rgb": "rgb(59, 130, 246)", "proportion": 0.25},
|
99 |
+
"secondary": {"hex": "#8B5CF6", "rgb": "rgb(139, 92, 246)", "proportion": 0.15}
|
100 |
+
},
|
101 |
+
"spacing": {
|
102 |
+
"small": "8px",
|
103 |
+
"medium": "16px",
|
104 |
+
"large": "32px"
|
105 |
+
},
|
106 |
+
"typography": {
|
107 |
+
"heading": {"family": "sans-serif", "size": "32px", "weight": "700"},
|
108 |
+
"body": {"family": "sans-serif", "size": "16px", "weight": "400"}
|
109 |
+
}
|
110 |
}
|
111 |
|
112 |
+
# Simple CSS output for testing
|
113 |
+
code_output = ":root {\n --color-primary: #3B82F6;\n --color-secondary: #8B5CF6;\n --spacing-small: 8px;\n --spacing-medium: 16px;\n --spacing-large: 32px;\n}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
|
115 |
# Save output file
|
116 |
+
output_filename = "design_tokens.css"
|
117 |
with open(output_filename, "w") as f:
|
118 |
f.write(code_output)
|
119 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
# Create preview visualization
|
121 |
preview_html = create_token_preview(tokens)
|
122 |
|
|
|
224 |
extract_btn.click(
|
225 |
fn=process_screenshot,
|
226 |
inputs=[input_image, output_format],
|
227 |
+
outputs=[preview, code_output, download_file]
|
|
|
228 |
)
|
229 |
|
230 |
# Add footer
|
test_minimal.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
def simple_function(text):
|
4 |
+
return f"You entered: {text}"
|
5 |
+
|
6 |
+
# Create a minimal Gradio app
|
7 |
+
with gr.Blocks() as app:
|
8 |
+
gr.Markdown("# Minimal Test App")
|
9 |
+
|
10 |
+
with gr.Row():
|
11 |
+
input_text = gr.Textbox(label="Enter text")
|
12 |
+
output_text = gr.Textbox(label="Output")
|
13 |
+
|
14 |
+
submit_btn = gr.Button("Submit")
|
15 |
+
|
16 |
+
submit_btn.click(
|
17 |
+
fn=simple_function,
|
18 |
+
inputs=[input_text],
|
19 |
+
outputs=[output_text]
|
20 |
+
)
|
21 |
+
|
22 |
+
if __name__ == "__main__":
|
23 |
+
app.launch(server_name="0.0.0.0", server_port=7861)
|