fix: make huggingface space happy
Browse files- Dockerfile +16 -3
- demo.py +9 -2
Dockerfile
CHANGED
|
@@ -1,7 +1,20 @@
|
|
| 1 |
FROM docker.io/jeffersonqin/yuzumarker.fontdetection.huggingfacespace.base:latest
|
| 2 |
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
FROM docker.io/jeffersonqin/yuzumarker.fontdetection.huggingfacespace.base:latest
|
| 2 |
|
| 3 |
+
RUN useradd -m -u 1000 user
|
| 4 |
+
USER user
|
| 5 |
+
ENV HOME=/home/user \
|
| 6 |
+
PATH=/home/user/.local/bin:$PATH
|
| 7 |
|
| 8 |
+
WORKDIR $HOME/app
|
| 9 |
+
USER root
|
| 10 |
+
RUN mv /workspace/font_demo_cache.bin $HOME/app/font_demo_cache.bin
|
| 11 |
+
RUN mv /workspace/demo_fonts $HOME/app/demo_fonts
|
| 12 |
|
| 13 |
+
USER user
|
| 14 |
+
COPY --chown=user detector $HOME/app/detector
|
| 15 |
+
COPY --chown=user font_dataset $HOME/app/font_dataset
|
| 16 |
+
COPY --chown=user utils $HOME/app/utils
|
| 17 |
+
COPY --chown=user configs $HOME/app/configs
|
| 18 |
+
COPY --chown=user demo.py $HOME/app/demo.py
|
| 19 |
+
|
| 20 |
+
CMD ["python", "demo.py", "-d", "-1", "-c", "huggingface://gyrojeff/YuzuMarker.FontDetection/commit=bc0f7fc-epoch=26-step=261954.ckpt", "-m", "resnet50", "-z", "512", "-p", "7860", "-a", "0.0.0.0"]
|
demo.py
CHANGED
|
@@ -58,6 +58,13 @@ parser.add_argument(
|
|
| 58 |
default=7860,
|
| 59 |
help="Port to use for Gradio (default: 7860)",
|
| 60 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
args = parser.parse_args()
|
| 63 |
|
|
@@ -84,6 +91,7 @@ else:
|
|
| 84 |
|
| 85 |
if torch.__version__ >= "2.0" and os.name == "posix":
|
| 86 |
model = torch.compile(model)
|
|
|
|
| 87 |
|
| 88 |
|
| 89 |
if str(args.checkpoint).startswith("huggingface://"):
|
|
@@ -92,7 +100,6 @@ if str(args.checkpoint).startswith("huggingface://"):
|
|
| 92 |
repo = f"{user}/{repo}"
|
| 93 |
args.checkpoint = hf_hub_download(repo, file)
|
| 94 |
|
| 95 |
-
|
| 96 |
detector = FontDetector(
|
| 97 |
model=model,
|
| 98 |
lambda_font=1,
|
|
@@ -205,4 +212,4 @@ with gr.Blocks() as demo:
|
|
| 205 |
)
|
| 206 |
|
| 207 |
|
| 208 |
-
demo.launch(share=args.share, server_port=args.port)
|
|
|
|
| 58 |
default=7860,
|
| 59 |
help="Port to use for Gradio (default: 7860)",
|
| 60 |
)
|
| 61 |
+
parser.add_argument(
|
| 62 |
+
"-a",
|
| 63 |
+
"--address",
|
| 64 |
+
type=str,
|
| 65 |
+
default="127.0.0.1",
|
| 66 |
+
help="Address to use for Gradio (default: 127.0.0.1)",
|
| 67 |
+
)
|
| 68 |
|
| 69 |
args = parser.parse_args()
|
| 70 |
|
|
|
|
| 91 |
|
| 92 |
if torch.__version__ >= "2.0" and os.name == "posix":
|
| 93 |
model = torch.compile(model)
|
| 94 |
+
torch._dynamo.config.suppress_errors = True
|
| 95 |
|
| 96 |
|
| 97 |
if str(args.checkpoint).startswith("huggingface://"):
|
|
|
|
| 100 |
repo = f"{user}/{repo}"
|
| 101 |
args.checkpoint = hf_hub_download(repo, file)
|
| 102 |
|
|
|
|
| 103 |
detector = FontDetector(
|
| 104 |
model=model,
|
| 105 |
lambda_font=1,
|
|
|
|
| 212 |
)
|
| 213 |
|
| 214 |
|
| 215 |
+
demo.launch(share=args.share, server_port=args.port, server_name=args.address)
|