Spaces:
Runtime error
Runtime error
final_ver
Browse files
app.py
CHANGED
@@ -2,24 +2,31 @@ import gradio as gr
|
|
2 |
import torch
|
3 |
import time
|
4 |
from fastai.vision.all import load_learner
|
|
|
5 |
from PIL import Image
|
|
|
|
|
|
|
6 |
|
7 |
# Load the exported model
|
8 |
-
|
|
|
|
|
9 |
|
10 |
# Function to classify an image
|
11 |
def classify_images(imgs):
|
|
|
12 |
start_time = time.time()
|
13 |
results = []
|
14 |
for img in imgs:
|
15 |
# Convert gradio image to PIL Image
|
16 |
-
|
17 |
|
18 |
# Perform inference
|
19 |
-
pred_class, pred_idx, pred_probs = model.predict(
|
20 |
|
21 |
# Format output
|
22 |
-
output = f"Image Name: {img.
|
23 |
results.append(output)
|
24 |
|
25 |
# Calculate total inference time
|
@@ -31,8 +38,8 @@ def classify_images(imgs):
|
|
31 |
return results
|
32 |
|
33 |
# Create Gradio interface
|
34 |
-
input_component = gr.
|
35 |
-
output_component = gr.
|
36 |
interface = gr.Interface(fn=classify_images, inputs=input_component, outputs=output_component, title="Image Classifier")
|
37 |
|
38 |
# Launch the Gradio interface
|
|
|
2 |
import torch
|
3 |
import time
|
4 |
from fastai.vision.all import load_learner
|
5 |
+
from fastai.vision.all import *
|
6 |
from PIL import Image
|
7 |
+
from pathlib import Path
|
8 |
+
import pathlib
|
9 |
+
import PIL
|
10 |
|
11 |
# Load the exported model
|
12 |
+
temp = pathlib.PosixPath
|
13 |
+
pathlib.PosixPath = pathlib.WindowsPath
|
14 |
+
model = load_learner(r"C:\Users\i0567479\Downloads\model.pkl")
|
15 |
|
16 |
# Function to classify an image
|
17 |
def classify_images(imgs):
|
18 |
+
[print(x) for x in imgs]
|
19 |
start_time = time.time()
|
20 |
results = []
|
21 |
for img in imgs:
|
22 |
# Convert gradio image to PIL Image
|
23 |
+
#img = PILImage.create(img)
|
24 |
|
25 |
# Perform inference
|
26 |
+
pred_class, pred_idx, pred_probs = model.predict(img)
|
27 |
|
28 |
# Format output
|
29 |
+
output = f"Image Name: {Path(img).stem} - Category: {pred_class}"
|
30 |
results.append(output)
|
31 |
|
32 |
# Calculate total inference time
|
|
|
38 |
return results
|
39 |
|
40 |
# Create Gradio interface
|
41 |
+
input_component = gr.File(label="Upload Image", file_count='multiple')
|
42 |
+
output_component = gr.Textbox(label="Classification Results")
|
43 |
interface = gr.Interface(fn=classify_images, inputs=input_component, outputs=output_component, title="Image Classifier")
|
44 |
|
45 |
# Launch the Gradio interface
|