added transformers compatibility shim for minicpm remote code, switched from python 3.13 to 3.11, moved gradio css to launch
Browse files- README.md +1 -1
- app.py +17 -7
- requirements.txt +1 -1
README.md
CHANGED
|
@@ -5,7 +5,7 @@ colorFrom: purple
|
|
| 5 |
colorTo: indigo
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 6.16.0
|
| 8 |
-
python_version: '3.
|
| 9 |
app_file: app.py
|
| 10 |
pinned: false
|
| 11 |
license: mit
|
|
|
|
| 5 |
colorTo: indigo
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 6.16.0
|
| 8 |
+
python_version: '3.11'
|
| 9 |
app_file: app.py
|
| 10 |
pinned: false
|
| 11 |
license: mit
|
app.py
CHANGED
|
@@ -12,8 +12,23 @@ with open("knowledge_base.json", "r") as f:
|
|
| 12 |
# Model configuration
|
| 13 |
MODEL_ID = os.environ.get("MODEL_ID", "openbmb/MiniCPM-2B-dpo-bf16")
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
def load_model():
|
| 16 |
print(f"Loading model {MODEL_ID}...")
|
|
|
|
| 17 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=True)
|
| 18 |
|
| 19 |
# Detect if CUDA is available
|
|
@@ -266,12 +281,7 @@ def format_output(result):
|
|
| 266 |
return "\n".join(lines)
|
| 267 |
|
| 268 |
# Gradio UI
|
| 269 |
-
with gr.Blocks(title="Parent Co-Pilot"
|
| 270 |
-
.header { text-align: center; margin-bottom: 20px; }
|
| 271 |
-
.header h1 { font-size: 2rem; color: #2c3e50; }
|
| 272 |
-
.header p { font-size: 1.1rem; color: #555; }
|
| 273 |
-
.result-box { background: #f8f9fa; padding: 20px; border-radius: 8px; }
|
| 274 |
-
""") as demo:
|
| 275 |
|
| 276 |
gr.Markdown("""
|
| 277 |
<div class="header">
|
|
@@ -367,4 +377,4 @@ with gr.Blocks(title="Parent Co-Pilot", css="""
|
|
| 367 |
""")
|
| 368 |
|
| 369 |
if __name__ == "__main__":
|
| 370 |
-
demo.launch()
|
|
|
|
| 12 |
# Model configuration
|
| 13 |
MODEL_ID = os.environ.get("MODEL_ID", "openbmb/MiniCPM-2B-dpo-bf16")
|
| 14 |
|
| 15 |
+
APP_CSS = """
|
| 16 |
+
.header { text-align: center; margin-bottom: 20px; }
|
| 17 |
+
.header h1 { font-size: 2rem; color: #2c3e50; }
|
| 18 |
+
.header p { font-size: 1.1rem; color: #555; }
|
| 19 |
+
.result-box { background: #f8f9fa; padding: 20px; border-radius: 8px; }
|
| 20 |
+
"""
|
| 21 |
+
|
| 22 |
+
def patch_transformers_for_minicpm():
|
| 23 |
+
"""Restore a helper MiniCPM remote code imports from older Transformers."""
|
| 24 |
+
import transformers.utils.import_utils as import_utils
|
| 25 |
+
|
| 26 |
+
if not hasattr(import_utils, "is_torch_fx_available"):
|
| 27 |
+
import_utils.is_torch_fx_available = lambda: False
|
| 28 |
+
|
| 29 |
def load_model():
|
| 30 |
print(f"Loading model {MODEL_ID}...")
|
| 31 |
+
patch_transformers_for_minicpm()
|
| 32 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=True)
|
| 33 |
|
| 34 |
# Detect if CUDA is available
|
|
|
|
| 281 |
return "\n".join(lines)
|
| 282 |
|
| 283 |
# Gradio UI
|
| 284 |
+
with gr.Blocks(title="Parent Co-Pilot") as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 285 |
|
| 286 |
gr.Markdown("""
|
| 287 |
<div class="header">
|
|
|
|
| 377 |
""")
|
| 378 |
|
| 379 |
if __name__ == "__main__":
|
| 380 |
+
demo.launch(css=APP_CSS)
|
requirements.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
gradio>=4.0.0
|
| 2 |
-
transformers>=4.40.0
|
| 3 |
torch>=2.0.0
|
| 4 |
accelerate>=0.25.0
|
|
|
|
| 1 |
gradio>=4.0.0
|
| 2 |
+
transformers>=4.40.0,<4.47.0
|
| 3 |
torch>=2.0.0
|
| 4 |
accelerate>=0.25.0
|