BimanL commited on
Commit
6eb150c
1 Parent(s): 5ff91bc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -4
app.py CHANGED
@@ -1,7 +1,35 @@
1
  import gradio as gr
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from fastai.vision.all import *
3
+ import skimage
4
 
5
+ # Load your trained model
6
+ learn = load_learner('export.pkl')
7
 
8
+ # Define the labels (in this case, just 'cat' and 'dog')
9
+ labels = ['cat', 'dog']
10
+
11
+ # Define the prediction function
12
+ def predict(img):
13
+ img = PILImage.create(img)
14
+ pred, pred_idx, probs = learn.predict(img)
15
+ # Return a dictionary of probabilities
16
+ return {labels[i]: float(probs[i]) for i in range(len(labels))}
17
+
18
+ # Update the title, description, and other details for your cat vs. dog classifier
19
+ title = "Cat vs Dog Classifier"
20
+ description = "A classifier to distinguish between cats and dogs. Trained with fastai on a relevant dataset."
21
+ article = "<p style='text-align: center'><a href='https://yourlinkhere.com' target='_blank'>Blog post or additional information</a></p>"
22
+ examples = ['/path/to/example_image.jpg'] # Update this path to your example images
23
+
24
+ # Create and launch the Gradio interface
25
+ gr.Interface(
26
+ fn=predict,
27
+ inputs=gr.inputs.Image(shape=(512, 512)),
28
+ outputs=gr.outputs.Label(num_top_classes=2),
29
+ title=title,
30
+ description=description,
31
+ article=article,
32
+ examples=examples,
33
+ interpretation='default',
34
+ enable_queue=True
35
+ ).launch()