vikhyatk commited on
Commit
57972e0
·
verified ·
1 Parent(s): 92bb3e8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -19
app.py CHANGED
@@ -1,4 +1,4 @@
1
- REVISION = "faa59888f8e93586c753a353bdbf53d00213a7d1"
2
 
3
  try:
4
  import spaces
@@ -46,18 +46,6 @@ moondream = AutoModelForCausalLM.from_pretrained(
46
  device_map={"": "cuda"},
47
  revision=REVISION
48
  )
49
-
50
- # CKPT_DIRS = ["/tmp/md-ckpt/ckpt/ft/song-moon-4c-s15/s72001/"]
51
- # def get_ckpt(filename):
52
- # ckpts = [
53
- # torch.load(os.path.join(dir, filename), map_location="cpu") for dir in CKPT_DIRS
54
- # ]
55
- # avg_ckpt = {
56
- # key.replace("._orig_mod", ""): sum(ckpt[key] for ckpt in ckpts) / len(ckpts)
57
- # for key in ckpts[0]
58
- # }
59
- # return avg_ckpt
60
- # moondream.load_state_dict(get_ckpt("model.pt"))
61
  moondream.eval()
62
 
63
 
@@ -278,7 +266,7 @@ with gr.Blocks(title="moondream vl (new)", css=css, js=js) as demo:
278
  scale=4,
279
  )
280
  submit = gr.Button("Submit")
281
- reasoning = gr.Checkbox(label="Enable reasoning")
282
  img = gr.Image(type="pil", label="Upload an Image")
283
  submit.click(answer_question, [img, prompt, reasoning], [output, thought])
284
  prompt.submit(answer_question, [img, prompt, reasoning], [output, thought])
@@ -362,16 +350,15 @@ with gr.Blocks(title="moondream vl (new)", css=css, js=js) as demo:
362
  img = Resize(768)(img)
363
  w, h = img.size
364
 
365
- coords = json.loads(evt.value[1])
366
- if len(coords) % 2 != 0:
367
- raise ValueError("Only points supported right now.")
368
 
369
  img_clone = img.copy()
370
  draw = ImageDraw.Draw(img_clone)
371
 
372
  for i in range(0, len(coords), 2): # Step by 2 to handle x,y pairs
373
- x = int(coords[i] * w)
374
- y = int(coords[i + 1] * h)
 
375
  draw.ellipse(
376
  (x - 3, y - 3, x + 3, y + 3),
377
  fill="red",
 
1
+ REVISION = "9fd441468eb4ca6091a6fbee26edc1090b55ded7"
2
 
3
  try:
4
  import spaces
 
46
  device_map={"": "cuda"},
47
  revision=REVISION
48
  )
 
 
 
 
 
 
 
 
 
 
 
 
49
  moondream.eval()
50
 
51
 
 
266
  scale=4,
267
  )
268
  submit = gr.Button("Submit")
269
+ reasoning = gr.Checkbox(label="Enable reasoning")
270
  img = gr.Image(type="pil", label="Upload an Image")
271
  submit.click(answer_question, [img, prompt, reasoning], [output, thought])
272
  prompt.submit(answer_question, [img, prompt, reasoning], [output, thought])
 
350
  img = Resize(768)(img)
351
  w, h = img.size
352
 
353
+ points = json.loads(evt.value[1])
 
 
354
 
355
  img_clone = img.copy()
356
  draw = ImageDraw.Draw(img_clone)
357
 
358
  for i in range(0, len(coords), 2): # Step by 2 to handle x,y pairs
359
+ for point in points:
360
+ x = int(point[0] * w)
361
+ y = int(point[1] * h)
362
  draw.ellipse(
363
  (x - 3, y - 3, x + 3, y + 3),
364
  fill="red",