Spaces:
Running
Running
Improve error reporting, add dependency version info to status, and update README with local testing instructions
Browse files
README.md
CHANGED
@@ -53,3 +53,65 @@ python app.py
|
|
53 |
- **mermaid-cli**: Handles the actual diagram rendering
|
54 |
|
55 |
*Note: Hugging Face Spaces handles Node.js and mermaid-cli installation automatically.*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
- **mermaid-cli**: Handles the actual diagram rendering
|
54 |
|
55 |
*Note: Hugging Face Spaces handles Node.js and mermaid-cli installation automatically.*
|
56 |
+
|
57 |
+
---
|
58 |
+
|
59 |
+
## Local Testing
|
60 |
+
|
61 |
+
To test this project locally before deploying or pushing to Hugging Face Spaces, follow these steps:
|
62 |
+
|
63 |
+
1. **Create and activate a Python virtual environment**
|
64 |
+
|
65 |
+
On macOS/Linux:
|
66 |
+
```bash
|
67 |
+
python3 -m venv venv
|
68 |
+
source venv/bin/activate
|
69 |
+
```
|
70 |
+
|
71 |
+
On Windows:
|
72 |
+
```cmd
|
73 |
+
python -m venv venv
|
74 |
+
venv\Scripts\activate
|
75 |
+
```
|
76 |
+
|
77 |
+
2. **Upgrade pip (recommended)**
|
78 |
+
```bash
|
79 |
+
pip install --upgrade pip
|
80 |
+
```
|
81 |
+
|
82 |
+
3. **Install Python dependencies**
|
83 |
+
```bash
|
84 |
+
pip install -r requirements.txt
|
85 |
+
```
|
86 |
+
|
87 |
+
4. **Ensure Node.js is installed**
|
88 |
+
```bash
|
89 |
+
node --version
|
90 |
+
```
|
91 |
+
If not installed, download from [nodejs.org](https://nodejs.org/).
|
92 |
+
|
93 |
+
5. **Ensure @mermaid-js/mermaid-cli is installed globally**
|
94 |
+
```bash
|
95 |
+
npm install -g @mermaid-js/[email protected]
|
96 |
+
```
|
97 |
+
|
98 |
+
6. **Run the Gradio app**
|
99 |
+
```bash
|
100 |
+
python app.py
|
101 |
+
```
|
102 |
+
Gradio will print a local URL (e.g., http://127.0.0.1:7860/) in the terminal.
|
103 |
+
|
104 |
+
7. **Open the app in your browser**
|
105 |
+
Visit the local URL to interact with and test the interface.
|
106 |
+
|
107 |
+
When finished, you can deactivate the virtual environment with:
|
108 |
+
```bash
|
109 |
+
deactivate
|
110 |
+
```
|
111 |
+
|
112 |
+
**Note:**
|
113 |
+
If you accidentally added the `venv` folder to git, remove it from tracking with:
|
114 |
+
```bash
|
115 |
+
git rm -r --cached venv
|
116 |
+
git commit -m "Stop tracking venv directory"
|
117 |
+
```
|
app.py
CHANGED
@@ -141,6 +141,38 @@ with gr.Blocks(title="Mermaid Diagram Renderer", theme=gr.themes.Soft()) as demo
|
|
141 |
except Exception as png_err:
|
142 |
logging.warning(f"Could not OCR PNG for errors: {png_err}")
|
143 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
144 |
return preview_path, output_path, status_message
|
145 |
|
146 |
except Exception as e:
|
|
|
141 |
except Exception as png_err:
|
142 |
logging.warning(f"Could not OCR PNG for errors: {png_err}")
|
143 |
|
144 |
+
# Gather dependency versions for debugging
|
145 |
+
import platform
|
146 |
+
dep_versions = []
|
147 |
+
try:
|
148 |
+
import gradio
|
149 |
+
dep_versions.append(f"gradio {gradio.__version__}")
|
150 |
+
except Exception:
|
151 |
+
dep_versions.append("gradio N/A")
|
152 |
+
try:
|
153 |
+
import pytesseract
|
154 |
+
dep_versions.append(f"pytesseract {pytesseract.__version__}")
|
155 |
+
except Exception:
|
156 |
+
dep_versions.append("pytesseract N/A")
|
157 |
+
try:
|
158 |
+
from PIL import __version__ as pillow_version
|
159 |
+
dep_versions.append(f"Pillow {pillow_version}")
|
160 |
+
except Exception:
|
161 |
+
dep_versions.append("Pillow N/A")
|
162 |
+
try:
|
163 |
+
node_ver = subprocess.run(["node", "--version"], capture_output=True, text=True)
|
164 |
+
dep_versions.append(f"Node.js {node_ver.stdout.strip()}")
|
165 |
+
except Exception:
|
166 |
+
dep_versions.append("Node.js N/A")
|
167 |
+
try:
|
168 |
+
mmdc_ver = subprocess.run(["mmdc", "--version"], capture_output=True, text=True)
|
169 |
+
dep_versions.append(f"mmdc {mmdc_ver.stdout.strip()}")
|
170 |
+
except Exception:
|
171 |
+
dep_versions.append("mmdc N/A")
|
172 |
+
dep_versions.append(f"Python {platform.python_version()}")
|
173 |
+
dep_info = " | ".join(dep_versions)
|
174 |
+
status_message = f"{status_message}\n\nDependencies: {dep_info}"
|
175 |
+
|
176 |
return preview_path, output_path, status_message
|
177 |
|
178 |
except Exception as e:
|