fuyu_example.py 878 B

1234567891011121314151617181920212223242526272829303132333435
  1. import os
  2. from PIL import Image
  3. from aphrodite import LLM, SamplingParams
  4. def run_fuyu():
  5. llm = LLM(model="adept/fuyu-8b", max_model_len=4096)
  6. # single-image prompt
  7. prompt = "What is the content of this image?\n"
  8. image_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),
  9. "burg.jpg")
  10. image = Image.open(image_path)
  11. sampling_params = SamplingParams(temperature=1.1,
  12. min_p=0.06,
  13. max_tokens=512)
  14. outputs = llm.generate(
  15. {
  16. "prompt": prompt,
  17. "multi_modal_data": {
  18. "image": image
  19. },
  20. },
  21. sampling_params=sampling_params)
  22. for o in outputs:
  23. generated_text = o.outputs[0].text
  24. print(generated_text)
  25. if __name__ == "__main__":
  26. run_fuyu()