Spaces:
				
			
			
	
			
			
					
		Running
		
	
	
	
			
			
	
	
	
	
		
		
					
		Running
		
	Add .gitignore and update app.py for platform-specific MLX imports; modify requirements.txt to comment out MLX dependencies
Browse files- .gitignore +237 -0
- app.py +26 -7
- requirements.txt +3 -2
    	
        .gitignore
    ADDED
    
    | @@ -0,0 +1,237 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            # Python
         | 
| 2 | 
            +
            __pycache__/
         | 
| 3 | 
            +
            *.py[cod]
         | 
| 4 | 
            +
            *$py.class
         | 
| 5 | 
            +
            *.so
         | 
| 6 | 
            +
            .Python
         | 
| 7 | 
            +
            build/
         | 
| 8 | 
            +
            develop-eggs/
         | 
| 9 | 
            +
            dist/
         | 
| 10 | 
            +
            downloads/
         | 
| 11 | 
            +
            eggs/
         | 
| 12 | 
            +
            .eggs/
         | 
| 13 | 
            +
            lib/
         | 
| 14 | 
            +
            lib64/
         | 
| 15 | 
            +
            parts/
         | 
| 16 | 
            +
            sdist/
         | 
| 17 | 
            +
            var/
         | 
| 18 | 
            +
            wheels/
         | 
| 19 | 
            +
            share/python-wheels/
         | 
| 20 | 
            +
            *.egg-info/
         | 
| 21 | 
            +
            .installed.cfg
         | 
| 22 | 
            +
            *.egg
         | 
| 23 | 
            +
            MANIFEST
         | 
| 24 | 
            +
             | 
| 25 | 
            +
            # PyInstaller
         | 
| 26 | 
            +
            *.manifest
         | 
| 27 | 
            +
            *.spec
         | 
| 28 | 
            +
             | 
| 29 | 
            +
            # Installer logs
         | 
| 30 | 
            +
            pip-log.txt
         | 
| 31 | 
            +
            pip-delete-this-directory.txt
         | 
| 32 | 
            +
             | 
| 33 | 
            +
            # Unit test / coverage reports
         | 
| 34 | 
            +
            htmlcov/
         | 
| 35 | 
            +
            .tox/
         | 
| 36 | 
            +
            .nox/
         | 
| 37 | 
            +
            .coverage
         | 
| 38 | 
            +
            .coverage.*
         | 
| 39 | 
            +
            .cache
         | 
| 40 | 
            +
            nosetests.xml
         | 
| 41 | 
            +
            coverage.xml
         | 
| 42 | 
            +
            *.cover
         | 
| 43 | 
            +
            *.py,cover
         | 
| 44 | 
            +
            .hypothesis/
         | 
| 45 | 
            +
            .pytest_cache/
         | 
| 46 | 
            +
            cover/
         | 
| 47 | 
            +
             | 
| 48 | 
            +
            # Translations
         | 
| 49 | 
            +
            *.mo
         | 
| 50 | 
            +
            *.pot
         | 
| 51 | 
            +
             | 
| 52 | 
            +
            # Django/Flask stuff
         | 
| 53 | 
            +
            *.log
         | 
| 54 | 
            +
            local_settings.py
         | 
| 55 | 
            +
            db.sqlite3
         | 
| 56 | 
            +
            db.sqlite3-journal
         | 
| 57 | 
            +
             | 
| 58 | 
            +
            # Jupyter Notebook
         | 
| 59 | 
            +
            .ipynb_checkpoints
         | 
| 60 | 
            +
             | 
| 61 | 
            +
            # IPython
         | 
| 62 | 
            +
            profile_default/
         | 
| 63 | 
            +
            ipython_config.py
         | 
| 64 | 
            +
             | 
| 65 | 
            +
            # pyenv
         | 
| 66 | 
            +
            .python-version
         | 
| 67 | 
            +
             | 
| 68 | 
            +
            # pipenv
         | 
| 69 | 
            +
            Pipfile.lock
         | 
| 70 | 
            +
             | 
| 71 | 
            +
            # poetry
         | 
| 72 | 
            +
            poetry.lock
         | 
| 73 | 
            +
             | 
| 74 | 
            +
            # pdm
         | 
| 75 | 
            +
            .pdm.toml
         | 
| 76 | 
            +
             | 
| 77 | 
            +
            # PEP 582
         | 
| 78 | 
            +
            __pypackages__/
         | 
| 79 | 
            +
             | 
| 80 | 
            +
            # Celery stuff
         | 
| 81 | 
            +
            celerybeat-schedule
         | 
| 82 | 
            +
            celerybeat.pid
         | 
| 83 | 
            +
             | 
| 84 | 
            +
            # SageMath parsed files
         | 
| 85 | 
            +
            *.sage.py
         | 
| 86 | 
            +
             | 
| 87 | 
            +
            # Environments
         | 
| 88 | 
            +
            .env
         | 
| 89 | 
            +
            .env.local
         | 
| 90 | 
            +
            .env.development.local
         | 
| 91 | 
            +
            .env.test.local
         | 
| 92 | 
            +
            .env.production.local
         | 
| 93 | 
            +
            .venv
         | 
| 94 | 
            +
            env/
         | 
| 95 | 
            +
            venv/
         | 
| 96 | 
            +
            ENV/
         | 
| 97 | 
            +
            env.bak/
         | 
| 98 | 
            +
            venv.bak/
         | 
| 99 | 
            +
             | 
| 100 | 
            +
            # Spyder project settings
         | 
| 101 | 
            +
            .spyderproject
         | 
| 102 | 
            +
            .spyproject
         | 
| 103 | 
            +
             | 
| 104 | 
            +
            # Rope project settings
         | 
| 105 | 
            +
            .ropeproject
         | 
| 106 | 
            +
             | 
| 107 | 
            +
            # mkdocs documentation
         | 
| 108 | 
            +
            /site
         | 
| 109 | 
            +
             | 
| 110 | 
            +
            # mypy
         | 
| 111 | 
            +
            .mypy_cache/
         | 
| 112 | 
            +
            .dmypy.json
         | 
| 113 | 
            +
            dmypy.json
         | 
| 114 | 
            +
             | 
| 115 | 
            +
            # Pyre type checker
         | 
| 116 | 
            +
            .pyre/
         | 
| 117 | 
            +
             | 
| 118 | 
            +
            # pytype static type analyzer
         | 
| 119 | 
            +
            .pytype/
         | 
| 120 | 
            +
             | 
| 121 | 
            +
            # Cython debug symbols
         | 
| 122 | 
            +
            cython_debug/
         | 
| 123 | 
            +
             | 
| 124 | 
            +
            # MLX/AI Model Files
         | 
| 125 | 
            +
            *.gguf
         | 
| 126 | 
            +
            *.bin
         | 
| 127 | 
            +
            *.safetensors
         | 
| 128 | 
            +
            *.h5
         | 
| 129 | 
            +
            *.onnx
         | 
| 130 | 
            +
            *.pb
         | 
| 131 | 
            +
            *.tflite
         | 
| 132 | 
            +
            *.mlmodel
         | 
| 133 | 
            +
            *.pth
         | 
| 134 | 
            +
            *.pt
         | 
| 135 | 
            +
            models/
         | 
| 136 | 
            +
            checkpoints/
         | 
| 137 | 
            +
            model_cache/
         | 
| 138 | 
            +
            .cache/
         | 
| 139 | 
            +
            huggingface_hub/
         | 
| 140 | 
            +
             | 
| 141 | 
            +
            # Transformers cache
         | 
| 142 | 
            +
            ~/.cache/huggingface/
         | 
| 143 | 
            +
            .transformers_cache/
         | 
| 144 | 
            +
             | 
| 145 | 
            +
            # MLX compiled files
         | 
| 146 | 
            +
            /tmp/*.so
         | 
| 147 | 
            +
            /tmp/*.cpp
         | 
| 148 | 
            +
            *.mlx_cache/
         | 
| 149 | 
            +
             | 
| 150 | 
            +
            # Gradio temporary files
         | 
| 151 | 
            +
            gradio_cached_examples/
         | 
| 152 | 
            +
            flagged/
         | 
| 153 | 
            +
             | 
| 154 | 
            +
            # Web scraping cache
         | 
| 155 | 
            +
            .ddgs_cache/
         | 
| 156 | 
            +
            requests_cache/
         | 
| 157 | 
            +
             | 
| 158 | 
            +
            # Local development
         | 
| 159 | 
            +
            local_test/
         | 
| 160 | 
            +
            test_files/
         | 
| 161 | 
            +
            debug/
         | 
| 162 | 
            +
             | 
| 163 | 
            +
            # Docker
         | 
| 164 | 
            +
            .dockerignore
         | 
| 165 | 
            +
             | 
| 166 | 
            +
            # Node.js (if any frontend dependencies)
         | 
| 167 | 
            +
            node_modules/
         | 
| 168 | 
            +
            npm-debug.log*
         | 
| 169 | 
            +
            yarn-debug.log*
         | 
| 170 | 
            +
            yarn-error.log*
         | 
| 171 | 
            +
            package-lock.json
         | 
| 172 | 
            +
            yarn.lock
         | 
| 173 | 
            +
             | 
| 174 | 
            +
            # Build outputs
         | 
| 175 | 
            +
            dist/
         | 
| 176 | 
            +
            out/
         | 
| 177 | 
            +
             | 
| 178 | 
            +
            # Cache directories
         | 
| 179 | 
            +
            .parcel-cache/
         | 
| 180 | 
            +
             | 
| 181 | 
            +
            # IDE and editor files
         | 
| 182 | 
            +
            .vscode/
         | 
| 183 | 
            +
            .idea/
         | 
| 184 | 
            +
            *.swp
         | 
| 185 | 
            +
            *.swo
         | 
| 186 | 
            +
            *~
         | 
| 187 | 
            +
            .vim/
         | 
| 188 | 
            +
             | 
| 189 | 
            +
            # OS generated files
         | 
| 190 | 
            +
            .DS_Store
         | 
| 191 | 
            +
            .DS_Store?
         | 
| 192 | 
            +
            ._*
         | 
| 193 | 
            +
            .Spotlight-V100
         | 
| 194 | 
            +
            .Trashes
         | 
| 195 | 
            +
            ehthumbs.db
         | 
| 196 | 
            +
            Thumbs.db
         | 
| 197 | 
            +
            desktop.ini
         | 
| 198 | 
            +
             | 
| 199 | 
            +
            # Logs
         | 
| 200 | 
            +
            logs/
         | 
| 201 | 
            +
            *.log
         | 
| 202 | 
            +
             | 
| 203 | 
            +
            # Runtime data
         | 
| 204 | 
            +
            pids/
         | 
| 205 | 
            +
            *.pid
         | 
| 206 | 
            +
            *.seed
         | 
| 207 | 
            +
            *.pid.lock
         | 
| 208 | 
            +
             | 
| 209 | 
            +
            # Temporary files
         | 
| 210 | 
            +
            tmp/
         | 
| 211 | 
            +
            temp/
         | 
| 212 | 
            +
            *.tmp
         | 
| 213 | 
            +
            *.temp
         | 
| 214 | 
            +
             | 
| 215 | 
            +
            # API Keys and secrets (extra protection)
         | 
| 216 | 
            +
            config.json
         | 
| 217 | 
            +
            secrets.json
         | 
| 218 | 
            +
            .secrets
         | 
| 219 | 
            +
            api_keys.txt
         | 
| 220 | 
            +
            tavily_key.txt
         | 
| 221 | 
            +
             | 
| 222 | 
            +
            # Large files that shouldn't be committed
         | 
| 223 | 
            +
            *.zip
         | 
| 224 | 
            +
            *.tar.gz
         | 
| 225 | 
            +
            *.rar
         | 
| 226 | 
            +
            *.7z
         | 
| 227 | 
            +
            large_files/
         | 
| 228 | 
            +
             | 
| 229 | 
            +
            # Backup files
         | 
| 230 | 
            +
            *.bak
         | 
| 231 | 
            +
            *.backup
         | 
| 232 | 
            +
            *.orig
         | 
| 233 | 
            +
             | 
| 234 | 
            +
            # Database files
         | 
| 235 | 
            +
            *.db
         | 
| 236 | 
            +
            *.sqlite
         | 
| 237 | 
            +
            *.sqlite3
         | 
    	
        app.py
    CHANGED
    
    | @@ -57,7 +57,13 @@ except Exception: | |
| 57 |  | 
| 58 |  | 
| 59 | 
             
            try:
         | 
| 60 | 
            -
                 | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 61 | 
             
            except Exception:
         | 
| 62 | 
             
                mlx_load = None
         | 
| 63 | 
             
                mlx_generate = None
         | 
| @@ -473,7 +479,7 @@ def _ensure_local_model(selected_model: str): | |
| 473 | 
             
                t0 = time.perf_counter()
         | 
| 474 | 
             
                if selected_model == "ibraschwan/Kumru-2B-mlx-4Bit":
         | 
| 475 | 
             
                    if mlx_load is None or mlx_generate is None:
         | 
| 476 | 
            -
                        raise RuntimeError(" | 
| 477 | 
             
                    _backend = "mlx"
         | 
| 478 | 
             
                    _mlx_model, _mlx_tokenizer = mlx_load(MLX_REPO)
         | 
| 479 | 
             
                    log_event("model_loaded", model_id=selected_model, backend=_backend, elapsed_ms=int((time.perf_counter() - t0) * 1000))
         | 
| @@ -568,8 +574,14 @@ def local_stream_generate(selected_model, system_message, user_msg, max_tokens, | |
| 568 |  | 
| 569 |  | 
| 570 | 
             
            def pick_inference_model(selected_model: str) -> str:
         | 
|  | |
| 571 | 
             
                unsupported = {MLX_REPO, LORA_REPO}
         | 
| 572 | 
            -
                 | 
|  | |
|  | |
|  | |
|  | |
|  | |
| 573 |  | 
| 574 |  | 
| 575 | 
             
            def respond(
         | 
| @@ -738,12 +750,19 @@ def respond( | |
| 738 | 
             
                    )
         | 
| 739 |  | 
| 740 |  | 
| 741 | 
            -
             | 
| 742 | 
            -
             | 
|  | |
| 743 | 
             
                    "vngrs-ai/Kumru-2B",
         | 
| 744 | 
            -
                    "ibraschwan/Kumru-2B-mlx-4Bit",
         | 
| 745 | 
             
                    "ceofast/kumru-2b-lora",
         | 
| 746 | 
            -
                ] | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 747 | 
             
                value="vngrs-ai/Kumru-2B",
         | 
| 748 | 
             
                label="Model",
         | 
| 749 | 
             
            )
         | 
|  | |
| 57 |  | 
| 58 |  | 
| 59 | 
             
            try:
         | 
| 60 | 
            +
                import platform
         | 
| 61 | 
            +
                # Only import MLX on macOS as it's not stable on Linux
         | 
| 62 | 
            +
                if platform.system() == "Darwin":
         | 
| 63 | 
            +
                    from mlx_lm import load as mlx_load, generate as mlx_generate
         | 
| 64 | 
            +
                else:
         | 
| 65 | 
            +
                    mlx_load = None
         | 
| 66 | 
            +
                    mlx_generate = None
         | 
| 67 | 
             
            except Exception:
         | 
| 68 | 
             
                mlx_load = None
         | 
| 69 | 
             
                mlx_generate = None
         | 
|  | |
| 479 | 
             
                t0 = time.perf_counter()
         | 
| 480 | 
             
                if selected_model == "ibraschwan/Kumru-2B-mlx-4Bit":
         | 
| 481 | 
             
                    if mlx_load is None or mlx_generate is None:
         | 
| 482 | 
            +
                        raise RuntimeError(f"MLX is not available on {platform.system()}. Please use a different model.")
         | 
| 483 | 
             
                    _backend = "mlx"
         | 
| 484 | 
             
                    _mlx_model, _mlx_tokenizer = mlx_load(MLX_REPO)
         | 
| 485 | 
             
                    log_event("model_loaded", model_id=selected_model, backend=_backend, elapsed_ms=int((time.perf_counter() - t0) * 1000))
         | 
|  | |
| 574 |  | 
| 575 |  | 
| 576 | 
             
            def pick_inference_model(selected_model: str) -> str:
         | 
| 577 | 
            +
                # Models that don't support remote inference
         | 
| 578 | 
             
                unsupported = {MLX_REPO, LORA_REPO}
         | 
| 579 | 
            +
                if selected_model in unsupported:
         | 
| 580 | 
            +
                    return "vngrs-ai/Kumru-2B"
         | 
| 581 | 
            +
                # Also fallback MLX model selection to base model on non-macOS
         | 
| 582 | 
            +
                if selected_model == "ibraschwan/Kumru-2B-mlx-4Bit" and platform.system() != "Darwin":
         | 
| 583 | 
            +
                    return "vngrs-ai/Kumru-2B"
         | 
| 584 | 
            +
                return selected_model
         | 
| 585 |  | 
| 586 |  | 
| 587 | 
             
            def respond(
         | 
|  | |
| 750 | 
             
                    )
         | 
| 751 |  | 
| 752 |  | 
| 753 | 
            +
            # Create model choices based on platform
         | 
| 754 | 
            +
            def get_model_choices():
         | 
| 755 | 
            +
                base_choices = [
         | 
| 756 | 
             
                    "vngrs-ai/Kumru-2B",
         | 
|  | |
| 757 | 
             
                    "ceofast/kumru-2b-lora",
         | 
| 758 | 
            +
                ]
         | 
| 759 | 
            +
                # Only add MLX model on macOS
         | 
| 760 | 
            +
                if platform.system() == "Darwin" and mlx_load is not None:
         | 
| 761 | 
            +
                    base_choices.insert(1, "ibraschwan/Kumru-2B-mlx-4Bit")
         | 
| 762 | 
            +
                return base_choices
         | 
| 763 | 
            +
             | 
| 764 | 
            +
            model_dropdown = gr.Dropdown(
         | 
| 765 | 
            +
                choices=get_model_choices(),
         | 
| 766 | 
             
                value="vngrs-ai/Kumru-2B",
         | 
| 767 | 
             
                label="Model",
         | 
| 768 | 
             
            )
         | 
    	
        requirements.txt
    CHANGED
    
    | @@ -19,7 +19,8 @@ huggingface_hub>=0.35.3 | |
| 19 | 
             
            requests>=2.32.5
         | 
| 20 | 
             
            structlog>=25.4.0
         | 
| 21 |  | 
| 22 | 
            -
             | 
| 23 | 
            -
            mlx | 
|  | |
| 24 | 
             
            # llama-cpp-python==0.3.16
         | 
| 25 | 
             
            peft==0.17.1
         | 
|  | |
| 19 | 
             
            requests>=2.32.5
         | 
| 20 | 
             
            structlog>=25.4.0
         | 
| 21 |  | 
| 22 | 
            +
            # MLX only works reliably on macOS
         | 
| 23 | 
            +
            # mlx==0.26.3
         | 
| 24 | 
            +
            # mlx-lm==0.26.4
         | 
| 25 | 
             
            # llama-cpp-python==0.3.16
         | 
| 26 | 
             
            peft==0.17.1
         | 
