Spaces:
Runtime error
Runtime error
Commit
·
a473a1e
1
Parent(s):
bdc45df
Try to update Gradio syntax
Browse files
.specstory/history/2025-03-27_10-40-gradio-code-update-and-error-fix.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!-- Generated by SpecStory -->
|
| 2 |
+
|
| 3 |
+
# Gradio Code Update and Error Fix (2025-03-27 18:40:39)
|
| 4 |
+
|
| 5 |
+
_**User**_
|
| 6 |
+
|
| 7 |
+
```
|
| 8 |
+
WARNING:tensorflow:No training configuration found in save file, so the model was *not* compiled. Compile it manually.
|
| 9 |
+
Traceback (most recent call last):
|
| 10 |
+
File "/home/user/app/app.py", line 59, in <module>
|
| 11 |
+
input = [gr.inputs.Image(type="filepath", label="Ground Truth - Real Image (jpg)"),
|
| 12 |
+
AttributeError: module 'gradio' has no attribute 'inputs'
|
| 13 |
+
```
|
| 14 |
+
|
| 15 |
+
Please update @app.py code to use Gradio version 5.23.1 syntax
|
| 16 |
+
|
| 17 |
+
---
|
| 18 |
+
|
| 19 |
+
_**Assistant**_
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
---
|
| 24 |
+
|
| 25 |
+
Let me update the code to use Gradio 5.23.1 syntax:
|
| 26 |
+
|
| 27 |
+
---
|
| 28 |
+
|
| 29 |
+
```diff
|
| 30 |
+
return np.array((fake_img+1)/2)
|
| 31 |
+
|
| 32 |
+
- # input
|
| 33 |
+
- input = [gr.inputs.Image(type="filepath", label="Ground Truth - Real Image (jpg)"),
|
| 34 |
+
- gr.inputs.Image(type="filepath", label="Corresponding Segmentation (png)"),
|
| 35 |
+
- gr.inputs.Image(type="filepath", label="Corresponding bitmap image (bmp)", image_mode="L")]
|
| 36 |
+
+ # Define inputs with modern Gradio syntax
|
| 37 |
+
+ ground_truth = gr.Image(type="filepath", label="Ground Truth - Real Image (jpg)")
|
| 38 |
+
+ segmentation = gr.Image(type="filepath", label="Corresponding Segmentation (png)")
|
| 39 |
+
+ bitmap = gr.Image(type="filepath", label="Corresponding bitmap image (bmp)", image_mode="L")
|
| 40 |
+
|
| 41 |
+
examples = [["facades_data/cmp_b0010.jpg", "facades_data/cmp_b0010.png", "facades_data/cmp_b0010.bmp"],
|
| 42 |
+
["facades_data/cmp_b0050.jpg", "facades_data/cmp_b0050.png", "facades_data/cmp_b0050.bmp"]]
|
| 43 |
+
|
| 44 |
+
- # output
|
| 45 |
+
- output = [gr.outputs.Image(type="numpy", label="Generated - Conditioned Images")]
|
| 46 |
+
-
|
| 47 |
+
title = "GauGAN For Conditional Image Generation"
|
| 48 |
+
description = "Upload an Image or take one from examples to generate realistic images that are conditioned on cue images and segmentation maps"
|
| 49 |
+
|
| 50 |
+
- gr.Interface(fn=predict, inputs = input, outputs = output, examples=examples, allow_flagging=False, analytics_enabled=False,
|
| 51 |
+
- title=title, description=description, article="<center>Space By: <u><a href='https://github.com/robotjellyzone'><b>Kavya Bisht</b></a></u> \n Based on <a href='https://keras.io/examples/generative/gaugan/'><b>this notebook</b></a></center>").launch(enable_queue=True, debug=True)
|
| 52 |
+
+ # Create interface with modern Gradio syntax
|
| 53 |
+
+ demo = gr.Interface(
|
| 54 |
+
+ fn=predict,
|
| 55 |
+
+ inputs=[ground_truth, segmentation, bitmap],
|
| 56 |
+
+ outputs=gr.Image(type="numpy", label="Generated - Conditioned Images"),
|
| 57 |
+
+ examples=examples,
|
| 58 |
+
+ allow_flagging=False,
|
| 59 |
+
+ analytics_enabled=False,
|
| 60 |
+
+ title=title,
|
| 61 |
+
+ description=description,
|
| 62 |
+
+ article="<center>Space By: <u><a href='https://github.com/robotjellyzone'><b>Kavya Bisht</b></a></u> \n Based on <a href='https://keras.io/examples/generative/gaugan/'><b>this notebook</b></a></center>"
|
| 63 |
+
+ )
|
| 64 |
+
+
|
| 65 |
+
+ if __name__ == "__main__":
|
| 66 |
+
+ demo.launch(enable_queue=True, debug=True)
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
---
|
| 70 |
+
|
| 71 |
+
The code has been updated to use Gradio 5.23.1 syntax. The main changes include:
|
| 72 |
+
|
| 73 |
+
1. Replaced the outdated `gr.inputs.Image()` with just `gr.Image()`
|
| 74 |
+
2. Replaced `gr.outputs.Image()` with `gr.Image()`
|
| 75 |
+
3. Created individual component variables instead of input/output lists
|
| 76 |
+
4. Added proper structure with a named `demo` variable
|
| 77 |
+
5. Added an `if __name__ == "__main__":` guard
|
| 78 |
+
6. Used a more modern and cleaner formatting style
|
| 79 |
+
|
| 80 |
+
These changes maintain all the same functionality while using the current Gradio component API.
|
| 81 |
+
|
| 82 |
+
---
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
---
|
| 87 |
+
|
app.py
CHANGED
|
@@ -55,10 +55,10 @@ def predict(image_file, segmentation_png, bitmap_img):
|
|
| 55 |
|
| 56 |
return np.array((fake_img+1)/2)
|
| 57 |
|
| 58 |
-
#
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
|
| 63 |
examples = [["facades_data/cmp_b0010.jpg", "facades_data/cmp_b0010.png", "facades_data/cmp_b0010.bmp"],
|
| 64 |
["facades_data/cmp_b0020.jpg", "facades_data/cmp_b0020.png", "facades_data/cmp_b0020.bmp"],
|
|
@@ -66,11 +66,21 @@ examples = [["facades_data/cmp_b0010.jpg", "facades_data/cmp_b0010.png", "facade
|
|
| 66 |
["facades_data/cmp_b0040.jpg", "facades_data/cmp_b0040.png", "facades_data/cmp_b0040.bmp"],
|
| 67 |
["facades_data/cmp_b0050.jpg", "facades_data/cmp_b0050.png", "facades_data/cmp_b0050.bmp"]]
|
| 68 |
|
| 69 |
-
# output
|
| 70 |
-
output = [gr.outputs.Image(type="numpy", label="Generated - Conditioned Images")]
|
| 71 |
-
|
| 72 |
title = "GauGAN For Conditional Image Generation"
|
| 73 |
description = "Upload an Image or take one from examples to generate realistic images that are conditioned on cue images and segmentation maps"
|
| 74 |
|
| 75 |
-
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
return np.array((fake_img+1)/2)
|
| 57 |
|
| 58 |
+
# Define inputs with modern Gradio syntax
|
| 59 |
+
ground_truth = gr.Image(type="filepath", label="Ground Truth - Real Image (jpg)")
|
| 60 |
+
segmentation = gr.Image(type="filepath", label="Corresponding Segmentation (png)")
|
| 61 |
+
bitmap = gr.Image(type="filepath", label="Corresponding bitmap image (bmp)", image_mode="L")
|
| 62 |
|
| 63 |
examples = [["facades_data/cmp_b0010.jpg", "facades_data/cmp_b0010.png", "facades_data/cmp_b0010.bmp"],
|
| 64 |
["facades_data/cmp_b0020.jpg", "facades_data/cmp_b0020.png", "facades_data/cmp_b0020.bmp"],
|
|
|
|
| 66 |
["facades_data/cmp_b0040.jpg", "facades_data/cmp_b0040.png", "facades_data/cmp_b0040.bmp"],
|
| 67 |
["facades_data/cmp_b0050.jpg", "facades_data/cmp_b0050.png", "facades_data/cmp_b0050.bmp"]]
|
| 68 |
|
|
|
|
|
|
|
|
|
|
| 69 |
title = "GauGAN For Conditional Image Generation"
|
| 70 |
description = "Upload an Image or take one from examples to generate realistic images that are conditioned on cue images and segmentation maps"
|
| 71 |
|
| 72 |
+
# Create interface with modern Gradio syntax
|
| 73 |
+
demo = gr.Interface(
|
| 74 |
+
fn=predict,
|
| 75 |
+
inputs=[ground_truth, segmentation, bitmap],
|
| 76 |
+
outputs=gr.Image(type="numpy", label="Generated - Conditioned Images"),
|
| 77 |
+
examples=examples,
|
| 78 |
+
allow_flagging=False,
|
| 79 |
+
analytics_enabled=False,
|
| 80 |
+
title=title,
|
| 81 |
+
description=description,
|
| 82 |
+
article="<center>Space By: <u><a href='https://github.com/robotjellyzone'><b>Kavya Bisht</b></a></u> \n Based on <a href='https://keras.io/examples/generative/gaugan/'><b>this notebook</b></a></center>"
|
| 83 |
+
)
|
| 84 |
+
|
| 85 |
+
if __name__ == "__main__":
|
| 86 |
+
demo.launch(enable_queue=True, debug=True)
|