Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,39 +1,26 @@
|
|
1 |
-
import
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
# --batched mode
|
28 |
-
inputs = processor(prompts, add_end_of_utterance_token=False, return_tensors="pt").to(device)
|
29 |
-
# --single sample mode
|
30 |
-
# inputs = processor(prompts[0], return_tensors="pt").to(device)
|
31 |
-
|
32 |
-
# Generation args
|
33 |
-
exit_condition = processor.tokenizer("<end_of_utterance>", add_special_tokens=False).input_ids
|
34 |
-
bad_words_ids = processor.tokenizer(["<image>", "<fake_token_around_image>"], add_special_tokens=False).input_ids
|
35 |
-
|
36 |
-
generated_ids = model.generate(**inputs, eos_token_id=exit_condition, bad_words_ids=bad_words_ids, max_length=100)
|
37 |
-
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)
|
38 |
-
for i, t in enumerate(generated_text):
|
39 |
-
print(f"{i}:\n{t}\n")
|
|
|
1 |
+
from text_generation import Client
|
2 |
+
|
3 |
+
API_TOKEN = ""
|
4 |
+
API_URL = "https://api-inference.huggingface.co/models/HuggingFaceM4/idefics-80b-instruct"
|
5 |
+
DECODING_STRATEGY = "Greedy"
|
6 |
+
QUERY = "User: What is in this image?![](https://upload.wikimedia.org/wikipedia/commons/8/86/Id%C3%A9fix.JPG)<end_of_utterance>\nAssistant:"
|
7 |
+
|
8 |
+
client = Client(
|
9 |
+
base_url=API_URL,
|
10 |
+
headers={"x-use-cache": "0", "Authorization": f"Bearer {API_TOKEN}"},
|
11 |
+
)
|
12 |
+
generation_args = {
|
13 |
+
"max_new_tokens": 256,
|
14 |
+
"repetition_penalty": 1.0,
|
15 |
+
"stop_sequences": ["<end_of_utterance>", "\nUser:"],
|
16 |
+
}
|
17 |
+
|
18 |
+
if DECODING_STRATEGY == "Greedy":
|
19 |
+
generation_args["do_sample"] = False
|
20 |
+
elif DECODING_STRATEGY == "Top P Sampling":
|
21 |
+
generation_args["temperature"] = 1.
|
22 |
+
generation_args["do_sample"] = True
|
23 |
+
generation_args["top_p"] = 0.95
|
24 |
+
|
25 |
+
generated_text = client.generate(prompt=QUERY, **generation_args)
|
26 |
+
print(generated_text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|