davidberenstein1957 HF staff commited on
Commit
e9178fb
1 Parent(s): 46850bc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -4
app.py CHANGED
@@ -3,12 +3,34 @@ import json
3
  import spaces
4
  import gradio as gr
5
  import torch
6
- from distilabel.llms import vLLM
7
  from distilabel.steps.tasks.argillalabeller import ArgillaLabeller
8
 
 
 
9
 
10
- llm = vLLM(
11
- model="Qwen/Qwen2-0.5B-Instruct-GGUF"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  )
13
  task = ArgillaLabeller(llm=llm)
14
  task.load()
@@ -30,7 +52,7 @@ def process_fields(fields):
30
  fields = [fields]
31
  return [field if isinstance(field, dict) else json.loads(field) for field in fields]
32
 
33
-
34
  def process_records_gradio(records, example_records, fields, question):
35
  try:
36
  # Convert string inputs to dictionaries
 
3
  import spaces
4
  import gradio as gr
5
  import torch
6
+ from distilabel.llms import LlamaCppLLM
7
  from distilabel.steps.tasks.argillalabeller import ArgillaLabeller
8
 
9
+ file_path = os.path.join(os.path.dirname(__file__), "qwen2-0_5b-instruct-fp16.gguf")
10
+ download_url = "https://huggingface.co/Qwen/Qwen2-0.5B-Instruct-GGUF/resolve/main/qwen2-0_5b-instruct-fp16.gguf?download=true"
11
 
12
+
13
+ if not os.path.exists(file_path):
14
+ import requests
15
+ import tqdm
16
+
17
+ response = requests.get(download_url, stream=True)
18
+ total_length = int(response.headers.get("content-length"))
19
+
20
+ with open(file_path, "wb") as f:
21
+ for chunk in tqdm.tqdm(
22
+ response.iter_content(chunk_size=1024),
23
+ total=total_length,
24
+ unit="KB",
25
+ unit_scale=True,
26
+ ):
27
+ f.write(chunk)
28
+
29
+
30
+ llm = LlamaCppLLM(
31
+ model_path=file_path,
32
+ n_gpu_layers=-1,
33
+ n_ctx=1024 * 4,
34
  )
35
  task = ArgillaLabeller(llm=llm)
36
  task.load()
 
52
  fields = [fields]
53
  return [field if isinstance(field, dict) else json.loads(field) for field in fields]
54
 
55
+ @spaces.GPU
56
  def process_records_gradio(records, example_records, fields, question):
57
  try:
58
  # Convert string inputs to dictionaries