Hi! I am trying to create a super-basic Space as an example for my students. In fact, I already have such a Space from last year, but I tried replicating it just in case and I am having trouble with uploaded images.
Relevant info:
- I am working from the HF front, as my students have limited experience.
- I am uploading images using the “+ Add File” button. Files are, by default, at root level (same as app.py).
- If I set “examples” as an empty list then the Space works just fine.
- I also tried using a list of lists in “examples”, as suggested by GPT.
- Error message (when using only one image): “
ValueError: File /home/user/app/french.jpg is not in the upload folder and cannot be accessed.
”
This is the Space in question (currently not working, but you should be able to look at the files):
For extra convenience, here you have the code directly:
import gradio as gr
from fastai.vision.all import *
from huggingface_hub import from_pretrained_fastai
learn = from_pretrained_fastai("Pablogps/gradio-test-24")
labels = learn.dls.vocab
def predict(img):
img = PILImage.create(img)
pred, pred_idx, probs = learn.predict(img)
return {labels[i]: float(probs[i]) for i in range(len(labels))}
title = "Bad castle predictor"
description = "A bad model that tries to identify the type of castle."
examples = ['spanish.jpg', 'french.jpg', 'japanese.jpg']
gr.Interface(
fn=predict,
inputs=gr.Image(),
outputs=gr.Label(num_top_classes=3),
title=title,
description=description,
examples=examples,
).launch()
iface.launch()