Error Unexpected token '<', "<!DOCTYPE "... is not valid JSON

Getting this Error when trying to upload pics from my desktop. The image is a .png, but also tired .jpegs with the same result. Thanks!

error_json

Hi @phi.designer

Would you please provide more details on what lead to the error?

It is a assignment that requires to upload a image?

Best regards
elirod

Sure @elirod , thanks:

As part of the Building GenAI apps with Gradio, during (what is now the first session) “Image Captionng App” / L2_Image_captioning_app notebook, in the Captioning with gr.Interface() exercise we create an interface where you can use image examples, or upload an image.
When uploading an image the “app” throws that error.

import gradio as gr
def image_to_base64_str(pil_image):
byte_arr = io.BytesIO()
pil_image.save(byte_arr, format=‘PNG’)
byte_arr = byte_arr.getvalue()
return str(base64.b64encode(byte_arr).decode(‘utf-8’))
def captioner(image):
base64_image = image_to_base64_str(image)
result = get_completion(base64_image)
return result[0][‘generated_text’]
gr.close_all()
demo = gr.Interface(fn=captioner,
inputs=[gr.Image(label=“Upload image”, type=“pil”)],
outputs=[gr.Textbox(label=“Caption”)],
title=“Image Captioning with BLIP”,
description=“Caption any image using the BLIP model”,
allow_flagging=“never”,
examples=[“christmas_dog.jpeg”, “bird_flight.jpeg”, “cow.jpeg”])
demo.launch(share=True, server_port=int(os.environ[‘PORT1’]))

Hi @phi.designer

Thank you for your reply.

unfortunately it i was unable to reproduce the error you mentioned. I did some tests with different images and everything worked normally.

to make sure the problem isn’t the file being used, I’ll send you the files I use in a private message so you can run some tests, OK?

best regards

Running it locally for the NER part, I gives a similar error:

This is the code that has been used (running it on a MAc):

from transformers import pipeline
get_completion = pipeline("ner", model="dslim/bert-base-NER")
def ner(input):
    output = get_completion(input)
    return {"text": input, "entities": output}
gr.close_all()
demo = gr.Interface(fn=ner,
                    inputs=[gr.Textbox(label="Text to find entities", lines=2)],
                    outputs=[gr.HighlightedText(label="Text with entities")],
                    title="NER with dslim/bert-base-NER",
                    description="Find entities using the `dslim/bert-base-NER` model under the hood!",
                    allow_flagging="never",
                    #Here we introduce a new tag, examples, easy to use examples for your application
                    examples=["My name is Andrew and I live in California", "My name is Poli and work at HuggingFace"])
demo.launch(share=True)

Thanks for giving some advice on how to solve it.