YaTharThShaRma999
commited on
Commit
•
b125944
1
Parent(s):
f8baec0
Update usage.py
Browse files
usage.py
CHANGED
@@ -62,4 +62,33 @@ for output in llm_speech(prompt, functions='default', function_executer=function
|
|
62 |
previous_prompts.append(prompt)
|
63 |
previous_answers.append(full_output)
|
64 |
torch.cuda.empty_cache()
|
65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
previous_prompts.append(prompt)
|
63 |
previous_answers.append(full_output)
|
64 |
torch.cuda.empty_cache()
|
65 |
+
|
66 |
+
|
67 |
+
from llama_cpp import Llama
|
68 |
+
from llama_cpp.llama_chat_format import MoondreamChatHandler
|
69 |
+
|
70 |
+
chat_handler = MoondreamChatHandler.from_pretrained(
|
71 |
+
repo_id="vikhyatk/moondream2",
|
72 |
+
filename="*mmproj*",
|
73 |
+
)
|
74 |
+
|
75 |
+
llm = Llama.from_pretrained(
|
76 |
+
repo_id="vikhyatk/moondream2",
|
77 |
+
filename="*text-model*",
|
78 |
+
chat_handler=chat_handler,
|
79 |
+
n_ctx=2048, # n_ctx should be increased to accommodate the image embedding
|
80 |
+
)
|
81 |
+
|
82 |
+
response = llm.create_chat_completion(
|
83 |
+
messages = [
|
84 |
+
{
|
85 |
+
"role": "user",
|
86 |
+
"content": [
|
87 |
+
{"type" : "text", "text": "What's in this image?"},
|
88 |
+
{"type": "image_url", "image_url": {"url": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg" } }
|
89 |
+
|
90 |
+
]
|
91 |
+
}
|
92 |
+
]
|
93 |
+
)
|
94 |
+
print(response["choices"][0]["text"])
|