Update app.py
Browse files
app.py
CHANGED
|
@@ -10,7 +10,11 @@ from htrflow.volume.volume import Collection
|
|
| 10 |
from htrflow.pipeline.pipeline import Pipeline
|
| 11 |
|
| 12 |
DEFAULT_OUTPUT = "alto"
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
PIPELINE_CONFIGS = {
|
| 16 |
"letter_english": {
|
|
@@ -116,7 +120,7 @@ PIPELINE_CONFIGS = {
|
|
| 116 |
}
|
| 117 |
|
| 118 |
@spaces.GPU
|
| 119 |
-
def htrflow_htr_url(image_path: str, document_type:
|
| 120 |
"""
|
| 121 |
Process handwritten text recognition (HTR) on uploaded images and return both file content and download link.
|
| 122 |
|
|
@@ -152,7 +156,7 @@ def htrflow_htr_url(image_path: str, document_type: Literal["letter_english", "l
|
|
| 152 |
str: JSON string containing both the file content and download link:
|
| 153 |
{
|
| 154 |
"content": "file_content_here",
|
| 155 |
-
"file_path": "[file_name](
|
| 156 |
}
|
| 157 |
"""
|
| 158 |
if not image_path:
|
|
@@ -198,9 +202,10 @@ def htrflow_htr_url(image_path: str, document_type: Literal["letter_english", "l
|
|
| 198 |
file_content = f.read()
|
| 199 |
|
| 200 |
|
|
|
|
| 201 |
file_name = Path(output_file_path).name
|
| 202 |
-
|
| 203 |
-
markdown_link = f"[{file_name}](
|
| 204 |
|
| 205 |
result = {
|
| 206 |
"content": file_content,
|
|
@@ -231,8 +236,8 @@ def create_htrflow_mcp_server():
|
|
| 231 |
fn=htrflow_htr_url,
|
| 232 |
inputs=[
|
| 233 |
gr.Image(type="filepath", label="Upload Image or Enter URL"),
|
| 234 |
-
gr.Dropdown(choices=
|
| 235 |
-
gr.Dropdown(choices=
|
| 236 |
gr.Textbox(label="Custom Settings (JSON)", placeholder="Optional custom pipeline settings", value=""),
|
| 237 |
],
|
| 238 |
outputs=gr.Textbox(label="HTR Result (JSON)", lines=10),
|
|
|
|
| 10 |
from htrflow.pipeline.pipeline import Pipeline
|
| 11 |
|
| 12 |
DEFAULT_OUTPUT = "alto"
|
| 13 |
+
FORMAT_CHOICES = ["letter_english", "letter_swedish", "spread_english", "spread_swedish"]
|
| 14 |
+
FILE_CHOICES = ["txt", "alto", "page", "json"]
|
| 15 |
+
|
| 16 |
+
FormatChoices = Literal["letter_english", "letter_swedish", "spread_english", "spread_swedish"]
|
| 17 |
+
FileChoices = Literal["txt", "alto", "page", "json"]
|
| 18 |
|
| 19 |
PIPELINE_CONFIGS = {
|
| 20 |
"letter_english": {
|
|
|
|
| 120 |
}
|
| 121 |
|
| 122 |
@spaces.GPU
|
| 123 |
+
def htrflow_htr_url(image_path: str, document_type: FormatChoices = "letter_swedish", output_format: FileChoices = DEFAULT_OUTPUT, custom_settings: Optional[str] = None, server_name= "https://gabriel-htrflow-mcp.hf.space/") -> str:
|
| 124 |
"""
|
| 125 |
Process handwritten text recognition (HTR) on uploaded images and return both file content and download link.
|
| 126 |
|
|
|
|
| 156 |
str: JSON string containing both the file content and download link:
|
| 157 |
{
|
| 158 |
"content": "file_content_here",
|
| 159 |
+
"file_path": "[file_name](https://gabriel-htrflow-mcp.hf.space/gradio_api/file=/tmp/{temp-folder}/{file-name}.{file-format})"
|
| 160 |
}
|
| 161 |
"""
|
| 162 |
if not image_path:
|
|
|
|
| 202 |
file_content = f.read()
|
| 203 |
|
| 204 |
|
| 205 |
+
|
| 206 |
file_name = Path(output_file_path).name
|
| 207 |
+
download_url = f"{server_name}/gradio_api/file={output_file_path}"
|
| 208 |
+
markdown_link = f"[{file_name}]({download_url})"
|
| 209 |
|
| 210 |
result = {
|
| 211 |
"content": file_content,
|
|
|
|
| 236 |
fn=htrflow_htr_url,
|
| 237 |
inputs=[
|
| 238 |
gr.Image(type="filepath", label="Upload Image or Enter URL"),
|
| 239 |
+
gr.Dropdown(choices=FORMAT_CHOICES, value="letter_swedish", label="Document Type"),
|
| 240 |
+
gr.Dropdown(choices=FILE_CHOICES, value=DEFAULT_OUTPUT, label="Output Format"),
|
| 241 |
gr.Textbox(label="Custom Settings (JSON)", placeholder="Optional custom pipeline settings", value=""),
|
| 242 |
],
|
| 243 |
outputs=gr.Textbox(label="HTR Result (JSON)", lines=10),
|