Norod78 commited on
Commit
3755dbb
verified
1 Parent(s): eebdd94

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -46
app.py CHANGED
@@ -8,25 +8,19 @@ from transformers import AutoProcessor, Gemma3ForConditionalGeneration, TextIter
8
  import spaces
9
  import time
10
 
11
- TITLE = " 诪讜讚诇 诪讘讜住住 讙诪讛 3 诇讬爪讬专转 砖讬专讬诐 诪讟讜驻砖讬诐 讘注讘专讬转 "
12
  DESCRIPTION= """
13
- 谞讬转谉 诇讘拽砖 砖讬专 注诇 讘住讬住 讟拽住讟, 转诪讜谞讛 讜讜讬讚讗讜
14
-
15
- 讘讻诇 驻注诐, 讬讜讜爪专 砖讬专 砖讜谞讛, 讗讝 讗诐 诇讗 讗讛讘转诐, 讗驻砖专 诇谞住讜转 砖讜讘 注诐 讗讜转讜 讛驻专讜诪驻讟
16
-
17
- [讛诪讜讚诇 讝诪讬谉 诇讛讜专讚讛](https://huggingface.co/Norod78/gemma-3_4b_hebrew-lyrics-finetune)
18
-
19
- 讛诪讜讚诇 讻旨讜旨讬址旨讬诇 注状讬 [讚讜专讜谉 讗讚诇专](https://linktr.ee/Norod78)
20
  """
21
 
22
  # model config
23
- model_4b_name = "Norod78/gemma-3_4b_hebrew-lyrics-finetune"
24
- model_4b = Gemma3ForConditionalGeneration.from_pretrained(
25
- model_4b_name,
26
  device_map="auto",
27
  torch_dtype=torch.bfloat16
28
  ).eval()
29
- processor_4b = AutoProcessor.from_pretrained(model_4b_name)
30
  # I will add timestamp later
31
  def extract_video_frames(video_path, num_frames=8):
32
  cap = cv2.VideoCapture(video_path)
@@ -90,31 +84,6 @@ def format_conversation_history(chat_history):
90
 
91
  @spaces.GPU(duration=120)
92
  def generate_response(input_data, chat_history, max_new_tokens, system_prompt, temperature, top_p, top_k, repetition_penalty):
93
- """
94
- Creates silly song lyrics in Hebrew based on user input and conversation history.
95
-
96
- Args:
97
- input_data (dict or str):
98
- - If dict: must include 'text' (str) and optional 'files' (list of image/video file paths).
99
- - If str: treated as plain text input.
100
- chat_history (list of dict):
101
- Sequence of past messages, each with keys 'role' and 'content'.
102
- max_new_tokens (int):
103
- Maximum number of tokens to generate for the response.
104
- system_prompt (str):
105
- Optional system-level instruction to guide the style and content of the response.
106
- temperature (float):
107
- Sampling temperature; higher values yield more diverse outputs.
108
- top_p (float):
109
- Nucleus sampling threshold for cumulative probability selection.
110
- top_k (int):
111
- Limits sampling to the top_k most likely tokens at each step.
112
- repetition_penalty (float):
113
- Penalty factor to discourage the model from repeating the same tokens.
114
-
115
- Yields:
116
- str: Streaming chunks of the generated Hebrew song lyrics in real time.
117
- """
118
 
119
  if isinstance(input_data, dict) and "text" in input_data:
120
  text = input_data["text"]
@@ -132,7 +101,7 @@ def generate_response(input_data, chat_history, max_new_tokens, system_prompt, t
132
  messages[-1]["content"].extend(new_message["content"])
133
  else:
134
  messages.append(new_message)
135
- model = model_4b
136
  processor = processor_4b
137
  inputs = processor.apply_chat_template(
138
  messages,
@@ -167,10 +136,10 @@ chat_interface = gr.ChatInterface(
167
  gr.Slider(label="Max new tokens", minimum=100, maximum=2000, step=1, value=512),
168
  gr.Textbox(
169
  label="System Prompt",
170
- value="讗转讛 诪砖讜专专 讬砖专讗诇讬, 讻讜转讘 砖讬专讬诐 讘注讘专讬转",
171
  lines=4,
172
- placeholder="砖谞讛 讗转 讛讛讙讚专讜转 砖诇 讛诪讜讚诇",
173
- text_align = 'right', rtl = True
174
  ),
175
  gr.Slider(label="Temperature", minimum=0.1, maximum=2.0, step=0.1, value=0.2),
176
  gr.Slider(label="Top-p", minimum=0.05, maximum=1.0, step=0.05, value=0.4),
@@ -178,20 +147,19 @@ chat_interface = gr.ChatInterface(
178
  gr.Slider(label="Repetition Penalty", minimum=1.0, maximum=2.0, step=0.05, value=1.1),
179
  ],
180
  examples=[
181
- [{"text": "讻转讜讘 诇讬 讘讘拽砖讛 砖讬专 讛诪转讗专 讗转 讛转诪讜谞讛", "files": ["examples/image1.jpg"]}],
182
- [{"text": "转驻讜讞 讗讚诪讛 注诐 讞专讚讛 讞讘专转讬转"}]
183
  ],
184
  textbox=gr.MultimodalTextbox(
185
- rtl=True,
186
  label="拽诇讟",
187
  file_types=["image", "video"],
188
  file_count="multiple",
189
- placeholder="讘拽砖讜 砖讬专 讜/讗讜 讛注诇讜 转诪讜谞讛",
190
  ),
191
  cache_examples=False,
192
  type="messages",
193
  fill_height=True,
194
- stop_btn="讛驻住拽",
195
  css_paths=["style.css"],
196
  multimodal=True,
197
  title=TITLE,
 
8
  import spaces
9
  import time
10
 
11
+ TITLE = " google/gemma-3-270m-it "
12
  DESCRIPTION= """
13
+ It's so small
 
 
 
 
 
 
14
  """
15
 
16
  # model config
17
+ model_270m_name = "google/gemma-3-270m-it"
18
+ model_270m = Gemma3ForConditionalGeneration.from_pretrained(
19
+ model_270m_name,
20
  device_map="auto",
21
  torch_dtype=torch.bfloat16
22
  ).eval()
23
+ processor_4b = AutoProcessor.from_pretrained(model_270m_name)
24
  # I will add timestamp later
25
  def extract_video_frames(video_path, num_frames=8):
26
  cap = cv2.VideoCapture(video_path)
 
84
 
85
  @spaces.GPU(duration=120)
86
  def generate_response(input_data, chat_history, max_new_tokens, system_prompt, temperature, top_p, top_k, repetition_penalty):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
 
88
  if isinstance(input_data, dict) and "text" in input_data:
89
  text = input_data["text"]
 
101
  messages[-1]["content"].extend(new_message["content"])
102
  else:
103
  messages.append(new_message)
104
+ model = model_270m
105
  processor = processor_4b
106
  inputs = processor.apply_chat_template(
107
  messages,
 
136
  gr.Slider(label="Max new tokens", minimum=100, maximum=2000, step=1, value=512),
137
  gr.Textbox(
138
  label="System Prompt",
139
+ value="You are a very helpful multimodal assistant",
140
  lines=4,
141
+ placeholder="Change the settings",
142
+ text_align = 'left', rtl = False
143
  ),
144
  gr.Slider(label="Temperature", minimum=0.1, maximum=2.0, step=0.1, value=0.2),
145
  gr.Slider(label="Top-p", minimum=0.05, maximum=1.0, step=0.05, value=0.4),
 
147
  gr.Slider(label="Repetition Penalty", minimum=1.0, maximum=2.0, step=0.05, value=1.1),
148
  ],
149
  examples=[
150
+ [{"text": "Write a poem which describes this image", "files": ["examples/image1.jpg"]}],
 
151
  ],
152
  textbox=gr.MultimodalTextbox(
153
+ rtl=False,
154
  label="拽诇讟",
155
  file_types=["image", "video"],
156
  file_count="multiple",
157
+ placeholder="Input text, image or video",
158
  ),
159
  cache_examples=False,
160
  type="messages",
161
  fill_height=True,
162
+ stop_btn="Stop",
163
  css_paths=["style.css"],
164
  multimodal=True,
165
  title=TITLE,