pizurny commited on
Commit
a19958b
·
verified ·
1 Parent(s): ae7e5c2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -7
app.py CHANGED
@@ -1,23 +1,27 @@
1
  from fastai.vision.all import *
2
- import pathlib
3
- import gradio as gr
4
-
5
- # Fix for Windows systems
6
- temp = pathlib.PosixPath
7
- pathlib.PosixPath = pathlib.WindowsPath
8
 
9
- # Load the trained model
10
  learn = load_learner('babis_fico_classifier.pkl')
11
 
 
 
 
 
 
 
12
  # Define the prediction function
13
  def predict_image(img):
14
  pred, pred_idx, probs = learn.predict(img)
15
  return {learn.dls.vocab[i]: float(probs[i]) for i in range(len(probs))}
16
 
17
  # Set up the Gradio interface
 
18
  image_input = gr.Image(type="pil")
19
  label_output = gr.Label(num_top_classes=2)
20
 
21
  interface = gr.Interface(fn=predict_image, inputs=image_input, outputs=label_output,
22
  title="Babiš vs Fico Classifier",
23
  description="Upload an image of Robert Fico or Andrej Babiš to classify.")
 
 
 
1
  from fastai.vision.all import *
2
+ from pathlib import Path
 
 
 
 
 
3
 
4
+ # Load the model with WindowsPath issue
5
  learn = load_learner('babis_fico_classifier.pkl')
6
 
7
+ # Re-save the model in the current Linux environment (removing WindowsPath issues)
8
+ learn.export('babis_fico_classifier_linux.pkl')
9
+
10
+ # Load the newly saved model
11
+ learn = load_learner('babis_fico_classifier_linux.pkl')
12
+
13
  # Define the prediction function
14
  def predict_image(img):
15
  pred, pred_idx, probs = learn.predict(img)
16
  return {learn.dls.vocab[i]: float(probs[i]) for i in range(len(probs))}
17
 
18
  # Set up the Gradio interface
19
+ import gradio as gr
20
  image_input = gr.Image(type="pil")
21
  label_output = gr.Label(num_top_classes=2)
22
 
23
  interface = gr.Interface(fn=predict_image, inputs=image_input, outputs=label_output,
24
  title="Babiš vs Fico Classifier",
25
  description="Upload an image of Robert Fico or Andrej Babiš to classify.")
26
+
27
+ interface.launch()