Balázs Thomay commited on
Commit
7162200
·
1 Parent(s): 1b6a143

Add motivational quote generator app with fine-tuned Llama 3.2 model

Browse files

- Fine-tuned Llama 3.2 3B-Instruct with LoRA on motivational quotes dataset
- Simple Gradio interface for generating personalized advice
- MLX framework for efficient inference
- 55MB LoRA adapters tracked with Git LFS

🤖 Generated with Claude Code

README.md CHANGED
@@ -1,14 +1,42 @@
1
- ---
2
- title: Motivational Quote Generator
3
- emoji: 💬
4
- colorFrom: yellow
5
- colorTo: purple
6
- sdk: gradio
7
- sdk_version: 5.0.1
8
- app_file: app.py
9
- pinned: false
10
- license: mit
11
- short_description: Fine tuned Llama-3.2-3B-Instruct for motivational quote
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  ---
13
 
14
- An example chatbot using [Gradio](https://gradio.app), [`huggingface_hub`](https://huggingface.co/docs/huggingface_hub/v0.22.2/en/index), and the [Hugging Face Inference API](https://huggingface.co/docs/api-inference/index).
 
1
+ # 🌟 Motivational Quote Generator
2
+
3
+ A fine-tuned Llama 3.2 3B model that generates motivational quotes and advice. This model has been specifically trained on a curated dataset of inspirational content to provide guidance on various life topics.
4
+
5
+ **🚀 Try it live: [https://huggingface.co/spaces/balazsthomay/motivational-quote-generator](https://huggingface.co/spaces/balazsthomay/motivational-quote-generator)**
6
+
7
+ ## 🎯 Features
8
+
9
+ - **Personalized Advice**: Get motivational quotes tailored to your specific situation
10
+ - **Multiple Topics**: Covers perseverance, leadership, success, personal growth, and more
11
+ - **Adjustable Creativity**: Control the temperature for more or less creative responses
12
+ - **Fast Generation**: Optimized with LoRA fine-tuning for efficient inference
13
+
14
+ ## 🛠️ Technical Details
15
+
16
+ - **Base Model**: Llama 3.2 3B-Instruct (4-bit quantized)
17
+ - **Fine-tuning Method**: LoRA (Low-Rank Adaptation)
18
+ - **Training**: 2000 iterations on curated motivational quotes dataset
19
+ - **Framework**: MLX for efficient Apple Silicon inference
20
+
21
+ ## 💡 Usage
22
+
23
+ Simply enter a topic you'd like advice about, such as:
24
+ - "Give me advice about perseverance"
25
+ - "Give me advice about overcoming fear"
26
+ - "Give me advice about leadership"
27
+
28
+ The model will generate a personalized motivational response to help inspire and guide you.
29
+
30
+ ## 🔧 Model Configuration
31
+
32
+ - **LoRA Rank**: 8
33
+ - **Training Iterations**: 2000
34
+ - **Max Sequence Length**: 2048 tokens
35
+
36
+ ## 📊 Training Data
37
+
38
+ The model was trained on a carefully curated dataset of motivational quotes, with theme-based labeling using Ollama for improved contextual understanding.
39
+
40
  ---
41
 
42
+ *Built with ❤️ using MLX and Gradio*
app.py CHANGED
@@ -1,64 +1,85 @@
1
  import gradio as gr
2
- from huggingface_hub import InferenceClient
 
3
 
4
- """
5
- For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
6
- """
7
- client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
8
-
9
-
10
- def respond(
11
- message,
12
- history: list[tuple[str, str]],
13
- system_message,
14
- max_tokens,
15
- temperature,
16
- top_p,
17
- ):
18
- messages = [{"role": "system", "content": system_message}]
19
-
20
- for val in history:
21
- if val[0]:
22
- messages.append({"role": "user", "content": val[0]})
23
- if val[1]:
24
- messages.append({"role": "assistant", "content": val[1]})
25
-
26
- messages.append({"role": "user", "content": message})
27
-
28
- response = ""
29
-
30
- for message in client.chat_completion(
31
- messages,
32
- max_tokens=max_tokens,
33
- stream=True,
34
- temperature=temperature,
35
- top_p=top_p,
36
- ):
37
- token = message.choices[0].delta.content
38
-
39
- response += token
40
- yield response
41
-
42
-
43
- """
44
- For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
45
- """
46
- demo = gr.ChatInterface(
47
- respond,
48
- additional_inputs=[
49
- gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
50
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
51
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
52
- gr.Slider(
53
- minimum=0.1,
54
- maximum=1.0,
55
- value=0.95,
56
- step=0.05,
57
- label="Top-p (nucleus sampling)",
58
- ),
59
- ],
60
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
 
 
63
  if __name__ == "__main__":
64
- demo.launch()
 
1
  import gradio as gr
2
+ import mlx_lm
3
+ from mlx_lm.sample_utils import make_sampler
4
 
5
+ # Load the fine-tuned model
6
+ print("Loading fine-tuned model...")
7
+ model, tokenizer = mlx_lm.load(
8
+ 'mlx-community/Llama-3.2-3B-Instruct-4bit',
9
+ adapter_path='./models/llama3.2-3b-quotes-lora-mlx'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  )
11
+ print("✅ Model loaded successfully!")
12
+
13
+ def chat_respond(message, temperature):
14
+ """Generate chat response"""
15
+ prompt = f"{message}"
16
+
17
+ # Generate response
18
+ sampler = make_sampler(temp=temperature)
19
+
20
+ try:
21
+ response = mlx_lm.generate(
22
+ model, tokenizer,
23
+ prompt=prompt,
24
+ max_tokens=150,
25
+ sampler=sampler
26
+ )
27
+
28
+ # Clean up the response (remove the original prompt)
29
+ if prompt in response:
30
+ response = response.replace(prompt, "").strip()
31
+
32
+ return response
33
+ except Exception as e:
34
+ return f"Error: {str(e)}"
35
 
36
+ # Create simple Gradio interface
37
+ with gr.Blocks() as demo:
38
+ gr.Markdown("# 🤖 Motivational Quote Generator")
39
+
40
+ with gr.Row():
41
+ temperature = gr.Slider(0.1, 1.5, 0.7, label="Temperature")
42
+
43
+ with gr.Row():
44
+ with gr.Column():
45
+ prompt_input = gr.Textbox(
46
+ label="Your Prompt",
47
+ placeholder="Give me advice about courage",
48
+ lines=2
49
+ )
50
+
51
+ generate_btn = gr.Button("Generate", variant="primary")
52
+
53
+ response_output = gr.Textbox(
54
+ label="Response",
55
+ lines=6,
56
+ interactive=False
57
+ )
58
+
59
+ # Examples
60
+ gr.Examples(
61
+ examples=[
62
+ "Give me advice about perseverance",
63
+ "Give me advice about courage",
64
+ "Give me advice about success",
65
+ "Give me advice about self-discipline"
66
+ ],
67
+ inputs=prompt_input
68
+ )
69
+
70
+ # Event handlers
71
+ generate_btn.click(
72
+ fn=chat_respond,
73
+ inputs=[prompt_input, temperature],
74
+ outputs=response_output
75
+ )
76
+
77
+ prompt_input.submit(
78
+ fn=chat_respond,
79
+ inputs=[prompt_input, temperature],
80
+ outputs=response_output
81
+ )
82
 
83
+ # Launch interface
84
  if __name__ == "__main__":
85
+ demo.launch()
models/0000200_adapters.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9cb263cb8abb8f809dac6db832c91c12cd18ff8754653c9b4e44fc7b40f1ab42
3
+ size 5249791
models/0000400_adapters.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f4115facf6940836839ab4113ed1b1a149f8b99a517c71190196ef895ae2daa5
3
+ size 5249791
models/0000600_adapters.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f9c8cdefd22ff392daa65f0c66e76876753dd544cc947c84392efac2804150c1
3
+ size 5249791
models/0000800_adapters.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:08b2f9f5045dee0d4955181d77db937855be569bb6cbd873ae1215e97c5b4167
3
+ size 5249791
models/0001000_adapters.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d8bf13476136b7213f8dc88745056ecbeaf8f566d2322b3b4d16c277181a92da
3
+ size 5249791
models/0001200_adapters.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3896c58045bf7047e5feb1fa4162eede7c45217253b847a9248dbbadc346f6a3
3
+ size 5249791
models/0001400_adapters.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6bd00dc72deb30b7c76b1a3e7b8bc8ea4e4d66c50e1f562e6d4b1173312a113f
3
+ size 5249791
models/0001600_adapters.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:37b618e666ecf7e914cdfb8289cd7e707cd3aa743fd23ea19fc120ecf9f14150
3
+ size 5249791
models/0001800_adapters.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fd790891ea4ea06417f571945ad71c1bfa13aa494382a719cafa75989f0e0473
3
+ size 5249791
models/0002000_adapters.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:040c43edaa3bbef61b329653e2ff7014fa9ea3faac1505f75a0a3b685365dd54
3
+ size 5249791
models/adapter_config.json ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "adapter_path": "/Users/thomaybalazs/Projects/quotes-finetuning/models/llama3.2-3b-quotes-lora-mlx",
3
+ "batch_size": 2,
4
+ "config": null,
5
+ "data": "data/training/mlx_format",
6
+ "fine_tune_type": "lora",
7
+ "grad_checkpoint": true,
8
+ "iters": 2000,
9
+ "learning_rate": 5e-05,
10
+ "lora_parameters": {
11
+ "rank": 8,
12
+ "dropout": 0.0,
13
+ "scale": 20.0
14
+ },
15
+ "lr_schedule": null,
16
+ "mask_prompt": false,
17
+ "max_seq_length": 2048,
18
+ "model": "mlx-community/Llama-3.2-3B-Instruct-4bit",
19
+ "num_layers": 16,
20
+ "optimizer": "adam",
21
+ "optimizer_config": {
22
+ "adam": {},
23
+ "adamw": {},
24
+ "muon": {},
25
+ "sgd": {},
26
+ "adafactor": {}
27
+ },
28
+ "resume_adapter_file": null,
29
+ "save_every": 200,
30
+ "seed": 0,
31
+ "steps_per_eval": 100,
32
+ "steps_per_report": 25,
33
+ "test": false,
34
+ "test_batches": 500,
35
+ "train": true,
36
+ "val_batches": 25,
37
+ "wandb": null
38
+ }
models/adapters.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:040c43edaa3bbef61b329653e2ff7014fa9ea3faac1505f75a0a3b685365dd54
3
+ size 5249791
requirements.txt CHANGED
@@ -1,5 +1,6 @@
1
- huggingface_hub==0.25.2
2
- mlx-lm
3
- gradio
4
- torch
5
- transformers
 
 
1
+ mlx-lm>=0.18.0
2
+ gradio>=4.0.0
3
+ mlx>=0.18.0
4
+ transformers>=4.40.0
5
+ torch>=2.0.0
6
+ numpy>=1.24.0