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