Arabic250 commited on
Commit
de1db51
·
verified ·
1 Parent(s): d6df91e

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +30 -17
app.py CHANGED
@@ -1,26 +1,39 @@
1
  import gradio as gr
2
  from llama_cpp import Llama
 
3
  import os
4
 
5
- # تحميل النموذج
6
- print("Loading model...")
7
- llm = Llama(
8
- model_path="gemma-4-medical.gguf",
9
- n_ctx=2048,
10
- n_threads=2
11
- )
 
 
12
 
13
- def generate_response(message, history):
14
- prompt = f"USER: {message}
15
- ASSISTANT: "
16
- response = llm(prompt, max_tokens=512, stop=["USER:"], echo=False)
17
- return response["choices"][0]["text"]
 
18
 
19
- demo = gr.ChatInterface(
20
- fn=generate_response,
21
- title="Gemma 4 Medical GGUF",
22
- description="Powered by llama-cpp-python inside HF Spaces"
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()