Spaces:
Runtime error
Runtime error
Nik Ska
commited on
Commit
•
f59bac9
1
Parent(s):
f2c3938
added error handling
Browse files- .gitignore +53 -0
- app.py +12 -8
- requirements.txt +2 -3
.gitignore
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Ignore compiled Python files
|
2 |
+
*.pyc
|
3 |
+
*.pyo
|
4 |
+
__pycache__/
|
5 |
+
|
6 |
+
# Ignore local development settings
|
7 |
+
.env
|
8 |
+
|
9 |
+
# Ignore the virtual environment directory
|
10 |
+
venv/
|
11 |
+
|
12 |
+
# Ignore the pipenv virtual environment
|
13 |
+
Pipfile
|
14 |
+
Pipfile.lock
|
15 |
+
|
16 |
+
# Ignore generated files
|
17 |
+
*.pyc
|
18 |
+
*.pyo
|
19 |
+
*.pyd
|
20 |
+
*.so
|
21 |
+
*.egg-info/
|
22 |
+
dist/
|
23 |
+
build/
|
24 |
+
*.egg
|
25 |
+
|
26 |
+
# Ignore IDE and editor files
|
27 |
+
.idea/
|
28 |
+
.vscode/
|
29 |
+
*.sublime-project
|
30 |
+
*.sublime-workspace
|
31 |
+
|
32 |
+
# Ignore system-specific files
|
33 |
+
.DS_Store
|
34 |
+
Thumbs.db
|
35 |
+
|
36 |
+
# Ignore logs and other generated data
|
37 |
+
logs/
|
38 |
+
*.log
|
39 |
+
|
40 |
+
# Ignore any sensitive or private information
|
41 |
+
config.ini
|
42 |
+
secrets.json
|
43 |
+
|
44 |
+
# Ignore cache and temporary files
|
45 |
+
*.swp
|
46 |
+
*.swo
|
47 |
+
*.bak
|
48 |
+
*.cache
|
49 |
+
*.tmp
|
50 |
+
|
51 |
+
# Ignore dependency directories
|
52 |
+
lib/
|
53 |
+
libs/
|
app.py
CHANGED
@@ -1,7 +1,5 @@
|
|
1 |
import PIL.Image
|
2 |
import gradio as gr
|
3 |
-
import numpy as np
|
4 |
-
import cv2
|
5 |
from PIL import ImageOps
|
6 |
import requests
|
7 |
from pathlib import Path
|
@@ -11,17 +9,16 @@ import numpy as np
|
|
11 |
import io
|
12 |
import os
|
13 |
from random import choice
|
|
|
14 |
|
|
|
15 |
|
16 |
-
def get_mask(img_in):
|
17 |
|
18 |
-
|
19 |
|
20 |
-
#
|
21 |
img_in = img_in.convert("RGB")
|
22 |
|
23 |
-
# img_in_smol = img_in.resize((256, 256))
|
24 |
-
|
25 |
file_path = "/tmp/img_in.jpg"
|
26 |
img_in.save(file_path)
|
27 |
|
@@ -32,6 +29,12 @@ def get_mask(img_in):
|
|
32 |
response = requests.post(upload_url, files=files)
|
33 |
|
34 |
if response.status_code == 200:
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
result = response.json()
|
36 |
print('Result:', result)
|
37 |
|
@@ -56,7 +59,8 @@ def get_mask(img_in):
|
|
56 |
|
57 |
return (img_in, result['emotion'])
|
58 |
else:
|
59 |
-
|
|
|
60 |
|
61 |
|
62 |
footer = r"""
|
|
|
1 |
import PIL.Image
|
2 |
import gradio as gr
|
|
|
|
|
3 |
from PIL import ImageOps
|
4 |
import requests
|
5 |
from pathlib import Path
|
|
|
9 |
import io
|
10 |
import os
|
11 |
from random import choice
|
12 |
+
from dotenv import load_dotenv
|
13 |
|
14 |
+
load_dotenv()
|
15 |
|
|
|
16 |
|
17 |
+
def get_mask(img_in):
|
18 |
|
19 |
+
# print(f"{img_in=}")
|
20 |
img_in = img_in.convert("RGB")
|
21 |
|
|
|
|
|
22 |
file_path = "/tmp/img_in.jpg"
|
23 |
img_in.save(file_path)
|
24 |
|
|
|
29 |
response = requests.post(upload_url, files=files)
|
30 |
|
31 |
if response.status_code == 200:
|
32 |
+
|
33 |
+
if 'error' in response.json():
|
34 |
+
print(f"ERROR: {response.json()['error']}")
|
35 |
+
gr.Error(response.json()['error'])
|
36 |
+
return (None, None)
|
37 |
+
|
38 |
result = response.json()
|
39 |
print('Result:', result)
|
40 |
|
|
|
59 |
|
60 |
return (img_in, result['emotion'])
|
61 |
else:
|
62 |
+
gr.Error(response.text)
|
63 |
+
# print('error:', response.text)
|
64 |
|
65 |
|
66 |
footer = r"""
|
requirements.txt
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
-
onnx
|
2 |
-
onnxruntime-gpu
|
3 |
opencv-python
|
4 |
numpy
|
5 |
pillow~=9.5.0
|
6 |
-
|
|
|
|
|
|
|
|
1 |
opencv-python
|
2 |
numpy
|
3 |
pillow~=9.5.0
|
4 |
+
gradio
|
5 |
+
python-dotenv
|