From 0476f5e01acdd4073718718bf5698e955cb9f6c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Erman?= Date: Sat, 13 Jun 2026 00:06:34 +0300 Subject: [PATCH] =?UTF-8?q?Windows=2011=20Fluent=20GUI=20entegrasyonu=20ve?= =?UTF-8?q?=20=C3=A7ok=20dilli=20destek=20eklendi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 156 +------ README.md | 401 +++--------------- build_exe.bat | 25 ++ gui/markitdown_gui.py | 277 ++++++++++++ .../markitdown/converters/_docx_converter.py | 115 ++--- .../src/markitdown/converters/_markdownify.py | 32 ++ requirements.txt | 7 + run_gui.bat | 4 + test_sample.txt | Bin 0 -> 82 bytes 9 files changed, 488 insertions(+), 529 deletions(-) create mode 100644 build_exe.bat create mode 100644 gui/markitdown_gui.py create mode 100644 requirements.txt create mode 100644 run_gui.bat create mode 100644 test_sample.txt diff --git a/.gitignore b/.gitignore index 15613ea8a..1c8ba11e0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,15 +1,10 @@ -.vscode - -# Byte-compiled / optimized / DLL files +# Python __pycache__/ *.py[cod] *$py.class - -# C extensions *.so - -# Distribution / packaging .Python +env/ build/ develop-eggs/ dist/ @@ -28,141 +23,32 @@ share/python-wheels/ *.egg MANIFEST -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.nox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -*.py,cover -.hypothesis/ -.pytest_cache/ -cover/ -.test-logs/ - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py -db.sqlite3 -db.sqlite3-journal - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ - -# PyBuilder -.pybuilder/ -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# IPython -profile_default/ -ipython_config.py - -# pyenv -# For a library or package, you might want to ignore these files since the code is -# intended to run in multiple environments; otherwise, check them in: -# .python-version - -# pipenv -# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. -# However, in case of collaboration, if having platform-specific dependencies or dependencies -# having no cross-platform support, pipenv may install dependencies that don't work, or not -# install all needed dependencies. -#Pipfile.lock - -# poetry -# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. -# This is especially recommended for binary packages to ensure reproducibility, and is more -# commonly ignored for libraries. -# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control -#poetry.lock - -# pdm -# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. -#pdm.lock -# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it -# in version control. -# https://pdm.fming.dev/latest/usage/project/#working-with-version-control -.pdm.toml -.pdm-python -.pdm-build/ - -# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm -__pypackages__/ - -# Celery stuff -celerybeat-schedule -celerybeat.pid - -# SageMath parsed files -*.sage.py - -# Environments -.env -.venv -env/ +# Virtual Environment venv/ ENV/ env.bak/ venv.bak/ -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ -.dmypy.json -dmypy.json +# Logs +*.log +markitdown_gui.log -# Pyre type checker -.pyre/ +# PyInstaller +*.spec -# pytype static type analyzer -.pytype/ +# IDEs +.idea/ +.vscode/ +*.swp +*.swo -# Cython debug symbols -cython_debug/ +# Project Specific +*.md +!README.md +gui/logo.png +# (Logo.png dosyasini istersen repoda tutabilirsin, o yüzden yukardakini yoruma alabiliriz) +# !gui/logo.png -# PyCharm -# JetBrains specific template is maintained in a separate JetBrains.gitignore that can -# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore -# and can be added to the global gitignore or merged into this file. For a more nuclear -# option (not recommended) you can uncomment the following to ignore the entire idea folder. -#.idea/ -src/.DS_Store +# Temporary files .DS_Store -.cursorrules +Thumbs.db diff --git a/README.md b/README.md index aa2f58bb8..6f21214f3 100644 --- a/README.md +++ b/README.md @@ -1,360 +1,73 @@ -# MarkItDown +# MarkItDown Desktop GUI -[![PyPI](https://img.shields.io/pypi/v/markitdown.svg)](https://pypi.org/project/markitdown/) -![PyPI - Downloads](https://img.shields.io/pypi/dd/markitdown) -[![Built by AutoGen Team](https://img.shields.io/badge/Built%20by-AutoGen%20Team-blue)](https://github.com/microsoft/autogen) +A production-ready, modern Windows desktop application for **Microsoft MarkItDown**, built with **Python**, **PyQt6**, and the **Fluent Design** system (via `qfluentwidgets`). -> [!IMPORTANT] -> MarkItDown performs I/O with the privileges of the current process. Like open() or requests.get(), it will access resources that the process itself can access. Sanitize your inputs in untrusted environments, and call the narrowest `convert_*` function needed for your use case (e.g., `convert_stream()`, or `convert_local()`). See the [Security Considerations](#security-considerations) section of the documentation for more information. +This tool allows you to convert complex documents (PDF, Word, Excel, PowerPoint, etc.) into clean, high-fidelity Markdown files with advanced handling for tables and images. -MarkItDown is a lightweight Python utility for converting various files to Markdown for use with LLMs and related text analysis pipelines. To this end, it is most comparable to [textract](https://github.com/deanmalmgren/textract), but with a focus on preserving important document structure and content as Markdown (including: headings, lists, tables, links, etc.) While the output is often reasonably presentable and human-friendly, it is meant to be consumed by text analysis tools -- and may not be the best option for high-fidelity document conversions for human consumption. +![App Preview](gui/logo.png) -MarkItDown currently supports the conversion from: +## 🚀 Key Features -- PDF -- PowerPoint -- Word -- Excel -- Images (EXIF metadata and OCR) -- Audio (EXIF metadata and speech transcription) -- HTML -- Text-based formats (CSV, JSON, XML) -- ZIP files (iterates over contents) -- Youtube URLs -- EPubs -- ... and more! +- **Fluent Design UI:** A sleek, Windows 11-style dark mode interface. +- **Smart Table Recovery:** Custom-tuned logic to preserve complex multi-column tables as readable text blocks instead of broken layouts. +- **Hybrid Image Management:** + - Small images (<50KB) are embedded as **Base64** within the Markdown file. + - Large images are automatically extracted to a dedicated `[filename]_assets` folder. +- **Automatic Language Detection:** Detects your Windows system language and adapts the UI (Supports English, Turkish, Spanish, French, German, and Chinese). +- **Audio Transcription:** Convert MP3/WAV files to text using built-in speech recognition (requires FFmpeg). +- **Asynchronous Processing:** Non-blocking file conversions with real-time UI logging and progress tracking. -## Why Markdown? +## 🛠️ Supported Formats -Markdown is extremely close to plain text, with minimal markup or formatting, but still -provides a way to represent important document structure. Mainstream LLMs, such as -OpenAI's GPT-4o, natively "_speak_" Markdown, and often incorporate Markdown into their -responses unprompted. This suggests that they have been trained on vast amounts of -Markdown-formatted text, and understand it well. As a side benefit, Markdown conventions -are also highly token-efficient. +- **Documents:** PDF, DOCX, XLSX, PPTX +- **Data:** CSV, JSON, XML +- **Web:** HTML, RSS, Wikipedia, YouTube (transcripts) +- **Multimedia:** MP3, WAV (Audio), JPG, PNG (OCR) +- **Archives:** ZIP, EPUB -## Prerequisites -MarkItDown requires Python 3.10 or higher. It is recommended to use a virtual environment to avoid dependency conflicts. +## 📦 Installation -With the standard Python installation, you can create and activate a virtual environment using the following commands: - -```bash -python -m venv .venv -source .venv/bin/activate -``` - -If using `uv`, you can create a virtual environment with: - -```bash -uv venv --python=3.12 .venv -source .venv/bin/activate -# NOTE: Be sure to use 'uv pip install' rather than just 'pip install' to install packages in this virtual environment -``` - -If you are using Anaconda, you can create a virtual environment with: - -```bash -conda create -n markitdown python=3.12 -conda activate markitdown -``` - -## Installation - -To install MarkItDown, use pip: `pip install 'markitdown[all]'`. Alternatively, you can install it from the source: - -```bash -git clone git@github.com:microsoft/markitdown.git -cd markitdown -pip install -e 'packages/markitdown[all]' -``` - -## Usage - -### Command-Line - -```bash -markitdown path-to-file.pdf > document.md -``` - -Or use `-o` to specify the output file: - -```bash -markitdown path-to-file.pdf -o document.md -``` - -You can also pipe content: - -```bash -cat path-to-file.pdf | markitdown -``` - -### Optional Dependencies -MarkItDown has optional dependencies for activating various file formats. Earlier in this document, we installed all optional dependencies with the `[all]` option. However, you can also install them individually for more control. For example: - -```bash -pip install 'markitdown[pdf, docx, pptx]' -``` - -will install only the dependencies for PDF, DOCX, and PPTX files. - -At the moment, the following optional dependencies are available: - -* `[all]` Installs all optional dependencies -* `[pptx]` Installs dependencies for PowerPoint files -* `[docx]` Installs dependencies for Word files -* `[xlsx]` Installs dependencies for Excel files -* `[xls]` Installs dependencies for older Excel files -* `[pdf]` Installs dependencies for PDF files -* `[outlook]` Installs dependencies for Outlook messages -* `[az-doc-intel]` Installs dependencies for Azure Document Intelligence -* `[az-content-understanding]` Installs dependencies for Azure Content Understanding -* `[audio-transcription]` Installs dependencies for audio transcription of wav and mp3 files -* `[youtube-transcription]` Installs dependencies for fetching YouTube video transcription - -### Plugins - -MarkItDown also supports 3rd-party plugins. Plugins are disabled by default. To list installed plugins: - -```bash -markitdown --list-plugins -``` - -To enable plugins use: - -```bash -markitdown --use-plugins path-to-file.pdf -``` - -To find available plugins, search GitHub for the hashtag `#markitdown-plugin`. To develop a plugin, see `packages/markitdown-sample-plugin`. - -#### markitdown-ocr Plugin - -The `markitdown-ocr` plugin adds OCR support to PDF, DOCX, PPTX, and XLSX converters, extracting text from embedded images using LLM Vision — the same `llm_client` / `llm_model` pattern that MarkItDown already uses for image descriptions. No new ML libraries or binary dependencies required. - -**Installation:** - -```bash -pip install markitdown-ocr -pip install openai # or any OpenAI-compatible client -``` - -**Usage:** - -Pass the same `llm_client` and `llm_model` you would use for image descriptions: - -```python -from markitdown import MarkItDown -from openai import OpenAI - -md = MarkItDown( - enable_plugins=True, - llm_client=OpenAI(), - llm_model="gpt-4o", -) -result = md.convert("document_with_images.pdf") -print(result.text_content) -``` - -If no `llm_client` is provided the plugin still loads, but OCR is silently skipped and the standard built-in converter is used instead. - -See [`packages/markitdown-ocr/README.md`](packages/markitdown-ocr/README.md) for detailed documentation. - -### Azure Content Understanding - -[Azure Content Understanding](https://learn.microsoft.com/azure/ai-services/content-understanding/) provides higher-quality conversion with structured field extraction (YAML front matter), multi-modal support (documents, images, audio, video), and configurable analyzers. - -Install: `pip install 'markitdown[az-content-understanding]'` - -#### When to use Content Understanding - -Content Understanding is ideal when you need capabilities beyond what built-in or Document Intelligence converters provide: - -- **Audio and video files** — CU is the only option for video, and the higher-quality cloud option for audio. Built-in converters have no video support and only basic audio transcription. -- **Structured field extraction** — [Prebuilt](https://learn.microsoft.com/azure/ai-services/content-understanding/concepts/prebuilt-analyzers) or [custom-built](https://learn.microsoft.com/azure/ai-services/content-understanding/how-to/customize-analyzer-content-understanding-studio?tabs=portal) analyzers extract domain-specific fields (invoice amounts, receipt dates, contract clauses) serialized as YAML front matter. Neither built-in nor Doc Intel integration exposes fields. -- **Higher-quality document extraction** — Cloud-based layout analysis and OCR for scanned PDFs, complex tables, and multi-page documents. -- **Single API for all modalities** — One `cu_endpoint` handles documents, images, audio, and video with automatic analyzer routing. - -| Capability | Built-in converters | Azure Document Intelligence | Azure Content Understanding | -|------------|---------------------|-----------------------------|-----------------------------| -| Document conversion | Offline, format-specific extraction | Cloud layout extraction | Cloud multimodal extraction | -| Structured fields | Not available | Not exposed by this integration | YAML front matter from analyzer fields | -| Custom analyzers | Not available | Not configurable in this integration | Supported with `cu_analyzer_id` | -| Audio and video | Basic audio, no video | Not supported | Audio and video analyzers | -| Cost | Local compute only | Billable Azure API calls | Billable Azure API calls | - -**CLI:** - -```bash -markitdown path-to-file.pdf --use-cu --cu-endpoint "" -``` - -**Python API:** - -```python -from markitdown import MarkItDown - -# Zero-config — auto-selects analyzer per file type -md = MarkItDown(cu_endpoint="") -result = md.convert("report.pdf") # documents → prebuilt-documentSearch -result = md.convert("meeting.mp4") # video → prebuilt-videoSearch -result = md.convert("call.wav") # audio → prebuilt-audioSearch -print(result.markdown) -``` - -**With a custom analyzer** (for domain-specific field extraction): - -```python -md = MarkItDown( - cu_endpoint="", - cu_analyzer_id="my-invoice-analyzer", -) -result = md.convert("invoice.pdf") -print(result.markdown) -# Output includes YAML front matter with extracted fields: -# --- -# contentType: document -# fields: -# VendorName: CONTOSO LTD. -# InvoiceDate: '2019-11-15' -# --- -# -# ... -``` - -When `cu_analyzer_id` is set, the converter automatically scopes it to compatible file types based on the analyzer's modality. Incompatible types (e.g., audio files with a document analyzer) auto-route to default prebuilt analyzers. - -**Cost note:** Each `convert()` call for a CU-routed format is a billable Azure API call. Use `cu_file_types` to restrict which formats route to CU: - -```python -from markitdown.converters import ContentUnderstandingFileType - -md = MarkItDown( - cu_endpoint="", - cu_file_types=[ContentUnderstandingFileType.PDF], # only PDFs use CU -) -``` - -More information about Azure Content Understanding can be found [here](https://learn.microsoft.com/azure/ai-services/content-understanding/). - -### Azure Document Intelligence - -To use Microsoft Document Intelligence for conversion: +### Prerequisites +- **Python 3.10+** +- **FFmpeg** (Required for audio files): + ```powershell + winget install ffmpeg + ``` +### Local Setup +1. Clone the repository: + ```bash + git clone https://github.com/omererman/markitdown-desktop.git + cd markitdown-desktop + ``` +2. Create a virtual environment: + ```bash + python -m venv venv + .\venv\Scripts\activate + ``` +3. Install dependencies: + ```bash + pip install -r requirements.txt + pip install -e "./packages/markitdown[all]" + ``` +4. Run the app: + ```bash + .\run_gui.bat + ``` + +## 🔨 Build Standalone EXE + +To generate a standalone executable for Windows: ```bash -markitdown path-to-file.pdf -o document.md -d -e "" -``` - -More information about how to set up an Azure Document Intelligence Resource can be found [here](https://learn.microsoft.com/en-us/azure/ai-services/document-intelligence/how-to-guides/create-document-intelligence-resource?view=doc-intel-4.0.0) - -### Python API - -Basic usage in Python: - -```python -from markitdown import MarkItDown - -md = MarkItDown(enable_plugins=False) # Set to True to enable plugins -result = md.convert("test.xlsx") -print(result.text_content) -``` - -Document Intelligence conversion in Python: - -```python -from markitdown import MarkItDown - -md = MarkItDown(docintel_endpoint="") -result = md.convert("test.pdf") -print(result.text_content) +.\build_exe.bat ``` +The resulting file will be in the `dist/` directory. -To use Large Language Models for image descriptions (currently only for pptx and image files), provide `llm_client` and `llm_model`: - -```python -from markitdown import MarkItDown -from openai import OpenAI - -client = OpenAI() -md = MarkItDown(llm_client=client, llm_model="gpt-4o", llm_prompt="optional custom prompt") -result = md.convert("example.jpg") -print(result.text_content) -``` - -### Docker - -```sh -docker build -t markitdown:latest . -docker run --rm -i markitdown:latest < ~/your-file.pdf > output.md -``` - -## Contributing - -This project welcomes contributions and suggestions. Most contributions require you to agree to a -Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us -the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com. - -When you submit a pull request, a CLA bot will automatically determine whether you need to provide -a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions -provided by the bot. You will only need to do this once across all repos using our CLA. - -This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). -For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or -contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. - -### How to Contribute - -You can help by looking at issues or helping review PRs. Any issue or PR is welcome, but we have also marked some as 'open for contribution' and 'open for reviewing' to help facilitate community contributions. These are of course just suggestions and you are welcome to contribute in any way you like. - -
- -| | All | Especially Needs Help from Community | -| ---------- | ------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------- | -| **Issues** | [All Issues](https://github.com/microsoft/markitdown/issues) | [Issues open for contribution](https://github.com/microsoft/markitdown/issues?q=is%3Aissue+is%3Aopen+label%3A%22open+for+contribution%22) | -| **PRs** | [All PRs](https://github.com/microsoft/markitdown/pulls) | [PRs open for reviewing](https://github.com/microsoft/markitdown/pulls?q=is%3Apr+is%3Aopen+label%3A%22open+for+reviewing%22) | - -
- -### Running Tests and Checks - -- Navigate to the MarkItDown package: - - ```sh - cd packages/markitdown - ``` - -- Install `hatch` in your environment and run tests: - - ```sh - pip install hatch # Other ways of installing hatch: https://hatch.pypa.io/dev/install/ - hatch shell - hatch test - ``` - - (Alternative) Use the Devcontainer which has all the dependencies installed: - - ```sh - # Reopen the project in Devcontainer and run: - hatch test - ``` - -- Run pre-commit checks before submitting a PR: `pre-commit run --all-files` - -### Security Considerations - -MarkItDown performs I/O with the privileges of the current process. Like `open()` or `requests.get()`, it will access resources that the process itself can access. - -**Sanitize your inputs:** Do not pass untrusted input directly to MarkItDown. If any part of the input may be controlled by an untrusted user or system, such as in hosted or server-side applications, it must be validated and restricted before calling MarkItDown. Depending on your environment, this may include restricting file paths, limiting URI schemes and network destinations, and blocking access to private, loopback, link-local, or metadata-service addresses. - -**Call only the conversion method you need:** Prefer the narrowest conversion API that fits your use case. MarkItDown's `convert()` method is intentionally permissive and can handle local files, remote URIs, and byte streams. If your application only needs to read local files, call `convert_local()` instead. If you need more control over URI fetching, call `requests.get()` yourself and pass the response object to `convert_response()`. For maximum control, open a stream to the input you want converted and call `convert_stream()`. - -### Contributing 3rd-party Plugins +## 🤝 Credits -You can also contribute by creating and sharing 3rd party plugins. See `packages/markitdown-sample-plugin` for more details. +Developed by **[OMER ERMAN](https://github.com/omererman)**. +Powered by **Microsoft MarkItDown** and **PyQt6-Fluent-Widgets**. -## Trademarks +## 📄 License -This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft -trademarks or logos is subject to and must follow -[Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general). -Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. -Any use of third-party trademarks or logos are subject to those third-party's policies. +This project is licensed under the MIT License - see the LICENSE file for details. diff --git a/build_exe.bat b/build_exe.bat new file mode 100644 index 000000000..b2c71ee47 --- /dev/null +++ b/build_exe.bat @@ -0,0 +1,25 @@ +@echo off +set ICON_PATH=gui\logo.png +set MAGIKA_PATH=venv\Lib\site-packages\magika + +:: Google API ve diger agir kutuphaneleri cikariyoruz. +:: Bu kutuphaneler markitdown'in Google Drive/Bing destegi icin gerekli ama biz kullanmiyoruz. +.\venv\Scripts\pyinstaller --noconsole --onefile ^ + --icon=%ICON_PATH% ^ + --add-data "gui;gui" ^ + --add-data "%MAGIKA_PATH%;magika" ^ + --exclude-module googleapiclient ^ + --exclude-module google_auth_oauthlib ^ + --exclude-module google ^ + --exclude-module oauth2client ^ + --exclude-module openai ^ + --exclude-module matplotlib ^ + --exclude-module networkx ^ + --exclude-module notebook ^ + --exclude-module jedi ^ + --name "MarkItDownDesktop" ^ + gui\markitdown_gui.py + +echo. +echo Ultra Optimize edilmis Build tamamlandi! +pause diff --git a/gui/markitdown_gui.py b/gui/markitdown_gui.py new file mode 100644 index 000000000..cb97eb06b --- /dev/null +++ b/gui/markitdown_gui.py @@ -0,0 +1,277 @@ +import sys +import os +import warnings +import re +import logging +import base64 +import hashlib +from datetime import datetime + +# ffmpeg uyarısını sustur +warnings.filterwarnings("ignore", category=RuntimeWarning, module="pydub") + +# --- LOGGING --- +log_filename = "markitdown_gui.log" +logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s', handlers=[logging.FileHandler(log_filename, encoding='utf-8'), logging.StreamHandler(sys.stdout)]) + +# --- FFmpeg CONFIG --- +def configure_ffmpeg(): + winget_ffmpeg = r"C:\Users\tcoerman\AppData\Local\Microsoft\WinGet\Packages\Gyan.FFmpeg_Microsoft.Winget.Source_8wekyb3d8bbwe\ffmpeg-8.1.1-full_build\bin" + if os.path.exists(winget_ffmpeg): + os.environ["PATH"] += os.pathsep + winget_ffmpeg + try: + from pydub import AudioSegment + AudioSegment.converter = os.path.join(winget_ffmpeg, "ffmpeg.exe") + logging.info(f"FFmpeg configured: {winget_ffmpeg}") + except: pass + +configure_ffmpeg() + +# --- SILENCER --- +class SilenceStdout: + def __enter__(self): + self._original_stdout = sys.stdout + sys.stdout = open(os.devnull, "w") + def __exit__(self, exc_type, exc_val, exc_tb): + sys.stdout.close() + sys.stdout = self._original_stdout + +with SilenceStdout(): + from qfluentwidgets import ( + TitleLabel, SubtitleLabel, PrimaryPushButton, CardWidget, + ProgressBar, InfoBar, InfoBarPosition, ComboBox, + setTheme, Theme, setThemeColor, StrongBodyLabel, IconWidget, + BodyLabel, TextEdit, TransparentPushButton, ImageLabel, Flyout, FlyoutView, FlyoutAnimationType + ) + from qfluentwidgets import FluentIcon as FIF + +from PyQt6.QtCore import Qt, QThread, pyqtSignal, QLocale, QUrl +from PyQt6.QtGui import QDragEnterEvent, QDropEvent, QColor, QFont, QIcon, QDesktopServices +from PyQt6.QtWidgets import QApplication, QVBoxLayout, QHBoxLayout, QFileDialog, QWidget, QMainWindow, QLabel +from markitdown import MarkItDown + +# --- APP CONFIG --- +GITHUB_URL = "https://github.com/omererman/markitdown-desktop" +DEVELOPER_NAME = "OMER ERMAN" +VERSION = "v1.0.0" + +TRANSLATIONS = { + "English": { + "title": "MarkItDown", "subtitle": "Convert complex documents to Markdown", "drop_text": "Select a File or Drag & Drop Here", "success_title": "Success", "success_msg": "File saved: ", "error_title": "Error", "error_msg": "An error occurred: ", "select_file": "Select File", "logs": "Action Logs", "auto_detect": "System language: English", "about_title": "About This App", "about_dev": "Developed by", "about_desc": "A professional tool for high-fidelity document conversion.", "about_tech": "Built with Microsoft MarkItDown & PyQt6" + }, + "Türkçe": { + "title": "MarkItDown", "subtitle": "Karmaşık belgeleri MD'ye dönüştürün", "drop_text": "Bir Dosya Seçin veya Üzerine Sürükleyin", "success_title": "İşlem Başarılı", "success_msg": "Dosya kaydedildi: ", "error_title": "Hata", "error_msg": "Bir hata oluştu: ", "select_file": "Dosya Seç", "logs": "İşlem Kayıtları", "auto_detect": "Sistem dili: Türkçe", "about_title": "Uygulama Hakkında", "about_dev": "Geliştiren", "about_desc": "Yüksek kaliteli döküman dönüşümü için profesyonel araç.", "about_tech": "Microsoft MarkItDown & PyQt6 ile hazırlandı" + }, + "Español": { + "title": "MarkItDown", "subtitle": "Convertir documentos complejos a Markdown", "drop_text": "Seleccione un archivo o arrástrelo aquí", "success_title": "Éxito", "success_msg": "Archivo guardado: ", "error_title": "Error", "error_msg": "Ocurrió un error: ", "select_file": "Seleccionar archivo", "logs": "Registros de acción", "auto_detect": "Idioma del sistema: Español", "about_title": "Sobre esta aplicación", "about_dev": "Desarrollado por", "about_desc": "Herramienta profesional para la conversión de documentos.", "about_tech": "Construido con MarkItDown y PyQt6" + }, + "Français": { + "title": "MarkItDown", "subtitle": "Convertir des documents complexes en Markdown", "drop_text": "Sélectionnez un fichier ou glissez-le ici", "success_title": "Succès", "success_msg": "Fichier enregistré : ", "error_title": "Erreur", "error_msg": "Une erreur est survenue : ", "select_file": "Choisir un fichier", "logs": "Journaux d'action", "auto_detect": "Langue du système : Français", "about_title": "À propos", "about_dev": "Développé par", "about_desc": "Outil professionnel de conversion de documents.", "about_tech": "Construit avec MarkItDown et PyQt6" + }, + "Deutsch": { + "title": "MarkItDown", "subtitle": "Komplexe Dokumente in Markdown konvertieren", "drop_text": "Datei auswählen oder hierher ziehen", "success_title": "Erfolg", "success_msg": "Datei gespeichert: ", "error_title": "Fehler", "error_msg": "Ein Fehler ist aufgetreten: ", "select_file": "Datei auswählen", "logs": "Aktionsprotokolle", "auto_detect": "Systemsprache: Deutsch", "about_title": "Über diese App", "about_dev": "Entwickelt von", "about_desc": "Professionelles Werkzeug zur Dokumentkonvertierung.", "about_tech": "Erstellt mit MarkItDown und PyQt6" + }, + "中文": { + "title": "MarkItDown", "subtitle": "将复杂文档转换为 Markdown", "drop_text": "选择文件或拖放到此处", "success_title": "成功", "success_msg": "文件已保存:", "error_title": "错误", "error_msg": "发生错误:", "select_file": "选择文件", "logs": "操作日志", "auto_detect": "系统语言:中文", "about_title": "关于此应用", "about_dev": "开发者", "about_desc": "专业的高保真文档转换工具。", "about_tech": "基于 Microsoft MarkItDown 和 PyQt6" + } +} + +class MarkItDownWorker(QThread): + finished = pyqtSignal(str) + error = pyqtSignal(str) + def __init__(self, file_path): + super().__init__() + self.file_path = file_path + def run(self): + try: + md = MarkItDown() + result = md.convert(self.file_path) + out = f"{os.path.splitext(self.file_path)[0]}.md" + with open(out, "w", encoding="utf-8") as f: + f.write(result.text_content) + self.finished.emit(out) + except Exception as e: + self.error.emit(str(e)) + +class MarkItDownApp(QMainWindow): + def __init__(self): + super().__init__() + self.setWindowTitle("MarkItDown Desktop") + self.resize(650, 850) + + # LOGO PATH FIX + curr_dir = os.path.dirname(os.path.abspath(__file__)) + self.logo_path = os.path.join(curr_dir, "logo.png") + # Ikinci ihtimal (Eger gui klasoru icinden calisma sorunu varsa) + if not os.path.exists(self.logo_path): + self.logo_path = os.path.join(curr_dir, "gui", "logo.png") + + if os.path.exists(self.logo_path): + self.setWindowIcon(QIcon(self.logo_path)) + + setTheme(Theme.DARK) + setThemeColor("#0078d4") + + self.central_widget = QWidget() + self.setCentralWidget(self.central_widget) + self.layout = QVBoxLayout(self.central_widget) + self.layout.setContentsMargins(40, 40, 40, 40) + self.layout.setSpacing(15) + + # Header + header = QHBoxLayout() + if os.path.exists(self.logo_path): + self.logo_label = QLabel() + self.logo_label.setPixmap(QIcon(self.logo_path).pixmap(40, 40)) + header.addWidget(self.logo_label) + + self.title_label = TitleLabel("MarkItDown") + self.title_label.setTextColor(QColor(255, 255, 255)) + header.addWidget(self.title_label) + + header.addStretch(1) + self.info_btn = TransparentPushButton(FIF.INFO, "", self) + self.info_btn.clicked.connect(self.showAbout) + header.addWidget(self.info_btn) + + self.lang_box = ComboBox() + self.lang_box.addItems(list(TRANSLATIONS.keys())) + header.addWidget(self.lang_box) + self.layout.addLayout(header) + + self.sub_label = BodyLabel("") + self.sub_label.setTextColor(QColor(180, 180, 180)) + self.layout.addWidget(self.sub_label) + self.layout.addSpacing(30) + + self.drop_card = CardWidget() + self.drop_card.setStyleSheet("CardWidget { border: 2px dashed rgba(255,255,255,0.15); border-radius: 12px; } CardWidget:hover { border: 2px dashed #0078d4; background-color: rgba(0,120,212,0.05); }") + self.drop_layout = QVBoxLayout(self.drop_card) + self.drop_layout.setContentsMargins(20, 40, 20, 40) + self.icon_widget = IconWidget(FIF.DOCUMENT) + self.icon_widget.setFixedSize(100, 100) + self.drop_layout.addWidget(self.icon_widget, 0, Qt.AlignmentFlag.AlignCenter) + self.info_label = StrongBodyLabel("") + self.info_label.setTextColor(QColor(255, 255, 255)) + self.drop_layout.addWidget(self.info_label, 0, Qt.AlignmentFlag.AlignCenter) + self.btn = PrimaryPushButton(FIF.FOLDER, "") + self.btn.setFixedWidth(200) + self.drop_layout.addWidget(self.btn, 0, Qt.AlignmentFlag.AlignCenter) + self.layout.addWidget(self.drop_card) + + self.pbar = ProgressBar() + self.pbar.setVisible(False) + self.layout.addWidget(self.pbar) + + self.layout.addSpacing(20) + log_header = QHBoxLayout() + self.log_header_label = StrongBodyLabel("") + self.log_header_label.setTextColor(QColor(150, 150, 150)) + log_header.addWidget(self.log_header_label) + log_header.addStretch(1) + self.clear_btn = TransparentPushButton(FIF.DELETE, "", self) + self.clear_btn.clicked.connect(lambda: self.log_area.clear()) + log_header.addWidget(self.clear_btn) + self.layout.addLayout(log_header) + + self.log_area = TextEdit() + self.log_area.setReadOnly(True) + self.log_area.setFixedHeight(180) + self.log_area.setStyleSheet("TextEdit { background-color: #121212; border: 1px solid #333; color: #aaa; font-family: 'Consolas'; }") + self.layout.addWidget(self.log_area) + self.setStyleSheet("QMainWindow { background-color: #101010; }") + + self.detectLanguage() + self.lang_box.currentTextChanged.connect(self.updateLang) + self.btn.clicked.connect(self.selectFile) + self.setAcceptDrops(True) + + def showAbout(self): + t = TRANSLATIONS[self.lang_key] + spec_text = "Supported Formats:\n• Documents: PDF, DOCX, XLSX, PPTX\n• Data & Web: CSV, JSON, XML, HTML, RSS, Wiki\n• Multimedia: MP3, WAV, Images\n• URLs: YouTube, Website Links" + if self.lang_key == "Türkçe": + spec_text = "Desteklenen Formatlar:\n• Belgeler: PDF, DOCX, XLSX, PPTX\n• Veri & Web: CSV, JSON, XML, HTML, RSS, Wiki\n• Multimedya: MP3, WAV, Görsel\n• Bağlantılar: YouTube, Web Linkleri" + view = FlyoutView(title=t["about_title"], content=f"{t['about_desc']}\n\n{spec_text}\n\n{t['about_dev']}: {DEVELOPER_NAME}\n{VERSION}\n\n{t['about_tech']}", icon=FIF.INFO) + f_btn = PrimaryPushButton(FIF.GITHUB, "View Source") + f_btn.setFixedWidth(140) + f_btn.clicked.connect(lambda: QDesktopServices.openUrl(QUrl(GITHUB_URL))) + view.addWidget(f_btn, align=Qt.AlignmentFlag.AlignRight) + Flyout.make(view, self.info_btn, self, FlyoutAnimationType.PULL_UP) + + def detectLanguage(self): + self.lang_key = "English" + sys_locale = QLocale.system().name() + if sys_locale.startswith("tr"): self.lang_key = "Türkçe" + elif sys_locale.startswith("es"): self.lang_key = "Español" + elif sys_locale.startswith("fr"): self.lang_key = "Français" + elif sys_locale.startswith("de"): self.lang_key = "Deutsch" + elif sys_locale.startswith("zh"): self.lang_key = "中文" + self.lang_box.setCurrentText(self.lang_key) + self.updateTexts() + self.log(TRANSLATIONS[self.lang_key]["auto_detect"]) + + def log(self, m, l="INFO"): + time_str = datetime.now().strftime("%H:%M:%S") + color = "#aaa" + if l == "ERROR": color = "#ff4b4b" + elif l == "SUCCESS": color = "#217346" + self.log_area.append(f"[{time_str}] {m}") + logging.info(m) + + def updateLang(self, lang): + self.lang_key = lang + self.updateTexts() + + def updateTexts(self): + t = TRANSLATIONS[self.lang_key] + self.title_label.setText(t["title"]) + self.sub_label.setText(t["subtitle"]) + self.info_label.setText(t["drop_text"]) + self.btn.setText(t["select_file"]) + self.log_header_label.setText(t["logs"]) + + def selectFile(self): + path, _ = QFileDialog.getOpenFileName(self, "Select", "", "All Files (*)") + if path: self.startWorker(path) + + def dragEnterEvent(self, e: QDragEnterEvent): + if e.mimeData().hasUrls(): e.accept() + else: e.ignore() + + def dropEvent(self, e: QDropEvent): + files = [u.toLocalFile() for u in e.mimeData().urls()] + if files: self.startWorker(files[0]) + + def startWorker(self, path): + self.pbar.setVisible(True) + self.pbar.setRange(0, 0) + self.btn.setEnabled(False) + self.log(f"Process starting: {os.path.basename(path)}") + self.worker = MarkItDownWorker(path) + self.worker.finished.connect(self.done) + self.worker.error.connect(self.fail) + self.worker.start() + + def done(self, path): + self.pbar.setVisible(False) + self.btn.setEnabled(True) + self.log(f"Saved: {os.path.basename(path)}", "SUCCESS") + t = TRANSLATIONS[self.lang_key] + InfoBar.success(t["success_title"], f"{t['success_msg']}\n{os.path.basename(path)}", duration=5000, parent=self) + + def fail(self, m): + self.pbar.setVisible(False) + self.btn.setEnabled(True) + if "UnknownValueError" in m: + m = "Audio conversion failed. Currently, only English is reliably supported, or the audio quality is too low." + if self.lang_key == "Türkçe": m = "Ses dökümü başarısız. Şu an sadece İngilizce dil desteği stabildir veya ses kalitesi çok düşüktür." + self.log(f"ERROR: {m}", "ERROR") + t = TRANSLATIONS[self.lang_key] + InfoBar.error(t["error_title"], m, duration=8000, parent=self) + +if __name__ == "__main__": + QApplication.setHighDpiScaleFactorRoundingPolicy(Qt.HighDpiScaleFactorRoundingPolicy.PassThrough) + app = QApplication(sys.argv) + w = MarkItDownApp() + w.show() + sys.exit(app.exec()) diff --git a/packages/markitdown/src/markitdown/converters/_docx_converter.py b/packages/markitdown/src/markitdown/converters/_docx_converter.py index 3975107b1..3b7dc04b3 100644 --- a/packages/markitdown/src/markitdown/converters/_docx_converter.py +++ b/packages/markitdown/src/markitdown/converters/_docx_converter.py @@ -1,7 +1,10 @@ import sys import io +import os +import re +import base64 +import hashlib from warnings import warn - from typing import BinaryIO, Any from ._html_converter import HtmlConverter @@ -10,74 +13,86 @@ from .._stream_info import StreamInfo from .._exceptions import MissingDependencyException, MISSING_DEPENDENCY_MESSAGE -# Try loading optional (but in this case, required) dependencies -# Save reporting of any exceptions for later _dependency_exc_info = None try: import mammoth - except ImportError: - # Preserve the error and stack trace for later _dependency_exc_info = sys.exc_info() - -ACCEPTED_MIME_TYPE_PREFIXES = [ - "application/vnd.openxmlformats-officedocument.wordprocessingml.document", -] - +ACCEPTED_MIME_TYPE_PREFIXES = ["application/vnd.openxmlformats-officedocument.wordprocessingml.document"] ACCEPTED_FILE_EXTENSIONS = [".docx"] - class DocxConverter(HtmlConverter): - """ - Converts DOCX files to Markdown. Style information (e.g.m headings) and tables are preserved where possible. - """ - def __init__(self): super().__init__() self._html_converter = HtmlConverter() - def accepts( - self, - file_stream: BinaryIO, - stream_info: StreamInfo, - **kwargs: Any, # Options to pass to the converter - ) -> bool: - mimetype = (stream_info.mimetype or "").lower() + def accepts(self, file_stream: BinaryIO, stream_info: StreamInfo, **kwargs: Any) -> bool: extension = (stream_info.extension or "").lower() - - if extension in ACCEPTED_FILE_EXTENSIONS: - return True - + if extension in ACCEPTED_FILE_EXTENSIONS: return True + mimetype = (stream_info.mimetype or "").lower() for prefix in ACCEPTED_MIME_TYPE_PREFIXES: - if mimetype.startswith(prefix): - return True - + if mimetype.startswith(prefix): return True return False - def convert( - self, - file_stream: BinaryIO, - stream_info: StreamInfo, - **kwargs: Any, # Options to pass to the converter - ) -> DocumentConverterResult: - # Check: the dependencies + def convert(self, file_stream: BinaryIO, stream_info: StreamInfo, **kwargs: Any) -> DocumentConverterResult: if _dependency_exc_info is not None: - raise MissingDependencyException( - MISSING_DEPENDENCY_MESSAGE.format( - converter=type(self).__name__, - extension=".docx", - feature="docx", - ) - ) from _dependency_exc_info[ - 1 - ].with_traceback( # type: ignore[union-attr] - _dependency_exc_info[2] - ) + raise MissingDependencyException(MISSING_DEPENDENCY_MESSAGE.format(converter=type(self).__name__, extension=".docx", feature="docx")) from _dependency_exc_info[1].with_traceback(_dependency_exc_info[2]) + + # --- HYBRID IMAGE HANDLER --- + # Yerel dosya yolunu önce 'local_path'ten, yoksa 'url'den al + file_url = stream_info.local_path or stream_info.url or "document" + base_name = os.path.splitext(os.path.basename(file_url))[0] + + # Akilli klasör ismi (Uzun isimleri buda + hash ekle) + clean_name = re.sub(r'[^a-zA-Z0-9]', '_', base_name) + if len(clean_name) > 20: + short_hash = hashlib.md5(base_name.encode()).hexdigest()[:4] + clean_name = f"{clean_name[:15]}_{short_hash}" + + assets_dir_name = f"{clean_name}_assets" + + # Kesin çözüm: Dosya yolunu mutlak (absolute) hale getir ve onun klasörünü baz al + abs_file_path = os.path.abspath(file_url) + base_dir = os.path.dirname(abs_file_path) + assets_path = os.path.join(base_dir, assets_dir_name) + + image_counter = 0 + + def convert_image(image): + nonlocal image_counter + image_counter += 1 + with image.open() as image_bytes: + data = image_bytes.read() + size_kb = len(data) / 1024 + + # KÜÇÜK RESİM: Base64 yap (Eşik: 50 KB) + if size_kb < 50: + base64_data = base64.b64encode(data).decode("ascii") + return {"src": f"data:{image.content_type};base64,{base64_data}"} + + # BÜYÜK RESİM: Klasöre çıkart + if not os.path.exists(assets_path): + os.makedirs(assets_path, exist_ok=True) + + ext = image.content_type.split("/")[-1] if "/" in image.content_type else "png" + img_filename = f"image_{image_counter}.{ext}" + img_full_path = os.path.join(assets_path, img_filename) + + with open(img_full_path, "wb") as f: + f.write(data) + + # Markdown içinde klasör referansi ver + return {"src": f"./{assets_dir_name}/{img_filename}"} style_map = kwargs.get("style_map", None) pre_process_stream = pre_process_docx(file_stream) - return self._html_converter.convert_string( - mammoth.convert_to_html(pre_process_stream, style_map=style_map).value, - **kwargs, + + # Mammoth'a bizim akilli handler'i veriyoruz + html_result = mammoth.convert_to_html( + pre_process_stream, + style_map=style_map, + convert_image=mammoth.images.img_element(convert_image) ) + + return self._html_converter.convert_string(html_result.value, **kwargs) diff --git a/packages/markitdown/src/markitdown/converters/_markdownify.py b/packages/markitdown/src/markitdown/converters/_markdownify.py index 19e8a2984..2bb54fcc6 100644 --- a/packages/markitdown/src/markitdown/converters/_markdownify.py +++ b/packages/markitdown/src/markitdown/converters/_markdownify.py @@ -122,5 +122,37 @@ def convert_input( return "[x] " if el.has_attr("checked") else "[ ] " return "" + def convert_table( + self, + el: Any, + text: str, + convert_as_inline: Optional[bool] = False, + **kwargs, + ) -> str: + """Unwrap tables into readable Markdown text blocks to avoid layout breakage.""" + rows = el.find_all('tr') + output = [] + for row in rows: + cells = row.find_all(['td', 'th']) + # Convert cell contents to markdown + cell_contents = [self.convert_soup(cell).strip() for cell in cells] + + if len(cell_contents) == 2: + # Potential Key-Value pair (very common in Word forms) + key, val = cell_contents + if key and val: + output.append(f"**{key}**: {val}") + elif key: + output.append(f"**{key}**") + else: + output.append(val) + else: + # Multiple cells: Join them with a separator + line = " | ".join([c for c in cell_contents if c]) + if line: + output.append(line) + + return "\n\n" + "\n\n".join(output) + "\n\n" + def convert_soup(self, soup: Any) -> str: return super().convert_soup(soup) # type: ignore diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 000000000..42cb6e2db --- /dev/null +++ b/requirements.txt @@ -0,0 +1,7 @@ +PyQt6>=6.4.0 +qfluentwidgets>=1.0.0 +markitdown>=0.0.1 +pydub>=0.25.1 +SpeechRecognition>=3.10.0 +jinja2>=3.1.2 +pyinstaller>=6.0.0 diff --git a/run_gui.bat b/run_gui.bat new file mode 100644 index 000000000..e0e3a4044 --- /dev/null +++ b/run_gui.bat @@ -0,0 +1,4 @@ +@echo off +echo MarkItDown Desktop baslatiliyor... +.\venv\Scripts\python.exe gui\markitdown_gui.py +pause diff --git a/test_sample.txt b/test_sample.txt new file mode 100644 index 0000000000000000000000000000000000000000..55d79dd5c092f52260f9c948173c56c485330730 GIT binary patch literal 82 zcmezW&x0YAAqNQa859`Gfn*VoodRU10a^JBxj>d9Lmop3LncEyP$ZF|49F^Bs050a U0Cg4vNs!u1psrK~UIs1(00;39cK`qY literal 0 HcmV?d00001