Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -30,7 +30,7 @@ def extract_metadata(image):
|
|
| 30 |
negative_prompt = lines[1].strip().replace('Negative prompt:', '').strip()
|
| 31 |
metadata['prompt'] = prompt
|
| 32 |
metadata['negative_prompt'] = negative_prompt
|
| 33 |
-
|
| 34 |
for line in lines[2:]:
|
| 35 |
line = line.strip()
|
| 36 |
if line.startswith('Steps:'):
|
|
@@ -43,7 +43,8 @@ def extract_metadata(image):
|
|
| 43 |
else:
|
| 44 |
return "No supported metadata found in the image.", {}
|
| 45 |
|
| 46 |
-
|
|
|
|
| 47 |
except Exception as e:
|
| 48 |
error_message = f"Error extracting metadata: {str(e)}\n{traceback.format_exc()}"
|
| 49 |
return error_message, {}
|
|
@@ -66,13 +67,13 @@ with gr.Blocks() as demo:
|
|
| 66 |
|
| 67 |
with gr.Column():
|
| 68 |
status_output = gr.Textbox(label="Status")
|
| 69 |
-
output_metadata = gr.JSON(label="Metadata")
|
| 70 |
|
| 71 |
input_image.change(
|
| 72 |
fn=process_image,
|
| 73 |
inputs=input_image,
|
| 74 |
outputs=[status_output, output_metadata],
|
| 75 |
-
api_name
|
| 76 |
)
|
| 77 |
|
| 78 |
gr.Examples(
|
|
@@ -88,4 +89,4 @@ with gr.Blocks() as demo:
|
|
| 88 |
cache_examples=True,
|
| 89 |
)
|
| 90 |
|
| 91 |
-
demo.launch()
|
|
|
|
| 30 |
negative_prompt = lines[1].strip().replace('Negative prompt:', '').strip()
|
| 31 |
metadata['prompt'] = prompt
|
| 32 |
metadata['negative_prompt'] = negative_prompt
|
| 33 |
+
|
| 34 |
for line in lines[2:]:
|
| 35 |
line = line.strip()
|
| 36 |
if line.startswith('Steps:'):
|
|
|
|
| 43 |
else:
|
| 44 |
return "No supported metadata found in the image.", {}
|
| 45 |
|
| 46 |
+
# Ensure JSON-safe return
|
| 47 |
+
return "Metadata extracted successfully.", json.loads(json.dumps(metadata))
|
| 48 |
except Exception as e:
|
| 49 |
error_message = f"Error extracting metadata: {str(e)}\n{traceback.format_exc()}"
|
| 50 |
return error_message, {}
|
|
|
|
| 67 |
|
| 68 |
with gr.Column():
|
| 69 |
status_output = gr.Textbox(label="Status")
|
| 70 |
+
output_metadata = gr.JSON(label="Metadata", type="value")
|
| 71 |
|
| 72 |
input_image.change(
|
| 73 |
fn=process_image,
|
| 74 |
inputs=input_image,
|
| 75 |
outputs=[status_output, output_metadata],
|
| 76 |
+
# Removed api_name to avoid Gradio bug
|
| 77 |
)
|
| 78 |
|
| 79 |
gr.Examples(
|
|
|
|
| 89 |
cache_examples=True,
|
| 90 |
)
|
| 91 |
|
| 92 |
+
demo.launch()
|