Arabic250 commited on
Commit
bbc047b
·
verified ·
1 Parent(s): 1871bcf

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +15 -26
app.py CHANGED
@@ -1,39 +1,28 @@
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()
 
1
  import gradio as gr
2
  from llama_cpp import Llama
3
  from huggingface_hub import hf_hub_download
 
4
 
5
+ print("--- Starting Deployment ---")
6
+
 
7
  try:
8
+ print("Downloading GGUF...")
9
  model_path = hf_hub_download(
10
+ repo_id='Arabic250/gemma-4-gguf-export',
11
+ filename='gemma-4-medical.gguf'
 
 
 
 
 
 
 
 
12
  )
13
+
14
+ print("Initializing Llama model...")
15
+ llm = Llama(model_path=model_path, n_ctx=2048)
16
 
17
+ def chat(message, history):
18
+ output = llm(f"USER: {message}\nASSISTANT: ", max_tokens=256, stop=['USER:'])
19
+ return output['choices'][0]['text']
 
20
 
21
+ demo = gr.ChatInterface(fn=chat, title='Gemma 4 Medical')
 
 
 
 
22
  except Exception as e:
23
+ print(f'Error: {e}')
24
  with gr.Blocks() as demo:
25
+ gr.Markdown(f'# Error loading model: {e}')
26
 
27
+ if __name__ == '__main__':
28
  demo.launch()