wolfofbackstreet commited on
Commit
f895b87
·
verified ·
1 Parent(s): 019895a

update model

Browse files
Files changed (3) hide show
  1. Dockerfile +0 -2
  2. app.py +118 -126
  3. requirements.txt +3 -5
Dockerfile CHANGED
@@ -6,8 +6,6 @@ COPY ./requirements.txt /code/requirements.txt
6
 
7
  RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
8
 
9
- RUN pip install -U gptqmodel --no-build-isolation -v
10
-
11
  # Set up a new user named "user" with user ID 1000
12
  RUN useradd -m -u 1000 user
13
  # Switch to the "user" user
 
6
 
7
  RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
8
 
 
 
9
  # Set up a new user named "user" with user ID 1000
10
  RUN useradd -m -u 1000 user
11
  # Switch to the "user" user
app.py CHANGED
@@ -1,127 +1,119 @@
1
- from transformers import AutoTokenizer, AutoModelForCausalLM, GPTQConfig
2
- import inspect
3
- from typing import get_type_hints, Callable, Any
4
- import gradio as gr
5
-
6
- model_name = "wolfofbackstreet/SmolLM2-135M-int4-qptq-v2"
7
- # Load tokenizer
8
- tokenizer = AutoTokenizer.from_pretrained(model_name)
9
-
10
- # Define GPTQ configuration
11
- #gptq_config = GPTQConfig(bits=4, use_exllama=False, use_cuda_fp16=False)
12
-
13
- # Load pre-quantized model on CPU
14
- model = AutoModelForCausalLM.from_pretrained(
15
- model_name,
16
- device_map="cpu" # Explicitly enforce CPU execution
17
- # quantization_config=gptq_config,
18
- )
19
-
20
-
21
- def parse_docstring(func):
22
- doc = inspect.getdoc(func)
23
- if not doc:
24
- return {"title": "Untitled", "description": ""}
25
-
26
- lines = doc.splitlines()
27
- title = next((line.replace("Title:", "").strip() for line in lines if line.startswith("Title:")), "Untitled")
28
- description = "\n".join(line.strip() for line in lines if line.startswith("Description:"))
29
- description = description.replace("Description:", "").strip()
30
-
31
- return {"title": title, "description": description}
32
-
33
- def gradio_app_with_docs(func: Callable) -> Callable:
34
- sig = inspect.signature(func)
35
- type_hints = get_type_hints(func)
36
- metadata = parse_docstring(func)
37
-
38
- """
39
- A decorator that automatically builds and launches a Gradio interface
40
- based on function type hints.
41
-
42
- Args:
43
- func: A callable with type-hinted parameters and return type.
44
-
45
- Returns:
46
- The wrapped function with a `.launch()` method to start the app.
47
- """
48
- # Infer Gradio components from type hints
49
- def _map_type(t: type) -> gr.Component:
50
- if t == str:
51
- return gr.Textbox(label="Input")
52
- elif t == int:
53
- return gr.Number(precision=0)
54
- elif t == float:
55
- return gr.Number()
56
- elif t == bool:
57
- return gr.Checkbox()
58
- elif hasattr(t, "__origin__") and t.__origin__ == list: # Handle List[type]
59
- elem_type = t.__args__[0]
60
- if elem_type == str:
61
- return gr.Dropdown(choices=["Option1", "Option2"])
62
- else:
63
- raise ValueError(f"Unsupported list element type: {elem_type}")
64
- else:
65
- raise ValueError(f"Unsupported type: {t}")
66
-
67
- # Extract function signature and type hints
68
- sig = inspect.signature(func)
69
- type_hints = get_type_hints(func)
70
-
71
- # Map parameters to Gradio inputs
72
- inputs = []
73
- for name, param in sig.parameters.items():
74
- if name == "self":
75
- continue # Skip self in class methods
76
- param_type = type_hints.get(name, Any)
77
- component = _map_type(param_type)
78
- component.label = name.replace("_", " ").title()
79
- inputs.append(component)
80
-
81
- # Map return type to Gradio output
82
- return_type = type_hints.get("return", Any)
83
- outputs = _map_type(return_type)
84
-
85
- # Wrap function with Gradio interface
86
- interface = gr.Interface(fn=func, inputs=inputs, outputs=outputs)
87
-
88
- with gr.Blocks() as demo:
89
- gr.Markdown(f"## {metadata['title']}\n{metadata['description']}")
90
- interface = gr.Interface(fn=func, inputs=inputs, outputs=outputs)
91
-
92
- def wrapper(*args, **kwargs):
93
- return func(*args, **kwargs)
94
-
95
- wrapper.launch = lambda: demo.launch()
96
- return wrapper
97
-
98
-
99
- @gradio_app_with_docs
100
- def generate_response(prompt: str) -> str:
101
- """
102
- Title: Super Tiny GPTQ V2 Model on CPU
103
- Description: A Simple app to test out the potentials of small GPTQ LLM model.
104
-
105
- Args:
106
- prompt (str): A simple prompt.
107
-
108
- Returns:
109
- str: Simplified response.
110
- """
111
- inputs = tokenizer(prompt, return_tensors="pt").to("cpu") # Move inputs to CPU
112
- outputs = model.generate(
113
- **inputs,
114
- max_new_tokens=50,
115
- temperature=0.7,
116
- top_p=0.9
117
- )
118
- return tokenizer.decode(outputs[0], skip_special_tokens=True)
119
-
120
- # # Example usage
121
- # prompt = "Explain quantum computing in simple terms."
122
- # response = generate_response(prompt)
123
- # print(response)
124
-
125
-
126
- if __name__ == "__main__":
127
  generate_response.launch()
 
1
+ import inspect
2
+ from typing import get_type_hints, Callable, Any
3
+ import gradio as gr
4
+ from transformers import AutoTokenizer, AutoModelForCausalLM
5
+
6
+ model_id = "unsloth/SmolLM2-135M-Instruct-GGUF"
7
+ filename = "SmolLM2-135M-Instruct-Q8_0.gguf"
8
+
9
+ tokenizer = AutoTokenizer.from_pretrained(model_id, gguf_file=filename)
10
+ model = AutoModelForCausalLM.from_pretrained(model_id, gguf_file=filename)
11
+
12
+
13
+ def parse_docstring(func):
14
+ doc = inspect.getdoc(func)
15
+ if not doc:
16
+ return {"title": "Untitled", "description": ""}
17
+
18
+ lines = doc.splitlines()
19
+ title = next((line.replace("Title:", "").strip() for line in lines if line.startswith("Title:")), "Untitled")
20
+ description = "\n".join(line.strip() for line in lines if line.startswith("Description:"))
21
+ description = description.replace("Description:", "").strip()
22
+
23
+ return {"title": title, "description": description}
24
+
25
+ def gradio_app_with_docs(func: Callable) -> Callable:
26
+ sig = inspect.signature(func)
27
+ type_hints = get_type_hints(func)
28
+ metadata = parse_docstring(func)
29
+
30
+ """
31
+ A decorator that automatically builds and launches a Gradio interface
32
+ based on function type hints.
33
+
34
+ Args:
35
+ func: A callable with type-hinted parameters and return type.
36
+
37
+ Returns:
38
+ The wrapped function with a `.launch()` method to start the app.
39
+ """
40
+ # Infer Gradio components from type hints
41
+ def _map_type(t: type) -> gr.Component:
42
+ if t == str:
43
+ return gr.Textbox(label="Input")
44
+ elif t == int:
45
+ return gr.Number(precision=0)
46
+ elif t == float:
47
+ return gr.Number()
48
+ elif t == bool:
49
+ return gr.Checkbox()
50
+ elif hasattr(t, "__origin__") and t.__origin__ == list: # Handle List[type]
51
+ elem_type = t.__args__[0]
52
+ if elem_type == str:
53
+ return gr.Dropdown(choices=["Option1", "Option2"])
54
+ else:
55
+ raise ValueError(f"Unsupported list element type: {elem_type}")
56
+ else:
57
+ raise ValueError(f"Unsupported type: {t}")
58
+
59
+ # Extract function signature and type hints
60
+ sig = inspect.signature(func)
61
+ type_hints = get_type_hints(func)
62
+
63
+ # Map parameters to Gradio inputs
64
+ inputs = []
65
+ for name, param in sig.parameters.items():
66
+ if name == "self":
67
+ continue # Skip self in class methods
68
+ param_type = type_hints.get(name, Any)
69
+ component = _map_type(param_type)
70
+ component.label = name.replace("_", " ").title()
71
+ inputs.append(component)
72
+
73
+ # Map return type to Gradio output
74
+ return_type = type_hints.get("return", Any)
75
+ outputs = _map_type(return_type)
76
+
77
+ # Wrap function with Gradio interface
78
+ interface = gr.Interface(fn=func, inputs=inputs, outputs=outputs)
79
+
80
+ with gr.Blocks() as demo:
81
+ gr.Markdown(f"## {metadata['title']}\n{metadata['description']}")
82
+ interface = gr.Interface(fn=func, inputs=inputs, outputs=outputs)
83
+
84
+ def wrapper(*args, **kwargs):
85
+ return func(*args, **kwargs)
86
+
87
+ wrapper.launch = lambda: demo.launch()
88
+ return wrapper
89
+
90
+
91
+ @gradio_app_with_docs
92
+ def generate_response(prompt: str) -> str:
93
+ """
94
+ Title: Super Tiny GPTQ V2 Model on CPU
95
+ Description: A Simple app to test out the potentials of small GPTQ LLM model.
96
+
97
+ Args:
98
+ prompt (str): A simple prompt.
99
+
100
+ Returns:
101
+ str: Simplified response.
102
+ """
103
+ inputs = tokenizer(prompt, return_tensors="pt").to("cpu") # Move inputs to CPU
104
+ outputs = model.generate(
105
+ **inputs,
106
+ max_new_tokens=50,
107
+ temperature=0.7,
108
+ top_p=0.9
109
+ )
110
+ return tokenizer.decode(outputs[0], skip_special_tokens=True)
111
+
112
+ # # Example usage
113
+ # prompt = "Explain quantum computing in simple terms."
114
+ # response = generate_response(prompt)
115
+ # print(response)
116
+
117
+
118
+ if __name__ == "__main__":
 
 
 
 
 
 
 
 
119
  generate_response.launch()
requirements.txt CHANGED
@@ -1,5 +1,3 @@
1
- optimum
2
- gradio
3
- torch
4
- transformers
5
- accelerate
 
1
+ numpy==2.2.5
2
+ gguf
3
+ transformers