Spaces:
Runtime error
Runtime error
Commit ·
c8b4b8f
1
Parent(s): a473a1e
Try to fix the flagging mode error
Browse filesFiles changed (2)
80 unmodified lines81828384858680 unmodified lines------80 unmodified lines8182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312480 unmodified lines---_**User**_Now the error become this```/usr/local/lib/python3.10/site-packages/gradio/interface.py:415: UserWarning: The `allow_flagging` parameter in `Interface` is deprecated.Use `flagging_mode` instead.warnings.warn(Traceback (most recent call last):File "/home/user/app/app.py", line 73, in <module>demo = gr.Interface(File "/usr/local/lib/python3.10/site-packages/gradio/interface.py", line 425, in __init__raise ValueError(ValueError: Invalid value for `flagging_mode` parameter.Must be: 'auto', 'manual', or 'never'.```---_**Assistant**_---```diffoutputs=gr.Image(type="numpy", label="Generated - Conditioned Images"),examples=examples,- allow_flagging=False,+ flagging_mode="never",analytics_enabled=False,title=title,```---I've updated the code by replacing the deprecated `allow_flagging=False` parameter with the new `flagging_mode="never"` parameter. The newer versions of Gradio have replaced the boolean flag with a more flexible string parameter that supports different flagging modes: 'auto', 'manual', or 'never'.------
7 unmodified lines8910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485867 unmodified linesfrom huggingface_hub import from_pretrained_kerasmodel = from_pretrained_keras("keras-io/GauGAN-Image-generation")def predict(image_file, segmentation_png, bitmap_img):image_list = [segmentation_png, image_file, bitmap_img]image = tf.image.decode_png(tf.io.read_file(image_list[1]), channels=3)image = tf.cast(image, tf.float32) / 127.5 - 1segmentation_file = tf.image.decode_png(tf.io.read_file(image_list[0]), channels=3)segmentation_file = tf.cast(segmentation_file, tf.float32)/127.5 - 1label_file = tf.image.decode_bmp(tf.io.read_file(image_list[2]), channels=0)# label_file = tf.image.rgb_to_grayscale(tf.image.decode_bmp(tf.io.read_file(image_list[2]), channels=3))# print("after decode_bmp --> ", label_file.shape, type(label_file))label_file = tf.squeeze(label_file)image_list = [segmentation_file, image, label_file]crop_size = tf.convert_to_tensor((256, 256))image_shape = tf.shape(image_list[1])[:2]margins = image_shape - crop_sizey1 = tf.random.uniform(shape=(), maxval=margins[0], dtype=tf.int32)x1 = tf.random.uniform(shape=(), maxval=margins[1], dtype=tf.int32)y2 = y1 + crop_size[0]x2 = x1 + crop_size[1]cropped_images = []for img in image_list:cropped_images.append(img[y1:y2, x1:x2])final_img_list = [tf.expand_dims(cropped_images[0], axis=0), tf.expand_dims(cropped_images[1], axis=0), tf.expand_dims(tf.one_hot(cropped_images[2], 12), axis=0)]# print(final_img_list[0].shape)# print(final_img_list[1].shape)# print(final_img_list[2].shape)latent_vector = tf.random.normal(shape=(1, 256), mean=0.0, stddev=2.0)# Generate fake imagesfake_image = model.predict([latent_vector, final_img_list[2]])fake_img = tf.squeeze(fake_image, axis=0)return 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"],["facades_data/cmp_b0030.jpg", "facades_data/cmp_b0030.png", "facades_data/cmp_b0030.bmp"],["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)7 unmodified lines891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151167 unmodified linesfrom huggingface_hub import from_pretrained_kerasmodel = from_pretrained_keras("keras-io/GauGAN-Image-generation")def predict(image_file, segmentation_png, bitmap_img):image_list = [segmentation_png, image_file, bitmap_img]image = tf.image.decode_png(tf.io.read_file(image_list[1]), channels=3)image = tf.cast(image, tf.float32) / 127.5 - 1segmentation_file = tf.image.decode_png(tf.io.read_file(image_list[0]), channels=3)segmentation_file = tf.cast(segmentation_file, tf.float32) / 127.5 - 1label_file = tf.image.decode_bmp(tf.io.read_file(image_list[2]), channels=0)# label_file = tf.image.rgb_to_grayscale(tf.image.decode_bmp(tf.io.read_file(image_list[2]), channels=3))# print("after decode_bmp --> ", label_file.shape, type(label_file))label_file = tf.squeeze(label_file)image_list = [segmentation_file, image, label_file]crop_size = tf.convert_to_tensor((256, 256))image_shape = tf.shape(image_list[1])[:2]margins = image_shape - crop_sizey1 = tf.random.uniform(shape=(), maxval=margins[0], dtype=tf.int32)x1 = tf.random.uniform(shape=(), maxval=margins[1], dtype=tf.int32)y2 = y1 + crop_size[0]x2 = x1 + crop_size[1]cropped_images = []for img in image_list:cropped_images.append(img[y1:y2, x1:x2])final_img_list = [tf.expand_dims(cropped_images[0], axis=0),tf.expand_dims(cropped_images[1], axis=0),tf.expand_dims(tf.one_hot(cropped_images[2], 12), axis=0),]# print(final_img_list[0].shape)# print(final_img_list[1].shape)# print(final_img_list[2].shape)latent_vector = tf.random.normal(shape=(1, 256), mean=0.0, stddev=2.0)# Generate fake imagesfake_image = model.predict([latent_vector, final_img_list[2]])fake_img = tf.squeeze(fake_image, axis=0)return 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",],["facades_data/cmp_b0030.jpg","facades_data/cmp_b0030.png","facades_data/cmp_b0030.bmp",],["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,flagging_mode="never",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.md+38
app.py+71-41