Update app.py
Browse files
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
|
| 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 |
-
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
|
|
|
|
|
|
|
| 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()
|