Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from roboflow import Roboflow
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
+
def obj(input_img):
|
| 7 |
+
#load model
|
| 8 |
+
rf = Roboflow(api_key="u5HA4Ou9LROqjjWJYSJV")
|
| 9 |
+
project = rf.workspace("modzie-work").project("bmd-result")
|
| 10 |
+
model = project.version(1).model
|
| 11 |
+
|
| 12 |
+
#save to .jpg
|
| 13 |
+
img = Image.fromarray(input_img, "RGB")
|
| 14 |
+
img.save("image_filename.jpg")
|
| 15 |
+
image_save_test = 'image_filename.jpg'
|
| 16 |
+
|
| 17 |
+
#predict
|
| 18 |
+
obj_result = model.predict(image_save_test, confidence=40, overlap=30).json()['predictions'][0]['class']
|
| 19 |
+
if obj_result == "Low Bone":
|
| 20 |
+
obj_result = "Osteopenia"
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
return obj_result
|
| 24 |
+
|
| 25 |
+
demo = gr.Interface(obj, "image", "text")
|
| 26 |
+
demo.launch()
|