GPTfree api commited on
Commit
5488267
·
verified ·
1 Parent(s): af95914

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from vllm import LLM
2
+ from vllm.sampling_params import SamplingParams
3
+ from huggingface_hub import hf_hub_download
4
+ from datetime import datetime, timedelta
5
+
6
+ model_name = "mistralai/Pixtral-Large-Instruct-2411"
7
+
8
+ def load_system_prompt(repo_id: str, filename: str) -> str:
9
+ file_path = hf_hub_download(repo_id=repo_id, filename=filename)
10
+ with open(file_path, 'r') as file:
11
+ system_prompt = file.read()
12
+ today = datetime.today().strftime('%Y-%m-%d')
13
+ yesterday = (datetime.today() - timedelta(days=1)).strftime('%Y-%m-%d')
14
+ model_name = repo_id.split("/")[-1]
15
+ return system_prompt.format(name=model_name, today=today, yesterday=yesterday)
16
+
17
+ SYSTEM_PROMPT = load_system_prompt(model_name, "SYSTEM_PROMPT.txt")
18
+
19
+ image_url = "https://huggingface.co/datasets/patrickvonplaten/random_img/resolve/main/europe.png"
20
+
21
+ messages = [
22
+ {"role": "system", "content": SYSTEM_PROMPT},
23
+ {
24
+ "role": "user",
25
+ "content": [
26
+ {
27
+ "type": "text",
28
+ "text": "Which of the depicted countries has the best food? Which the second and third and fourth? Name the country, its color on the map and one its city that is visible on the map, but is not the capital. Make absolutely sure to only name a city that can be seen on the map.",
29
+ },
30
+ {"type": "image_url", "image_url": {"url": image_url}},
31
+ ],
32
+ },
33
+ ]
34
+
35
+ sampling_params = SamplingParams(max_tokens=512)
36
+
37
+ # note that running this model on GPU requires over 300 GB of GPU RAM
38
+ llm = LLM(model=model_name, config_format="mistral", load_format="mistral", tokenizer_mode="mistral", tensor_parallel_size=8, limit_mm_per_prompt={"image": 4})
39
+
40
+ outputs = llm.chat(messages, sampling_params=sampling_params)
41
+
42
+ print(outputs[0].outputs[0].text)