aadya1762 commited on
Commit
3a14fb3
·
1 Parent(s): d71e3b1

add examples functionality

Browse files
gemmademo/__init__.py CHANGED
@@ -1,11 +1,9 @@
1
  from ._chat import GradioChat
2
  from ._model import LlamaCppGemmaModel
3
  from ._prompts import PromptManager
4
- from ._utils import huggingface_login
5
 
6
  __all__ = [
7
  "GradioChat",
8
  "LlamaCppGemmaModel",
9
  "PromptManager",
10
- "huggingface_login",
11
  ]
 
1
  from ._chat import GradioChat
2
  from ._model import LlamaCppGemmaModel
3
  from ._prompts import PromptManager
 
4
 
5
  __all__ = [
6
  "GradioChat",
7
  "LlamaCppGemmaModel",
8
  "PromptManager",
 
9
  ]
gemmademo/_chat.py CHANGED
@@ -67,23 +67,77 @@ class GradioChat:
67
  response_stream = self.model.generate_response(prompt)
68
  yield from response_stream
69
 
70
- chat_interface = gr.ChatInterface(
71
- chat_fn,
72
- textbox=gr.Textbox(placeholder="Ask me something...", container=False),
73
- additional_inputs=[
74
- gr.Dropdown(
75
- choices=self.model_options,
76
- value=self.current_model_name,
77
- label="Select Gemma Model",
78
- ),
79
- gr.Dropdown(
80
- choices=self.task_options,
81
- value=self.current_task_name,
82
- label="Select Task",
83
- ),
84
  ],
85
- )
86
- chat_interface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
 
88
  def run(self):
89
  self._chat()
 
67
  response_stream = self.model.generate_response(prompt)
68
  yield from response_stream
69
 
70
+ # Examples for each task type
71
+ examples = {
72
+ "Question Answering": [
73
+ "What is quantum computing?",
74
+ "How do neural networks work?",
75
+ "Explain climate change in simple terms.",
 
 
 
 
 
 
 
 
76
  ],
77
+ "Text Generation": [
78
+ "Once upon a time in a distant galaxy...",
79
+ "The abandoned house at the end of the street had...",
80
+ "In the year 2150, humanity discovered...",
81
+ ],
82
+ "Code Completion": [
83
+ "def fibonacci(n):",
84
+ "class BinarySearchInAList:",
85
+ "async def fetch_data(url):",
86
+ ],
87
+ }
88
+
89
+ def update_examples(task):
90
+ return examples.get(task)
91
+
92
+ with gr.Blocks() as demo:
93
+ with gr.Row():
94
+ with gr.Column(scale=3):
95
+ task_dropdown = gr.Dropdown(
96
+ choices=self.task_options,
97
+ value=self.current_task_name,
98
+ label="Select Task",
99
+ )
100
+ model_dropdown = gr.Dropdown(
101
+ choices=self.model_options,
102
+ value=self.current_model_name,
103
+ label="Select Gemma Model",
104
+ )
105
+
106
+ chat_interface = gr.ChatInterface(
107
+ chat_fn,
108
+ additional_inputs=[model_dropdown, task_dropdown],
109
+ textbox=gr.Textbox(
110
+ placeholder="Ask me something...", container=False
111
+ ),
112
+ )
113
+
114
+ with gr.Column(scale=1):
115
+ gr.Markdown(
116
+ """
117
+ ## Tips
118
+
119
+ - First response will be slower (model loading)
120
+ - Switching models clears chat history
121
+ - For code completion, start with function definition
122
+ - Shorter queries work better
123
+ - Larger models (7B) need more memory but give better results
124
+ """
125
+ )
126
+
127
+ gr.Markdown("## Examples")
128
+ examples_list = gr.Examples(
129
+ examples=examples[self.current_task_name],
130
+ inputs=chat_interface.textbox,
131
+ )
132
+
133
+ # Update examples when task changes
134
+ task_dropdown.change(
135
+ fn=update_examples,
136
+ inputs=task_dropdown,
137
+ outputs=examples_list,
138
+ )
139
+
140
+ demo.launch()
141
 
142
  def run(self):
143
  self._chat()
gemmademo/_model.py CHANGED
@@ -25,22 +25,22 @@ class LlamaCppGemmaModel:
25
  AVAILABLE_MODELS: Dict[str, Dict] = {
26
  "gemma-3b": {
27
  "model_path": "models/gemma-3-1b-it-Q5_K_M.gguf",
28
- "repo_id": "bartowski/google_gemma-3-1b-it-GGUF",
29
  "filename": "google_gemma-3-1b-it-Q5_K_M.gguf", # Better quantization
30
  "description": "3B parameters, instruction-tuned (Q5_K_M)",
31
  "type": "instruct",
32
  },
33
  "gemma-2b": {
34
  "model_path": "models/gemma-2b-it.gguf",
35
- "repo_id": "MaziyarPanahi/gemma-2b-it-GGUF",
36
  "filename": "gemma-2b-it.Q4_K_M.gguf",
37
  "description": "2B parameters, instruction-tuned",
38
  "type": "instruct",
39
  },
40
  "gemma-7b": {
41
  "model_path": "models/gemma-7b-it.gguf",
42
- "repo_id": "rahuldshetty/gemma-7b-it-gguf-quantized",
43
- "filename": "gemma-7b-it-Q4_K_M.gguf",
44
  "description": "7B parameters in GGUF format",
45
  "type": "base",
46
  },
 
25
  AVAILABLE_MODELS: Dict[str, Dict] = {
26
  "gemma-3b": {
27
  "model_path": "models/gemma-3-1b-it-Q5_K_M.gguf",
28
+ "repo_id": "bartowski/google_gemma-3-1b-it-GGUF",
29
  "filename": "google_gemma-3-1b-it-Q5_K_M.gguf", # Better quantization
30
  "description": "3B parameters, instruction-tuned (Q5_K_M)",
31
  "type": "instruct",
32
  },
33
  "gemma-2b": {
34
  "model_path": "models/gemma-2b-it.gguf",
35
+ "repo_id": "MaziyarPanahi/gemma-2b-it-GGUF",
36
  "filename": "gemma-2b-it.Q4_K_M.gguf",
37
  "description": "2B parameters, instruction-tuned",
38
  "type": "instruct",
39
  },
40
  "gemma-7b": {
41
  "model_path": "models/gemma-7b-it.gguf",
42
+ "repo_id": "rahuldshetty/gemma-7b-it-gguf-quantized",
43
+ "filename": "gemma-7b-it-Q4_K_M.gguf",
44
  "description": "7B parameters in GGUF format",
45
  "type": "base",
46
  },
gemmademo/_utils.py DELETED
@@ -1,7 +0,0 @@
1
- def huggingface_login(token: str):
2
- """
3
- Login to Hugging Face using the token
4
- """
5
- from huggingface_hub import login
6
-
7
- login(token=token)