Dolpheyn commited on
Commit
39bb2df
·
1 Parent(s): 6ebc96d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -2
app.py CHANGED
@@ -1,4 +1,49 @@
 
 
 
 
 
 
 
1
  import streamlit as st
2
 
3
- x = st.slider('Select a value')
4
- st.write(x, 'squared is', x * x)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from PIL import Image
2
+ from model import yolox
3
+ from os import listdir
4
+ import os.path
5
+ import gdown
6
+ import gradio as gr
7
+ import numpy as np
8
  import streamlit as st
9
 
10
+ DMINITY_MODEL_URL = "https://drive.google.com/uc?id=1HnBFOXoRsqn6LiX63hZqZFSEOic2-71M"
11
+ MODEL_PATH = "dminity.onnx"
12
+
13
+ @st.cache(allow_output_mutation=True, show_spinner=True)
14
+ def get_model():
15
+ # Download model from Google Drive if it does not exist
16
+ if not os.path.isfile(MODEL_PATH):
17
+ gdown.download(DMINITY_MODEL_URL, MODEL_PATH)
18
+
19
+ # Load model with OpenCV
20
+ model = yolox(MODEL_PATH, p6=False, confThreshold=0.3)
21
+
22
+ return model
23
+
24
+
25
+ def dminity(im, size=640):
26
+ model = get_model()
27
+ # Resize image
28
+ g = (size / max(im.size))
29
+ im = im.resize((int(x * g) for x in im.size))
30
+ im = np.array(im)
31
+
32
+ # Detect and get back rendered image and amenities list
33
+ image, amenities = model.detect(im)
34
+ return image, amenities
35
+
36
+ inputs = gr.inputs.Image(type='pil', label="Original Image")
37
+ outputs = [gr.outputs.Image(type='pil', label="Output Image"), "text"]
38
+
39
+ title = "Dminity"
40
+ description = "Dminity demo for amenity object detection. Upload a house interior image with amenities or click an example image to use."
41
+ article = "<p style='text-align: center'>Dminity is a YOLOX object detection model trained to detect home amenities.</p>"
42
+
43
+ # List of example images
44
+ files = ['images/' + f for f in listdir('images')]
45
+ examples=[[f] for f in files]
46
+
47
+ gr.Interface(dminity, inputs, outputs, title=title, description=description,
48
+ article=article, examples=examples,
49
+ theme="huggingface").launch(debug=True)