Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,17 +1,11 @@
|
|
1 |
import os
|
2 |
-
import streamlit as st #Web App
|
3 |
-
from PIL import Image #Image Processing
|
4 |
-
import numpy as np #Image Processing
|
5 |
import torch
|
|
|
|
|
|
|
|
|
6 |
|
7 |
-
#title
|
8 |
-
st.title("Hololive Waifu Classification")
|
9 |
-
|
10 |
-
image = st.text_input('Image URL', '')
|
11 |
-
# st.write('URL: ', title)
|
12 |
|
13 |
-
#image uploader
|
14 |
-
# image = st.file_uploader(label = "Upload your image here",type=['png','jpg','jpeg'])
|
15 |
def check_suffix(file='yolov5s.pt', suffix=('.pt',), msg=''):
|
16 |
# Check file(s) for acceptable suffix
|
17 |
if file and suffix:
|
@@ -31,52 +25,26 @@ def check_file(file, suffix=''):
|
|
31 |
return file
|
32 |
elif file.startswith(('http:/', 'https:/')): # download
|
33 |
url = file # warning: Pathlib turns :// -> :/
|
34 |
-
|
|
|
35 |
if os.path.isfile(file):
|
36 |
print(f'Found {url} locally at {file}') # file already exists
|
37 |
else:
|
38 |
print(f'Downloading {url} to {file}...')
|
39 |
torch.hub.download_url_to_file(url, file)
|
40 |
-
assert Path(file).exists() and Path(file).stat(
|
41 |
-
|
42 |
-
elif file.startswith('clearml://'): # ClearML Dataset ID
|
43 |
-
assert 'clearml' in sys.modules, "ClearML is not installed, so cannot use ClearML dataset. Try running 'pip install clearml'."
|
44 |
return file
|
45 |
-
else: # search
|
46 |
-
files = []
|
47 |
-
for d in 'data', 'models', 'utils': # search directories
|
48 |
-
files.extend(glob.glob(str(ROOT / d / '**' / file), recursive=True)) # find file
|
49 |
-
assert len(files), f'File not found: {file}' # assert file was found
|
50 |
-
assert len(files) == 1, f"Multiple files match '{file}', specify exact path: {files}" # assert unique
|
51 |
-
return files[0]
|
52 |
|
53 |
-
@st.cache
|
54 |
-
def load_model():
|
55 |
-
model = torch.hub.load('ultralytics/yolov5', 'yolov5x6', path='best.pt') # local model
|
56 |
|
57 |
-
|
|
|
|
|
58 |
|
59 |
if image != '':
|
60 |
image = check_file(image)
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
#result = reader.readtext(np.array(input_image))
|
69 |
-
|
70 |
-
#result_text = [] #empty list for results
|
71 |
-
|
72 |
-
|
73 |
-
#for text in result:
|
74 |
-
#result_text.append(text[1])
|
75 |
-
|
76 |
-
#st.write(result_text)
|
77 |
-
#st.success("Here you go!")
|
78 |
-
#st.balloons()
|
79 |
-
#else:
|
80 |
-
#st.write("Upload an Image")
|
81 |
-
|
82 |
-
st.caption("authors: neko941")
|
|
|
1 |
import os
|
|
|
|
|
|
|
2 |
import torch
|
3 |
+
import urllib
|
4 |
+
from PIL import Image
|
5 |
+
import streamlit as st
|
6 |
+
from pathlib import Path
|
7 |
|
|
|
|
|
|
|
|
|
|
|
8 |
|
|
|
|
|
9 |
def check_suffix(file='yolov5s.pt', suffix=('.pt',), msg=''):
|
10 |
# Check file(s) for acceptable suffix
|
11 |
if file and suffix:
|
|
|
25 |
return file
|
26 |
elif file.startswith(('http:/', 'https:/')): # download
|
27 |
url = file # warning: Pathlib turns :// -> :/
|
28 |
+
# '%2F' to '/', split https://url.com/file.txt?auth
|
29 |
+
file = Path(urllib.parse.unquote(file).split('?')[0]).name
|
30 |
if os.path.isfile(file):
|
31 |
print(f'Found {url} locally at {file}') # file already exists
|
32 |
else:
|
33 |
print(f'Downloading {url} to {file}...')
|
34 |
torch.hub.download_url_to_file(url, file)
|
35 |
+
assert Path(file).exists() and Path(file).stat(
|
36 |
+
).st_size > 0, f'File download failed: {url}' # check
|
|
|
|
|
37 |
return file
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
|
|
|
|
|
|
39 |
|
40 |
+
st.title("Hololive Waifu Classification")
|
41 |
+
|
42 |
+
image = st.text_input('Image URL', '')
|
43 |
|
44 |
if image != '':
|
45 |
image = check_file(image)
|
46 |
+
input_image = Image.open(image)
|
47 |
+
model = torch.hub.load('ultralytics/yolov5', 'custom', path='best.pt')
|
48 |
+
results = model(input_image, size=640)
|
49 |
+
for img in results.render():
|
50 |
+
st.image(img)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|