Update app.py
Browse files
app.py
CHANGED
@@ -157,15 +157,8 @@ def htrflow_htr_url(image_path: str, document_type: FormatChoices = "letter_swed
|
|
157 |
|
158 |
Returns:
|
159 |
Tuple[str, str]: A tuple containing:
|
160 |
-
- JSON string with extracted text, file content
|
161 |
-
- File path for direct download via gr.File
|
162 |
-
|
163 |
-
JSON structure:
|
164 |
-
{
|
165 |
-
"text": "extracted_plain_text_here",
|
166 |
-
"content": "full_file_content_here",
|
167 |
-
"file_path": "[file_name](download_url)"
|
168 |
-
}
|
169 |
"""
|
170 |
if not image_path:
|
171 |
error_json = json.dumps({"error": "No image provided"})
|
@@ -213,16 +206,9 @@ def htrflow_htr_url(image_path: str, document_type: FormatChoices = "letter_swed
|
|
213 |
with open(output_file_path, 'r', encoding='utf-8') as f:
|
214 |
file_content = f.read()
|
215 |
|
216 |
-
file_name = Path(output_file_path).name
|
217 |
-
|
218 |
-
server_base = server_name.rstrip('/')
|
219 |
-
download_url = f"{server_base}/gradio_api/file={os.path.abspath(output_file_path)}"
|
220 |
-
markdown_link = f"[{file_name}]({download_url})"
|
221 |
-
|
222 |
result = {
|
223 |
"text": extracted_text,
|
224 |
"content": file_content,
|
225 |
-
"file_path": markdown_link
|
226 |
}
|
227 |
|
228 |
json_result = json.dumps(result, ensure_ascii=False, indent=2)
|
@@ -259,7 +245,7 @@ def create_htrflow_mcp_server():
|
|
259 |
gr.Textbox(label="HTR Result (JSON)", lines=10),
|
260 |
gr.File(label="Download HTR Output File")
|
261 |
],
|
262 |
-
description="Process handwritten text from uploaded file or URL and get both content and download link
|
263 |
api_name="htrflow_htr_url",
|
264 |
)
|
265 |
|
|
|
157 |
|
158 |
Returns:
|
159 |
Tuple[str, str]: A tuple containing:
|
160 |
+
- JSON string with extracted text, file content
|
161 |
+
- File path for direct download via gr.File (server_name/gradio_api/file=/tmp/gradio/{temp_folder}/{file_name})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
162 |
"""
|
163 |
if not image_path:
|
164 |
error_json = json.dumps({"error": "No image provided"})
|
|
|
206 |
with open(output_file_path, 'r', encoding='utf-8') as f:
|
207 |
file_content = f.read()
|
208 |
|
|
|
|
|
|
|
|
|
|
|
|
|
209 |
result = {
|
210 |
"text": extracted_text,
|
211 |
"content": file_content,
|
|
|
212 |
}
|
213 |
|
214 |
json_result = json.dumps(result, ensure_ascii=False, indent=2)
|
|
|
245 |
gr.Textbox(label="HTR Result (JSON)", lines=10),
|
246 |
gr.File(label="Download HTR Output File")
|
247 |
],
|
248 |
+
description="Process handwritten text from uploaded file or URL and get both content and download link for file",
|
249 |
api_name="htrflow_htr_url",
|
250 |
)
|
251 |
|