Spaces:
Sleeping
Sleeping
Commit
·
c32acb1
1
Parent(s):
d79f4cf
Fix Gradio Progress parameter causing TypeError
Browse files- Changed progress parameter from gr.Progress() default to None
- Added conditional checks before calling progress methods
- Added show_progress=True to button click handler
- Resolves schema type error during API info generation
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
app.py
CHANGED
@@ -85,7 +85,7 @@ def create_token_preview(tokens):
|
|
85 |
return html
|
86 |
|
87 |
|
88 |
-
def process_screenshot(image, output_format, progress=
|
89 |
"""Process uploaded screenshot and extract design tokens"""
|
90 |
if image is None:
|
91 |
return None, "Please upload a screenshot", None
|
@@ -94,7 +94,8 @@ def process_screenshot(image, output_format, progress=gr.Progress()):
|
|
94 |
generator = TokenCodeGenerator()
|
95 |
|
96 |
try:
|
97 |
-
progress
|
|
|
98 |
|
99 |
# Resize image if needed
|
100 |
image = extractor.resize_for_processing(image)
|
@@ -104,16 +105,20 @@ def process_screenshot(image, output_format, progress=gr.Progress()):
|
|
104 |
temp_path = tmp.name
|
105 |
image.save(temp_path)
|
106 |
|
107 |
-
progress
|
|
|
108 |
colors = extractor.extract_colors(temp_path)
|
109 |
|
110 |
-
progress
|
|
|
111 |
spacing = extractor.detect_spacing(image)
|
112 |
|
113 |
-
progress
|
|
|
114 |
typography = extractor.detect_typography(image)
|
115 |
|
116 |
-
progress
|
|
|
117 |
components = extractor.analyze_components(image)
|
118 |
|
119 |
# Combine all tokens
|
@@ -124,7 +129,8 @@ def process_screenshot(image, output_format, progress=gr.Progress()):
|
|
124 |
"components": components
|
125 |
}
|
126 |
|
127 |
-
progress
|
|
|
128 |
|
129 |
# Generate output based on selected format
|
130 |
if output_format == "CSS Variables":
|
@@ -157,7 +163,8 @@ def process_screenshot(image, output_format, progress=gr.Progress()):
|
|
157 |
except:
|
158 |
pass
|
159 |
|
160 |
-
progress
|
|
|
161 |
|
162 |
# Create preview visualization
|
163 |
preview_html = create_token_preview(tokens)
|
@@ -266,7 +273,8 @@ def create_gradio_app():
|
|
266 |
extract_btn.click(
|
267 |
fn=process_screenshot,
|
268 |
inputs=[input_image, output_format],
|
269 |
-
outputs=[preview, code_output, download_file]
|
|
|
270 |
)
|
271 |
|
272 |
# Add footer
|
|
|
85 |
return html
|
86 |
|
87 |
|
88 |
+
def process_screenshot(image, output_format, progress=None):
|
89 |
"""Process uploaded screenshot and extract design tokens"""
|
90 |
if image is None:
|
91 |
return None, "Please upload a screenshot", None
|
|
|
94 |
generator = TokenCodeGenerator()
|
95 |
|
96 |
try:
|
97 |
+
if progress:
|
98 |
+
progress(0.1, desc="Initializing extraction...")
|
99 |
|
100 |
# Resize image if needed
|
101 |
image = extractor.resize_for_processing(image)
|
|
|
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
|
|
|
129 |
"components": components
|
130 |
}
|
131 |
|
132 |
+
if progress:
|
133 |
+
progress(0.8, desc="Generating code...")
|
134 |
|
135 |
# Generate output based on selected format
|
136 |
if output_format == "CSS Variables":
|
|
|
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)
|
|
|
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
|