Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -1,26 +1,39 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from llama_cpp import Llama
|
|
|
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
if __name__ == "__main__":
|
| 26 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from llama_cpp import Llama
|
| 3 |
+
from huggingface_hub import hf_hub_download
|
| 4 |
import os
|
| 5 |
|
| 6 |
+
print("--- Starting Space ---")
|
| 7 |
+
# Download from the Model Repository instead of local Space storage
|
| 8 |
+
print("Downloading model from Model Hub (9.6GB)...")
|
| 9 |
+
try:
|
| 10 |
+
model_path = hf_hub_download(
|
| 11 |
+
repo_id="Arabic250/gemma-4-gguf-export",
|
| 12 |
+
filename="gemma-4-medical.gguf"
|
| 13 |
+
)
|
| 14 |
+
print(f"Model downloaded to: {model_path}")
|
| 15 |
|
| 16 |
+
print("Loading model into Llama-CPP...")
|
| 17 |
+
llm = Llama(
|
| 18 |
+
model_path=model_path,
|
| 19 |
+
n_ctx=2048,
|
| 20 |
+
n_threads=2
|
| 21 |
+
)
|
| 22 |
|
| 23 |
+
def generate_response(message, history):
|
| 24 |
+
prompt = f"USER: {message}\nASSISTANT: "
|
| 25 |
+
response = llm(prompt, max_tokens=512, stop=["USER:"], echo=False)
|
| 26 |
+
return response["choices"][0]["text"]
|
| 27 |
+
|
| 28 |
+
demo = gr.ChatInterface(
|
| 29 |
+
fn=generate_response,
|
| 30 |
+
title="Gemma 4 Medical - GGUF Hub Edition",
|
| 31 |
+
description="This Space pulls the model from Arabic250/gemma-4-gguf-export"
|
| 32 |
+
)
|
| 33 |
+
except Exception as e:
|
| 34 |
+
print(f"Error loading model: {e}")
|
| 35 |
+
with gr.Blocks() as demo:
|
| 36 |
+
gr.Markdown(f"### ⚠️ Error: {e}")
|
| 37 |
|
| 38 |
if __name__ == "__main__":
|
| 39 |
demo.launch()
|