Spaces:
Sleeping
Sleeping
Commit
·
0bce035
1
Parent(s):
bdac169
refactor imports
Browse files
app.py
CHANGED
@@ -1,4 +1,7 @@
|
|
1 |
-
import
|
|
|
|
|
|
|
2 |
from PIL import Image
|
3 |
import numpy as np
|
4 |
import json
|
@@ -9,6 +12,9 @@ import torch
|
|
9 |
import matplotlib.pyplot as plt
|
10 |
import matplotlib.ticker as ticker
|
11 |
from huggingface_hub import HfApi
|
|
|
|
|
|
|
12 |
|
13 |
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
14 |
|
@@ -82,14 +88,14 @@ class Network(nn.Module):
|
|
82 |
|
83 |
return F.log_softmax(x, dim=1)
|
84 |
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
inp = Image.open(img_path)
|
94 |
exif = inp.getexif()
|
95 |
|
@@ -212,5 +218,5 @@ gr.Interface(
|
|
212 |
predict,
|
213 |
inputs=gr.inputs.Image(label="Upload a flower image", type="filepath"),
|
214 |
outputs=gr.outputs.Label(num_top_classes=5),
|
215 |
-
title="What kind of flower is this?"
|
216 |
).launch()
|
|
|
1 |
+
import os
|
2 |
+
import re
|
3 |
+
from datetime import datetime
|
4 |
+
|
5 |
from PIL import Image
|
6 |
import numpy as np
|
7 |
import json
|
|
|
12 |
import matplotlib.pyplot as plt
|
13 |
import matplotlib.ticker as ticker
|
14 |
from huggingface_hub import HfApi
|
15 |
+
import gradio as gr
|
16 |
+
|
17 |
+
HF_TOKEN = os.environ.get("HF_TOKEN")
|
18 |
|
19 |
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
20 |
|
|
|
88 |
|
89 |
return F.log_softmax(x, dim=1)
|
90 |
|
91 |
+
def process_image(img_path):
|
92 |
+
"""Scales, crops, and normalizes a PIL image for a PyTorch model,
|
93 |
+
returns a Numpy array
|
94 |
|
95 |
+
Arguments
|
96 |
+
---------
|
97 |
+
image: path of the image to be processed
|
98 |
+
"""
|
99 |
inp = Image.open(img_path)
|
100 |
exif = inp.getexif()
|
101 |
|
|
|
218 |
predict,
|
219 |
inputs=gr.inputs.Image(label="Upload a flower image", type="filepath"),
|
220 |
outputs=gr.outputs.Label(num_top_classes=5),
|
221 |
+
title="What kind of flower is this?"
|
222 |
).launch()
|