Add debug logging to trace startup
Browse files
app.py
CHANGED
|
@@ -1,10 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import torch
|
|
|
|
|
|
|
| 3 |
import spaces
|
|
|
|
|
|
|
| 4 |
import gradio as gr
|
|
|
|
|
|
|
| 5 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
|
|
| 6 |
|
| 7 |
MODEL_ID = os.getenv("MODEL_ID", "GnLOLot/MiniCPM5-1B-Claude-Opus-Fable5-V2-Thinking")
|
|
|
|
| 8 |
|
| 9 |
model = None
|
| 10 |
tokenizer = None
|
|
@@ -13,6 +24,7 @@ tokenizer = None
|
|
| 13 |
def chat_fn(message, history):
|
| 14 |
global model, tokenizer
|
| 15 |
if model is None:
|
|
|
|
| 16 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=True)
|
| 17 |
model = AutoModelForCausalLM.from_pretrained(
|
| 18 |
MODEL_ID,
|
|
@@ -22,6 +34,7 @@ def chat_fn(message, history):
|
|
| 22 |
)
|
| 23 |
if tokenizer.pad_token is None:
|
| 24 |
tokenizer.pad_token = tokenizer.eos_token
|
|
|
|
| 25 |
|
| 26 |
messages = []
|
| 27 |
for h in history:
|
|
@@ -44,6 +57,8 @@ def chat_fn(message, history):
|
|
| 44 |
|
| 45 |
return tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True).strip()
|
| 46 |
|
|
|
|
|
|
|
| 47 |
with gr.Blocks(title="MiniCPM5-1B Chat") as demo:
|
| 48 |
gr.Markdown(f"# MiniCPM5-1B Chat\n**Model:** `{MODEL_ID}`\n\nPowered by ZeroGPU free GPU")
|
| 49 |
gr.ChatInterface(
|
|
@@ -51,3 +66,5 @@ with gr.Blocks(title="MiniCPM5-1B Chat") as demo:
|
|
| 51 |
title=None,
|
| 52 |
description="First request loads the model (~30s), subsequent calls are faster."
|
| 53 |
)
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
print("Step 1: import start", flush=True)
|
| 3 |
+
|
| 4 |
import os
|
| 5 |
import torch
|
| 6 |
+
print("Step 2: torch imported", flush=True)
|
| 7 |
+
|
| 8 |
import spaces
|
| 9 |
+
print("Step 3: spaces imported", flush=True)
|
| 10 |
+
|
| 11 |
import gradio as gr
|
| 12 |
+
print("Step 4: gradio imported", flush=True)
|
| 13 |
+
|
| 14 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 15 |
+
print("Step 5: transformers imported", flush=True)
|
| 16 |
|
| 17 |
MODEL_ID = os.getenv("MODEL_ID", "GnLOLot/MiniCPM5-1B-Claude-Opus-Fable5-V2-Thinking")
|
| 18 |
+
print(f"Step 6: MODEL_ID = {MODEL_ID}", flush=True)
|
| 19 |
|
| 20 |
model = None
|
| 21 |
tokenizer = None
|
|
|
|
| 24 |
def chat_fn(message, history):
|
| 25 |
global model, tokenizer
|
| 26 |
if model is None:
|
| 27 |
+
print("Loading model...", flush=True)
|
| 28 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=True)
|
| 29 |
model = AutoModelForCausalLM.from_pretrained(
|
| 30 |
MODEL_ID,
|
|
|
|
| 34 |
)
|
| 35 |
if tokenizer.pad_token is None:
|
| 36 |
tokenizer.pad_token = tokenizer.eos_token
|
| 37 |
+
print("Model loaded", flush=True)
|
| 38 |
|
| 39 |
messages = []
|
| 40 |
for h in history:
|
|
|
|
| 57 |
|
| 58 |
return tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True).strip()
|
| 59 |
|
| 60 |
+
print("Step 7: function defined, creating Blocks...", flush=True)
|
| 61 |
+
|
| 62 |
with gr.Blocks(title="MiniCPM5-1B Chat") as demo:
|
| 63 |
gr.Markdown(f"# MiniCPM5-1B Chat\n**Model:** `{MODEL_ID}`\n\nPowered by ZeroGPU free GPU")
|
| 64 |
gr.ChatInterface(
|
|
|
|
| 66 |
title=None,
|
| 67 |
description="First request loads the model (~30s), subsequent calls are faster."
|
| 68 |
)
|
| 69 |
+
|
| 70 |
+
print("Step 8: demo created successfully", flush=True)
|