Spaces:
Runtime error
Runtime error
Commit ·
a473a1e
1
Parent(s): bdc45df
Try to update Gradio syntax
Browse filesFiles changed (2)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687<!-- Generated by SpecStory -->
# Gradio Code Update and Error Fix (2025-03-27 18:40:39)
_**User**_
```WARNING:tensorflow:No training configuration found in save file, so the model was *not* compiled. Compile it manually.Traceback (most recent call last): File "/home/user/app/app.py", line 59, in <module> input = [gr.inputs.Image(type="filepath", label="Ground Truth - Real Image (jpg)"),AttributeError: module 'gradio' has no attribute 'inputs'```
Please update @app.py code to use Gradio version 5.23.1 syntax
---
_**Assistant**_
---
Let me update the code to use Gradio 5.23.1 syntax:
---
```diff return np.array((fake_img+1)/2) - # input- input = [gr.inputs.Image(type="filepath", label="Ground Truth - Real Image (jpg)"), - gr.inputs.Image(type="filepath", label="Corresponding Segmentation (png)"),- gr.inputs.Image(type="filepath", label="Corresponding bitmap image (bmp)", image_mode="L")]+ # Define inputs with modern Gradio syntax+ ground_truth = gr.Image(type="filepath", label="Ground Truth - Real Image (jpg)")+ segmentation = gr.Image(type="filepath", label="Corresponding Segmentation (png)")+ bitmap = gr.Image(type="filepath", label="Corresponding bitmap image (bmp)", image_mode="L") examples = [["facades_data/cmp_b0010.jpg", "facades_data/cmp_b0010.png", "facades_data/cmp_b0010.bmp"], ["facades_data/cmp_b0050.jpg", "facades_data/cmp_b0050.png", "facades_data/cmp_b0050.bmp"]] - # output- output = [gr.outputs.Image(type="numpy", label="Generated - Conditioned Images")]- title = "GauGAN For Conditional Image Generation" description = "Upload an Image or take one from examples to generate realistic images that are conditioned on cue images and segmentation maps" - gr.Interface(fn=predict, inputs = input, outputs = output, examples=examples, allow_flagging=False, analytics_enabled=False,- 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)+ # Create interface with modern Gradio syntax+ demo = gr.Interface(+ fn=predict, + inputs=[ground_truth, segmentation, bitmap],+ outputs=gr.Image(type="numpy", label="Generated - Conditioned Images"),+ examples=examples,+ allow_flagging=False,+ analytics_enabled=False,+ 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>"+ )+ + if __name__ == "__main__":+ demo.launch(enable_queue=True, debug=True)```
---
The code has been updated to use Gradio 5.23.1 syntax. The main changes include:
1. Replaced the outdated `gr.inputs.Image()` with just `gr.Image()`2. Replaced `gr.outputs.Image()` with `gr.Image()`3. Created individual component variables instead of input/output lists4. Added proper structure with a named `demo` variable5. Added an `if __name__ == "__main__":` guard6. Used a more modern and cleaner formatting style
These changes maintain all the same functionality while using the current Gradio component API.
---
---
54 unmodified lines555657585960616263641 unmodified line666768697071727374757654 unmodified linesreturn np.array((fake_img+1)/2)# inputinput = [gr.inputs.Image(type="filepath", label="Ground Truth - Real Image (jpg)"),gr.inputs.Image(type="filepath", label="Corresponding Segmentation (png)"),gr.inputs.Image(type="filepath", label="Corresponding bitmap image (bmp)", image_mode="L")]examples = [["facades_data/cmp_b0010.jpg", "facades_data/cmp_b0010.png", "facades_data/cmp_b0010.bmp"],["facades_data/cmp_b0020.jpg", "facades_data/cmp_b0020.png", "facades_data/cmp_b0020.bmp"],1 unmodified line["facades_data/cmp_b0040.jpg", "facades_data/cmp_b0040.png", "facades_data/cmp_b0040.bmp"],["facades_data/cmp_b0050.jpg", "facades_data/cmp_b0050.png", "facades_data/cmp_b0050.bmp"]]# outputoutput = [gr.outputs.Image(type="numpy", label="Generated - Conditioned Images")]title = "GauGAN For Conditional Image Generation"description = "Upload an Image or take one from examples to generate realistic images that are conditioned on cue images and segmentation maps"gr.Interface(fn=predict, inputs = input, outputs = output, examples=examples, allow_flagging=False, analytics_enabled=False,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)54 unmodified lines555657585960616263641 unmodified line66676869707172737475767778798081828384858654 unmodified linesreturn np.array((fake_img+1)/2)# Define inputs with modern Gradio syntaxground_truth = gr.Image(type="filepath", label="Ground Truth - Real Image (jpg)")segmentation = gr.Image(type="filepath", label="Corresponding Segmentation (png)")bitmap = gr.Image(type="filepath", label="Corresponding bitmap image (bmp)", image_mode="L")examples = [["facades_data/cmp_b0010.jpg", "facades_data/cmp_b0010.png", "facades_data/cmp_b0010.bmp"],["facades_data/cmp_b0020.jpg", "facades_data/cmp_b0020.png", "facades_data/cmp_b0020.bmp"],1 unmodified line["facades_data/cmp_b0040.jpg", "facades_data/cmp_b0040.png", "facades_data/cmp_b0040.bmp"],["facades_data/cmp_b0050.jpg", "facades_data/cmp_b0050.png", "facades_data/cmp_b0050.bmp"]]title = "GauGAN For Conditional Image Generation"description = "Upload an Image or take one from examples to generate realistic images that are conditioned on cue images and segmentation maps"# Create interface with modern Gradio syntaxdemo = gr.Interface(fn=predict,inputs=[ground_truth, segmentation, bitmap],outputs=gr.Image(type="numpy", label="Generated - Conditioned Images"),examples=examples,allow_flagging=False,analytics_enabled=False,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>")if __name__ == "__main__":demo.launch(enable_queue=True, debug=True)
.specstory/history/2025-03-27_10-40-gradio-code-update-and-error-fix.mdAdded+87
app.py+19-9