osanseviero commited on
Commit
f3dac4d
1 Parent(s): 79a6c02

Create new file

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from huggingface_hub import from_pretrained_fastai
4
+ from pathlib import Path
5
+
6
+ examples = ["llama.jpg", "alpaca.png"]
7
+ repo_id = "osanseviero/llama_or_alpaca"
8
+ path = Path("./")
9
+
10
+ def get_y(r):
11
+ return r["label"]
12
+
13
+ def get_x(r):
14
+ return path/r["fname"]
15
+
16
+ learner = from_pretrained_fastai(repo_id)
17
+ labels = learner.dls.vocab
18
+
19
+ def inference(image):
20
+ label_predict,_,probs = learner.predict(image)
21
+ labels_probs = {labels[i]: float(probs[i]) for i, _ in enumerate(labels)}
22
+ return labels_probs
23
+
24
+ gr.Interface(
25
+ fn=inference,
26
+ title="Llama or alpaca",
27
+ description = "Predict if this image has a llama or an alpaca",
28
+ inputs="image",
29
+ outputs="label",
30
+ examples=examples,
31
+ ).launch(debug=True, enable_queue=True)