qanastek / HugsVision

HugsVision is a easy to use huggingface wrapper for state-of-the-art computer vision

Home Page:https://pypi.org/project/hugsvision/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

issues and errors in first tryout in ubuntu 20

johnfelipe opened this issue · comments

sudo su
apt update
apt upgrade
shutdown -r now

sudo su
cd
apt install python3-pip
pip install gradio
git clone https://huggingface.co/spaces/HugsVision/Skin-Cancer
cd Skin-Cancer/
pip install -r requirements.txt
nano app.py


##
interface.launch(server_name="0.0.0.0")
##

and run with

python3 app.py

	/usr/local/lib/python3.8/dist-packages/torchvision/transforms/transforms.py:287: UserWarning: Argument interpolation should be of type InterpolationMode instead of int. Please, use InterpolationMode enum.
	  warnings.warn(
	2022-01-10 23:04:23.268536: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory
	2022-01-10 23:04:23.268576: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
	/usr/local/lib/python3.8/dist-packages/torchvision/transforms/transforms.py:287: UserWarning: Argument interpolation should be of type InterpolationMode instead of int. Please, use InterpolationMode enum.
	  warnings.warn(
	[['images/akiec.jpg'], ['images/bcc.jpg'], ['images/bkl.jpg'], ['images/df.jpg'], ['images/mel.jpg'], ['images/nv.jpg'], ['images/vasc.jpg']]
	/usr/local/lib/python3.8/dist-packages/gradio/interface.py:188: UserWarning: The `capture_session` parameter in the `Interface` is deprecated and has no effect.
	  warnings.warn("The `capture_session` parameter in the `Interface` is deprecated and has no effect.")
	/usr/local/lib/python3.8/dist-packages/gradio/interface.py:205: UserWarning: 'darkhuggingface' theme name is deprecated, using dark-huggingface instead.
	  warnings.warn(f"'{theme}' theme name is deprecated, using {DEPRECATED_THEME_MAP[theme]} instead.")
	/usr/local/lib/python3.8/dist-packages/gradio/interface.py:248: UserWarning: The `allow_flagging` parameter in `Interface` nowtakes a string value ('auto', 'manual', or 'never'), not a boolean. Setting parameter to: 'never'.
	  warnings.warn("The `allow_flagging` parameter in `Interface` now"
	/usr/local/lib/python3.8/dist-packages/gradio/interface.py:271: UserWarning: The `show_tips` parameter in the `Interface` is deprecated. Please use the `show_tips` parameter in `launch()` instead
	  warnings.warn("The `show_tips` parameter in the `Interface` is deprecated. Please use the `show_tips` parameter in `launch()` instead")
	/usr/local/lib/python3.8/dist-packages/gradio/interface.py:293: UserWarning: The `encrypt` parameter in the `Interface` classwill be deprecated. Please provide this parameterin `launch()` instead
	  warnings.warn(
	Running on local URL:  http://localhost:7860/

	To create a public link, set `share=True` in `launch()`.

SNAG-0868

[2022-01-10 23:04:49,518] ERROR in app: Exception on /api/predict/ [POST]
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 2073, in wsgi_app
	response = self.full_dispatch_request()
  File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1518, in full_dispatch_request
	rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.8/dist-packages/flask_cors/extension.py", line 165, in wrapped_function
	return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1516, in full_dispatch_request
	rv = self.dispatch_request()
  File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1502, in dispatch_request
	return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "/usr/local/lib/python3.8/dist-packages/gradio/networking.py", line 93, in wrapper
	return func(*args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/gradio/networking.py", line 232, in predict
	prediction, durations = process_example(app.interface, example_id)
  File "/usr/local/lib/python3.8/dist-packages/gradio/process_examples.py", line 12, in process_example
	prediction, durations = interface.process(raw_input)
  File "/usr/local/lib/python3.8/dist-packages/gradio/interface.py", line 408, in process
	processed_input = [input_component.preprocess(raw_input[i])
  File "/usr/local/lib/python3.8/dist-packages/gradio/interface.py", line 408, in <listcomp>
	processed_input = [input_component.preprocess(raw_input[i])
IndexError: list index out of range

how can solve this?

Hi John,

Thanks you very much for your feedback I seriously appreciate it.

This is due to the default value of the Radio input. By default, it's set to None and cause a crash. It's occur only when you aren't selecting explicitly a model name and use the default model name.

Default values in HTTP payload:

{
    "example_id": 0
}

HTTP payload after selecting a model:

{
    "data": [
        "data:image/jpeg;base64......",
        "ShuffleNetV2"
    ]
}

You can fix this temporally by removing the radio button from the inputs and only giving the image.

def predict_image(image):
    model_name = "DenseNet121"

and

interface = gr.Interface(
    fn=predict_image, 
    inputs=[image],
    outputs=label, 
    examples=samples,
)
interface.launch()

I will fixing it by the end of the week. Let me know if you find any solution by then.

This is already fixed?

Hi Felipe,

I tried my best to understand why it's happen and it's 100% sure it's related to gradio itself.

id2label = ["akiec", "bcc", "bkl", "df", "mel", "nv", "vasc"]

det = ["VGG16","DeiT","ShuffleNetV2","MobileNetV2","DenseNet121"]

inter = Interface(
    fn=predict_image,
    outputs=outputs.Label(num_top_classes=len(id2label)), 
    examples=list([["images/" + p + ".jpg"] for p in id2label]),
    inputs=[
        inputs.Image(),
        inputs.Dropdown(choices=det, default=None)
    ],
)

It's look like that the parameter choices is empty during the Dropdown instantiation.

I think it's due to having an Image and Radio / Dropdown elements in the same time as inputs.

If we reverse the Image and Radio elements, it's completely broken too.

Screenshot 2022-01-21 at 20 45 57

When using this code :

from gradio import inputs, outputs, Interface

def predict_image(image, model_name):
    pred = {}
    for key in ["akiec", "bcc", "bkl", "df", "mel", "nv", "vasc"]:
        pred[key] = 0.55
    return pred

id2label = ["akiec", "bcc", "bkl", "df", "mel", "nv", "vasc"]
det = ["VGG16","DeiT","ShuffleNetV2","MobileNetV2","DenseNet121"]

inter = Interface(
    fn=predict_image,
    outputs=outputs.Label(num_top_classes=len(id2label)), 
    examples=list([["images/" + p + ".jpg"] for p in id2label]),
    inputs=[
        inputs.Dropdown(choices=list(det), default=None),
        inputs.Image(type="filepath"),
    ],
)
inter.launch(show_error=True)

If we remove the Image or Radio it's works perfectly fine. So, in my opinion, having both elements at the same time is the reason of this issue. Please consider creating an issue on the gradio github to warn the maintainers about this issue.