Spaces:
Running on Zero
Running on Zero
Commit ·
b0f9e4b
1
Parent(s): 9ec4d75
init
Browse files
apps/gradio-space/src/gradio_space/app.py
CHANGED
|
@@ -46,6 +46,19 @@ def chat(message: str, history: list) -> str:
|
|
| 46 |
return _backend.chat(messages)
|
| 47 |
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
def build_demo() -> gr.Blocks:
|
| 50 |
model_repo = os.environ.get("MODEL_REPO", "Qwen/Qwen2.5-3B-Instruct-GGUF")
|
| 51 |
model_file = os.environ.get("MODEL_FILE", "qwen2.5-3b-instruct-q4_k_m.gguf")
|
|
@@ -56,7 +69,7 @@ def build_demo() -> gr.Blocks:
|
|
| 56 |
f"""
|
| 57 |
# Small Model Chat
|
| 58 |
|
| 59 |
-
Local inference via **{backend_name}**.
|
| 60 |
|
| 61 |
- **Repo:** `{model_repo}`
|
| 62 |
- **File:** `{model_file}`
|
|
@@ -64,10 +77,12 @@ Local inference via **{backend_name}**. Model loads on first message.
|
|
| 64 |
Part of the [Build Small Hackathon](https://huggingface.co/build-small-hackathon).
|
| 65 |
"""
|
| 66 |
)
|
|
|
|
| 67 |
gr.ChatInterface(
|
| 68 |
fn=chat,
|
| 69 |
examples=["Hello! What can you help me with?", "Explain llama.cpp in one sentence."],
|
| 70 |
)
|
|
|
|
| 71 |
|
| 72 |
return demo
|
| 73 |
|
|
|
|
| 46 |
return _backend.chat(messages)
|
| 47 |
|
| 48 |
|
| 49 |
+
def warmup() -> str:
|
| 50 |
+
if _model_ready:
|
| 51 |
+
return "Model ready."
|
| 52 |
+
|
| 53 |
+
if _load_error:
|
| 54 |
+
return _load_error
|
| 55 |
+
|
| 56 |
+
return (
|
| 57 |
+
"Model not loaded yet. It will download from Hugging Face Hub on the "
|
| 58 |
+
"first chat message — this can take a few minutes on CPU."
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
|
| 62 |
def build_demo() -> gr.Blocks:
|
| 63 |
model_repo = os.environ.get("MODEL_REPO", "Qwen/Qwen2.5-3B-Instruct-GGUF")
|
| 64 |
model_file = os.environ.get("MODEL_FILE", "qwen2.5-3b-instruct-q4_k_m.gguf")
|
|
|
|
| 69 |
f"""
|
| 70 |
# Small Model Chat
|
| 71 |
|
| 72 |
+
Local inference via **{backend_name}**.
|
| 73 |
|
| 74 |
- **Repo:** `{model_repo}`
|
| 75 |
- **File:** `{model_file}`
|
|
|
|
| 77 |
Part of the [Build Small Hackathon](https://huggingface.co/build-small-hackathon).
|
| 78 |
"""
|
| 79 |
)
|
| 80 |
+
status = gr.Markdown(warmup())
|
| 81 |
gr.ChatInterface(
|
| 82 |
fn=chat,
|
| 83 |
examples=["Hello! What can you help me with?", "Explain llama.cpp in one sentence."],
|
| 84 |
)
|
| 85 |
+
demo.load(warmup, outputs=status)
|
| 86 |
|
| 87 |
return demo
|
| 88 |
|