sraimund commited on
Commit
ac6ac91
·
verified ·
1 Parent(s): ce877f6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -1,10 +1,8 @@
1
  import gradio as gr
2
  import torch
3
- from PIL import Image
4
  import open_clip
5
 
6
- def greet(image):
7
- image = Image.fromarray(file_path)
8
  device = torch.device("cpu")
9
  model, _, preprocess = open_clip.create_model_and_transforms('ViT-L-14', pretrained='openai', device=device)
10
 
@@ -16,8 +14,13 @@ def greet(image):
16
  image_features /= image_features.norm(dim=-1, keepdim=True)
17
 
18
  embedding = image_features[0]
 
19
 
20
- return str(embedding)
 
 
21
 
22
- demo = gr.Interface(fn=greet, inputs=gr.inputs.Image(), outputs="text")
 
 
23
  demo.launch()
 
1
  import gradio as gr
2
  import torch
 
3
  import open_clip
4
 
5
+ def predict(image):
 
6
  device = torch.device("cpu")
7
  model, _, preprocess = open_clip.create_model_and_transforms('ViT-L-14', pretrained='openai', device=device)
8
 
 
14
  image_features /= image_features.norm(dim=-1, keepdim=True)
15
 
16
  embedding = image_features[0]
17
+ print(embedding)
18
 
19
+ model = joblib.load('model.pkl')
20
+ result = model.predict([embedding])
21
+ print(result)
22
 
23
+ return "Map" if result == 1 else "No map"
24
+
25
+ demo = gr.Interface(fn=predict, inputs=gr.Image(label="Input Image", type="pil"), outputs="text")
26
  demo.launch()