bigemma2999 commited on
Commit
d77fb43
·
verified ·
1 Parent(s): 9778888

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -19
app.py CHANGED
@@ -1,27 +1,20 @@
 
 
 
1
  import gradio as gr
2
- from transformers import AutoTokenizer, AutoModelForCausalLM
3
- import torch
4
 
5
- # Model path
6
- MODEL_ID = "TheBloke/dolphin-2.6-mixtral-8x7b-GGUF"
7
 
8
- # Load model & tokenizer
9
- tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
10
- model = AutoModelForCausalLM.from_pretrained(
11
- MODEL_ID,
12
- torch_dtype=torch.float16,
13
- low_cpu_mem_usage=True,
14
- device_map="auto"
15
- )
16
 
17
  def chat_fn(prompt, max_new_tokens=256, temperature=0.7):
18
- inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
19
- outputs = model.generate(
20
- **inputs,
21
- max_new_tokens=max_new_tokens,
22
- temperature=temperature
23
- )
24
- return tokenizer.decode(outputs[0], skip_special_tokens=True)
25
 
26
  iface = gr.Interface(
27
  fn=chat_fn,
 
1
+ import os
2
+ os.system("pip install llama-cpp-python==0.2.75 --quiet")
3
+
4
  import gradio as gr
5
+ from llama_cpp import Llama
 
6
 
7
+ MODEL_PATH = "dolphin-2.6-mixtral-8x7b.Q4_K_M.gguf" # Quantized file
 
8
 
9
+ # Download model if not present
10
+ if not os.path.exists(MODEL_PATH):
11
+ os.system(f"wget https://huggingface.co/TheBloke/dolphin-2.6-mixtral-8x7b-GGUF/resolve/main/{MODEL_PATH}")
12
+
13
+ llm = Llama(model_path=MODEL_PATH, n_ctx=2048, n_threads=4)
 
 
 
14
 
15
  def chat_fn(prompt, max_new_tokens=256, temperature=0.7):
16
+ output = llm(prompt, max_tokens=max_new_tokens, temperature=temperature)
17
+ return output["choices"][0]["text"]
 
 
 
 
 
18
 
19
  iface = gr.Interface(
20
  fn=chat_fn,