Spaces:
Sleeping
Sleeping
Commit ·
f78216c
0
Parent(s):
base gradio app
Browse files- .env.example +3 -0
- .gitattributes +1 -0
- README.md +0 -0
- docker/docker-compose.yml +0 -0
- planparser/app.py +42 -0
- pyproject.toml +11 -0
.env.example
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MODEL_DIR=models
|
| 2 |
+
MODEL_FILE=model.pt
|
| 3 |
+
GRADIO_WATCH_DIRS="planparser,src"
|
.gitattributes
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
*.jpg filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
File without changes
|
docker/docker-compose.yml
ADDED
|
File without changes
|
planparser/app.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
MODEL_DIR = os.getenv("MODEL_DIR", "models")
|
| 5 |
+
MODEL_FILE = os.getenv("MODEL_FILE", "model.pt")
|
| 6 |
+
|
| 7 |
+
_model = None
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def get_model_path() -> str:
|
| 11 |
+
path = os.path.join(MODEL_DIR, MODEL_FILE)
|
| 12 |
+
if not os.path.exists(path):
|
| 13 |
+
raise FileNotFoundError(
|
| 14 |
+
f"Model not found: {path}. Put the file there or set MODEL_DIR and MODEL_FILE."
|
| 15 |
+
)
|
| 16 |
+
return path
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def load_model():
|
| 20 |
+
global _model
|
| 21 |
+
if _model is not None:
|
| 22 |
+
return _model
|
| 23 |
+
import torch
|
| 24 |
+
|
| 25 |
+
_model = torch.jit.load(get_model_path(), map_location="cpu").eval()
|
| 26 |
+
return _model
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def predict(text: str) -> str:
|
| 30 |
+
_ = load_model()
|
| 31 |
+
return f"Loaded local model: {os.path.join(MODEL_DIR, MODEL_FILE)}. Input: {text}"
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
demo = gr.Interface(
|
| 35 |
+
fn=predict,
|
| 36 |
+
inputs=gr.Textbox(label="Input"),
|
| 37 |
+
outputs=gr.Textbox(label="Output"),
|
| 38 |
+
title="Minimal demo",
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
if __name__ == "__main__":
|
| 42 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|
pyproject.toml
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[project]
|
| 2 |
+
name = "planparser"
|
| 3 |
+
version = "0.1.0"
|
| 4 |
+
description = "Add your description here"
|
| 5 |
+
readme = "README.md"
|
| 6 |
+
requires-python = ">=3.12"
|
| 7 |
+
dependencies = [
|
| 8 |
+
"gradio>=6.2.0",
|
| 9 |
+
"torch>=2.9.1",
|
| 10 |
+
"torchvision>=0.24.1",
|
| 11 |
+
]
|