Voodude commited on
Commit
4f083b6
·
verified ·
1 Parent(s): 9550429

Fix Gradio 6 ChatInterface: drop type=, use ChatInterface as demo

Browse files
Files changed (1) hide show
  1. app.py +36 -44
app.py CHANGED
@@ -207,62 +207,54 @@ def chat(
207
  raise gr.Error(f"Generation failed: {errors[0]}")
208
 
209
 
210
- CSS = """
211
- #col-container { max-width: 920px; margin: 0 auto; }
212
- .dark .gradio-container { color: var(--body-text-color); }
213
- """
214
-
215
  DESCRIPTION = f"""
216
- # Gemma 4 E2B
217
  Chat demo for Google's edge-sized **Gemma 4** model
218
- ([{BASE_MODEL}]({f"https://huggingface.co/{BASE_MODEL}"})):
219
  2.3B effective parameters, 128K context, **text + image + audio**.
220
 
221
- This Space runs the instruction-tuned checkpoint
222
- [`{MODEL_ID}`](https://huggingface.co/{MODEL_ID}) on ZeroGPU.
223
  The [pretrained base](https://huggingface.co/{BASE_MODEL}) is for fine-tuning, not chat.
224
 
225
  **Tips:** put the image *before* your question; put audio *after* it.
226
- Official model card: [google/gemma-4-E2B](https://huggingface.co/google/gemma-4-E2B)
227
  """
228
 
229
  EXAMPLES = [
230
- {"text": "Write a short joke about saving RAM."},
231
- {
232
- "text": "What is shown in this image?",
233
- "files": ["examples/golden_gate.png"],
234
- },
235
- {
236
- "text": (
237
- "Transcribe the following speech segment in its original language. "
238
- "Follow these specific instructions for formatting the answer:\n"
239
- "* Only output the transcription, with no newlines.\n"
240
- "* When transcribing numbers, write the digits, i.e. write 1.7 and not one point seven, "
241
- "and write 3 instead of three."
242
- ),
243
- "files": ["examples/journal1.wav"],
244
- },
 
245
  ]
246
 
247
- with gr.Blocks(theme=gr.themes.Citrus(), css=CSS, fill_height=True) as demo:
248
- with gr.Column(elem_id="col-container"):
249
- gr.Markdown(DESCRIPTION)
250
- chatbot = gr.ChatInterface(
251
- fn=chat,
252
- type="messages",
253
- multimodal=True,
254
- examples=EXAMPLES,
255
- additional_inputs=[
256
- gr.Checkbox(label="Thinking mode", value=False),
257
- gr.Slider(64, 1024, value=512, step=32, label="Max new tokens"),
258
- ],
259
- additional_inputs_accordion=gr.Accordion("Settings", open=False),
260
- textbox=gr.MultimodalTextbox(
261
- file_types=["image", ".wav", ".mp3", ".flac", ".ogg", ".m4a", ".mp4", ".webm"],
262
- placeholder="Ask Gemma 4 E2B — attach an image or a short audio clip…",
263
- show_label=False,
264
- ),
265
- )
266
 
267
  if __name__ == "__main__":
268
  demo.launch(mcp_server=True)
 
207
  raise gr.Error(f"Generation failed: {errors[0]}")
208
 
209
 
 
 
 
 
 
210
  DESCRIPTION = f"""
 
211
  Chat demo for Google's edge-sized **Gemma 4** model
212
+ ([{BASE_MODEL}](https://huggingface.co/{BASE_MODEL})):
213
  2.3B effective parameters, 128K context, **text + image + audio**.
214
 
215
+ Runs the instruction-tuned checkpoint [`{MODEL_ID}`](https://huggingface.co/{MODEL_ID}) on ZeroGPU.
 
216
  The [pretrained base](https://huggingface.co/{BASE_MODEL}) is for fine-tuning, not chat.
217
 
218
  **Tips:** put the image *before* your question; put audio *after* it.
 
219
  """
220
 
221
  EXAMPLES = [
222
+ [{"text": "Write a short joke about saving RAM."}, False, 512],
223
+ [{"text": "What is shown in this image?", "files": ["examples/golden_gate.png"]}, False, 512],
224
+ [
225
+ {
226
+ "text": (
227
+ "Transcribe the following speech segment in its original language. "
228
+ "Follow these specific instructions for formatting the answer:\n"
229
+ "* Only output the transcription, with no newlines.\n"
230
+ "* When transcribing numbers, write the digits, i.e. write 1.7 and not one point seven, "
231
+ "and write 3 instead of three."
232
+ ),
233
+ "files": ["examples/journal1.wav"],
234
+ },
235
+ False,
236
+ 512,
237
+ ],
238
  ]
239
 
240
+ demo = gr.ChatInterface(
241
+ fn=chat,
242
+ multimodal=True,
243
+ title="Gemma 4 E2B",
244
+ description=DESCRIPTION,
245
+ examples=EXAMPLES,
246
+ cache_examples=False,
247
+ additional_inputs=[
248
+ gr.Checkbox(label="Thinking mode", value=False),
249
+ gr.Slider(64, 1024, value=512, step=32, label="Max new tokens"),
250
+ ],
251
+ additional_inputs_accordion="Settings",
252
+ textbox=gr.MultimodalTextbox(
253
+ file_types=["image", ".wav", ".mp3", ".flac", ".ogg", ".m4a", ".mp4", ".webm"],
254
+ placeholder="Ask Gemma 4 E2B — attach an image or a short audio clip…",
255
+ show_label=False,
256
+ ),
257
+ )
 
258
 
259
  if __name__ == "__main__":
260
  demo.launch(mcp_server=True)