paralym commited on
Commit
f13019e
1 Parent(s): 5616769

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +187 -165
app.py CHANGED
@@ -255,27 +255,49 @@ def bot(history):
255
  print(input_ids.device)
256
  print(image_tensor.device)
257
  # import pdb;pdb.set_trace()
258
- with torch.inference_mode():
259
- output_ids = our_chatbot.model.generate(
260
- input_ids,
261
- images=image_tensor,
262
- do_sample=True,
263
- temperature=0.2,
264
- max_new_tokens=1024,
265
- streamer=streamer,
266
- use_cache=False,
267
- stopping_criteria=[stopping_criteria],
268
- )
269
-
270
- outputs = our_chatbot.tokenizer.decode(output_ids[0]).strip()
271
- if outputs.endswith(stop_str):
272
- outputs = outputs[: -len(stop_str)]
273
- our_chatbot.conversation.messages[-1][-1] = outputs
274
-
275
- history[-1] = [text, outputs]
276
-
277
- return history
278
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
279
 
280
  txt = gr.Textbox(
281
  scale=4,
@@ -355,150 +377,150 @@ with gr.Blocks(
355
  "text": "この猫の目の大きさは、どのような理由で他の猫と比べて特に大きく見えますか?",
356
  },
357
  ],
358
- [
359
- {
360
- "files": [
361
- f"{cur_dir}/examples/172197131626056_P7966202.png",
362
- ],
363
- "text": "Why this image funny?",
364
- },
365
- ],
366
- [
367
- {
368
- "files": [
369
- f"{cur_dir}/examples/norway.jpg",
370
- ],
371
- "text": "Analysieren, in welchem Land diese Szene höchstwahrscheinlich gedreht wurde.",
372
- },
373
- ],
374
- [
375
- {
376
- "files": [
377
- f"{cur_dir}/examples/totoro.jpg",
378
- ],
379
- "text": "¿En qué anime aparece esta escena? ¿Puedes presentarlo?",
380
- },
381
- ],
382
- [
383
- {
384
- "files": [
385
- f"{cur_dir}/examples/africa.jpg",
386
- ],
387
- "text": "इस तस्वीर में हर एक दृश्य तत्व का क्या प्रतिनिधित्व करता है?",
388
- },
389
- ],
390
- [
391
- {
392
- "files": [
393
- f"{cur_dir}/examples/hot_ballon.jpg",
394
- ],
395
- "text": "ฉากบอลลูนลมร้อนในภาพนี้อาจอยู่ที่ไหน? สถานที่นี้มีความพิเศษอย่างไร?",
396
- },
397
- ],
398
- [
399
- {
400
- "files": [
401
- f"{cur_dir}/examples/bar.jpg",
402
- ],
403
- "text": "Você pode me dar ideias de design baseadas no tema de coquetéis deste letreiro?",
404
- },
405
- ],
406
- [
407
- {
408
- "files": [
409
- f"{cur_dir}/examples/pink_lake.jpg",
410
- ],
411
- "text": "Обясни защо езерото на този остров е в този цвят.",
412
- },
413
- ],
414
- [
415
- {
416
- "files": [
417
- f"{cur_dir}/examples/hanzi.jpg",
418
- ],
419
- "text": "Can you describe in Hebrew the evolution process of these four Chinese characters from pictographs to modern characters?",
420
- },
421
- ],
422
- [
423
- {
424
- "files": [
425
- f"{cur_dir}/examples/ballon.jpg",
426
- ],
427
- "text": "இந்த காட்சியை விவரிக்கவும், மேலும் இந்த படத்தின் அடிப்படையில் துருக்கியில் இந்த காட்சியுடன் தொடர்பான சில பிரபலமான நிகழ்வுகள் என்ன?",
428
- },
429
- ],
430
- [
431
- {
432
- "files": [
433
- f"{cur_dir}/examples/pie.jpg",
434
- ],
435
- "text": "Décrivez ce graphique. Quelles informations pouvons-nous en tirer?",
436
- },
437
- ],
438
- [
439
- {
440
- "files": [
441
- f"{cur_dir}/examples/camera.jpg",
442
- ],
443
- "text": "Apa arti dari dua angka di sebelah kiri yang ditampilkan di layar kamera?",
444
- },
445
- ],
446
- [
447
- {
448
- "files": [
449
- f"{cur_dir}/examples/dog.jpg",
450
- ],
451
- "text": "이 강아지의 표정을 보고 어떤 기분이나 감정을 느끼고 있는지 설명해 주시겠어요?",
452
- },
453
- ],
454
- [
455
- {
456
- "files": [
457
- f"{cur_dir}/examples/book.jpg",
458
- ],
459
- "text": "What language is the text in, and what does the title mean in English?",
460
- },
461
- ],
462
- [
463
- {
464
- "files": [
465
- f"{cur_dir}/examples/food.jpg",
466
- ],
467
- "text": "Unaweza kunipa kichocheo cha kutengeneza hii pancake?",
468
- },
469
- ],
470
- [
471
- {
472
- "files": [
473
- f"{cur_dir}/examples/line chart.jpg",
474
- ],
475
- "text": "Hãy trình bày những xu hướng mà bạn quan sát được từ biểu đồ và hiện tượng xã hội tiềm ẩn từ đó.",
476
- },
477
- ],
478
- [
479
- {
480
- "files": [
481
- f"{cur_dir}/examples/south africa.jpg",
482
- ],
483
- "text": "Waar is hierdie plek? Help my om ’n reisroete vir hierdie land te beplan.",
484
- },
485
- ],
486
- [
487
- {
488
- "files": [
489
- f"{cur_dir}/examples/girl.jpg",
490
- ],
491
- "text": "لماذا هذه الصورة مضحكة؟",
492
- },
493
- ],
494
- [
495
- {
496
- "files": [
497
- f"{cur_dir}/examples/eagles.jpg",
498
- ],
499
- "text": "Какой креатив должен быть в этом логотипе?",
500
- },
501
- ],
502
  ],
503
  inputs=[chat_input],
504
  label="Image",
 
255
  print(input_ids.device)
256
  print(image_tensor.device)
257
  # import pdb;pdb.set_trace()
258
+ # with torch.inference_mode():
259
+ # output_ids = our_chatbot.model.generate(
260
+ # input_ids,
261
+ # images=image_tensor,
262
+ # do_sample=True,
263
+ # temperature=0.2,
264
+ # max_new_tokens=1024,
265
+ # streamer=streamer,
266
+ # use_cache=False,
267
+ # stopping_criteria=[stopping_criteria],
268
+ # )
269
+
270
+ # outputs = our_chatbot.tokenizer.decode(output_ids[0]).strip()
271
+ # if outputs.endswith(stop_str):
272
+ # outputs = outputs[: -len(stop_str)]
273
+ # our_chatbot.conversation.messages[-1][-1] = outputs
274
+
275
+ # history[-1] = [text, outputs]
276
+
277
+ # return history
278
+ generate_kwargs = dict(
279
+ input_ids=input_ids,
280
+ streamer=streamer,
281
+ images=image_tensor,
282
+ max_new_tokens=1024,
283
+ do_sample=True,
284
+ temperature=0.2,
285
+ num_beams=1,
286
+ use_cache=False,
287
+ stopping_criteria=[stopping_criteria],
288
+ )
289
+
290
+ t = Thread(target=our_chatbot.model.generate, kwargs=generate_kwargs)
291
+ t.start()
292
+
293
+ outputs = []
294
+ for text in streamer:
295
+ outputs.append(text)
296
+ yield "".join(outputs)
297
+
298
+ our_chatbot.conversation.messages[-1][-1] = "".join(outputs)
299
+ history[-1] = [text, "".join(outputs)]
300
+
301
 
302
  txt = gr.Textbox(
303
  scale=4,
 
377
  "text": "この猫の目の大きさは、どのような理由で他の猫と比べて特に大きく見えますか?",
378
  },
379
  ],
380
+ # [
381
+ # {
382
+ # "files": [
383
+ # f"{cur_dir}/examples/172197131626056_P7966202.png",
384
+ # ],
385
+ # "text": "Why this image funny?",
386
+ # },
387
+ # ],
388
+ # [
389
+ # {
390
+ # "files": [
391
+ # f"{cur_dir}/examples/norway.jpg",
392
+ # ],
393
+ # "text": "Analysieren, in welchem Land diese Szene höchstwahrscheinlich gedreht wurde.",
394
+ # },
395
+ # ],
396
+ # [
397
+ # {
398
+ # "files": [
399
+ # f"{cur_dir}/examples/totoro.jpg",
400
+ # ],
401
+ # "text": "¿En qué anime aparece esta escena? ¿Puedes presentarlo?",
402
+ # },
403
+ # ],
404
+ # [
405
+ # {
406
+ # "files": [
407
+ # f"{cur_dir}/examples/africa.jpg",
408
+ # ],
409
+ # "text": "इस तस्वीर में हर एक दृश्य तत्व का क्या प्रतिनिधित्व करता है?",
410
+ # },
411
+ # ],
412
+ # [
413
+ # {
414
+ # "files": [
415
+ # f"{cur_dir}/examples/hot_ballon.jpg",
416
+ # ],
417
+ # "text": "ฉากบอลลูนลมร้อนในภาพนี้อาจอยู่ที่ไหน? สถานที่นี้มีความพิเศษอย่างไร?",
418
+ # },
419
+ # ],
420
+ # [
421
+ # {
422
+ # "files": [
423
+ # f"{cur_dir}/examples/bar.jpg",
424
+ # ],
425
+ # "text": "Você pode me dar ideias de design baseadas no tema de coquetéis deste letreiro?",
426
+ # },
427
+ # ],
428
+ # [
429
+ # {
430
+ # "files": [
431
+ # f"{cur_dir}/examples/pink_lake.jpg",
432
+ # ],
433
+ # "text": "Обясни защо езерото на този остров е в този цвят.",
434
+ # },
435
+ # ],
436
+ # [
437
+ # {
438
+ # "files": [
439
+ # f"{cur_dir}/examples/hanzi.jpg",
440
+ # ],
441
+ # "text": "Can you describe in Hebrew the evolution process of these four Chinese characters from pictographs to modern characters?",
442
+ # },
443
+ # ],
444
+ # [
445
+ # {
446
+ # "files": [
447
+ # f"{cur_dir}/examples/ballon.jpg",
448
+ # ],
449
+ # "text": "இந்த காட்சியை விவரிக்கவும், மேலும் இந்த படத்தின் அடிப்படையில் துருக்கியில் இந்த காட்சியுடன் தொடர்பான சில பிரபலமான நிகழ்வுகள் என்ன?",
450
+ # },
451
+ # ],
452
+ # [
453
+ # {
454
+ # "files": [
455
+ # f"{cur_dir}/examples/pie.jpg",
456
+ # ],
457
+ # "text": "Décrivez ce graphique. Quelles informations pouvons-nous en tirer?",
458
+ # },
459
+ # ],
460
+ # [
461
+ # {
462
+ # "files": [
463
+ # f"{cur_dir}/examples/camera.jpg",
464
+ # ],
465
+ # "text": "Apa arti dari dua angka di sebelah kiri yang ditampilkan di layar kamera?",
466
+ # },
467
+ # ],
468
+ # [
469
+ # {
470
+ # "files": [
471
+ # f"{cur_dir}/examples/dog.jpg",
472
+ # ],
473
+ # "text": "이 강아지의 표정을 보고 어떤 기분이나 감정을 느끼고 있는지 설명해 주시겠어요?",
474
+ # },
475
+ # ],
476
+ # [
477
+ # {
478
+ # "files": [
479
+ # f"{cur_dir}/examples/book.jpg",
480
+ # ],
481
+ # "text": "What language is the text in, and what does the title mean in English?",
482
+ # },
483
+ # ],
484
+ # [
485
+ # {
486
+ # "files": [
487
+ # f"{cur_dir}/examples/food.jpg",
488
+ # ],
489
+ # "text": "Unaweza kunipa kichocheo cha kutengeneza hii pancake?",
490
+ # },
491
+ # ],
492
+ # [
493
+ # {
494
+ # "files": [
495
+ # f"{cur_dir}/examples/line chart.jpg",
496
+ # ],
497
+ # "text": "Hãy trình bày những xu hướng mà bạn quan sát được từ biểu đồ và hiện tượng xã hội tiềm ẩn từ đó.",
498
+ # },
499
+ # ],
500
+ # [
501
+ # {
502
+ # "files": [
503
+ # f"{cur_dir}/examples/south africa.jpg",
504
+ # ],
505
+ # "text": "Waar is hierdie plek? Help my om ’n reisroete vir hierdie land te beplan.",
506
+ # },
507
+ # ],
508
+ # [
509
+ # {
510
+ # "files": [
511
+ # f"{cur_dir}/examples/girl.jpg",
512
+ # ],
513
+ # "text": "لماذا هذه الصورة مضحكة؟",
514
+ # },
515
+ # ],
516
+ # [
517
+ # {
518
+ # "files": [
519
+ # f"{cur_dir}/examples/eagles.jpg",
520
+ # ],
521
+ # "text": "Какой креатив должен быть в этом логотипе?",
522
+ # },
523
+ # ],
524
  ],
525
  inputs=[chat_input],
526
  label="Image",