brxerq commited on
Commit
048fc2b
·
verified ·
1 Parent(s): 6c5251e

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -41
app.py DELETED
@@ -1,41 +0,0 @@
1
- # app.py
2
-
3
- __all__ = ['bird', 'learn', 'classify_image', 'categories', 'image', 'label', 'examples', 'intf']
4
-
5
- # Load categories from labels.txt
6
- with open("labels.txt", "r") as file:
7
- categories = [line.strip() for line in file.readlines()]
8
-
9
- # Import FastAI, PyTorch, and Gradio
10
- from fastai.vision.all import *
11
- import gradio as gr
12
- import torch
13
- from torchvision.models import resnet50
14
-
15
- # ✅ Define Model Architecture
16
- def create_model():
17
- model = resnet50(weights=None) # No pre-trained weights
18
- num_features = model.fc.in_features # Get input features of the final layer
19
- model.fc = torch.nn.Linear(num_features, len(categories)) # Replace final layer
20
- return model
21
-
22
- # ✅ Load Model Weights Safely
23
- model = create_model()
24
- model.load_state_dict(torch.load("model_weights.pth", map_location="cpu"))
25
- model.eval() # Set to evaluation mode
26
-
27
- # ✅ Wrap in a FastAI Learner (Even Without DataLoaders)
28
- learn = Learner(dls=None, model=model)
29
-
30
- # ✅ Define the Classification Function
31
- def classify_image(img):
32
- preds, idx, probs = learn.predict(img)
33
- return dict(zip(categories, map(float, probs)))
34
-
35
- # ✅ Gradio UI Components
36
- image = gr.Image()
37
- label = gr.Label(num_top_classes=3)
38
-
39
- # ✅ Create and Launch Gradio Interface
40
- intf = gr.Interface(fn=classify_image, inputs=image, outputs=label)
41
- intf.launch(inline=False, share=True)