Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from fastai.vision.all import load_learner
|
| 3 |
+
from fastai import *
|
| 4 |
+
import torch
|
| 5 |
+
import os
|
| 6 |
+
from PIL import Image
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
model_path = 'model3-86%.pkl'
|
| 10 |
+
|
| 11 |
+
model = load_learner(model_path)
|
| 12 |
+
|
| 13 |
+
def result(path):
|
| 14 |
+
|
| 15 |
+
pred,_,probability = model.predict(path)
|
| 16 |
+
pred = str(pred)
|
| 17 |
+
pred = pred.upper()
|
| 18 |
+
|
| 19 |
+
return {pred: float(probability.max())}
|
| 20 |
+
|
| 21 |
+
path = 'test/'
|
| 22 |
+
|
| 23 |
+
image_path = []
|
| 24 |
+
|
| 25 |
+
for i in os.listdir(path):
|
| 26 |
+
image_path.append(path+i)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
image = gr.inputs.Image(shape =(200,200),image_mode='L',invert_colors=False)
|
| 30 |
+
label = gr.outputs.Label()
|
| 31 |
+
|
| 32 |
+
iface = gr.Interface(fn=result, inputs=image, outputs=label, examples = image_path)
|
| 33 |
+
iface.launch(inline=False)
|