Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -26,19 +26,25 @@ prompt_suffix = "<|end|>\n"
|
|
26 |
|
27 |
# Inference function
|
28 |
def ask_phi(image, question):
|
29 |
-
|
|
|
30 |
|
31 |
prompt = f"{user_prompt}<|image_1|>\n{question}{prompt_suffix}{assistant_prompt}"
|
32 |
print(f">>> Prompt\n{prompt}")
|
33 |
images = og.Images.open(image)
|
34 |
inputs = processor(prompt=prompt, images=images, return_tensors="pt")
|
35 |
|
|
|
36 |
# start here
|
|
|
|
|
37 |
params = og.GeneratorParams(model)
|
38 |
params.set_inputs(inputs)
|
39 |
params.set_search_options(max_length=7680)
|
40 |
|
41 |
generator = og.Generator(model, params)
|
|
|
|
|
42 |
start_time = time.time()
|
43 |
|
44 |
response = ""
|
@@ -47,7 +53,7 @@ def ask_phi(image, question):
|
|
47 |
|
48 |
new_token = generator.get_next_tokens()[0]
|
49 |
response += tokenizer_stream.decode(new_token) + " "
|
50 |
-
print(response)
|
51 |
|
52 |
total_run_time = time.time() - start_time
|
53 |
print(f"Total Time : {total_run_time:.2f}")
|
|
|
26 |
|
27 |
# Inference function
|
28 |
def ask_phi(image, question):
|
29 |
+
print("Entered ask_phi")
|
30 |
+
start_time = time.time()
|
31 |
|
32 |
prompt = f"{user_prompt}<|image_1|>\n{question}{prompt_suffix}{assistant_prompt}"
|
33 |
print(f">>> Prompt\n{prompt}")
|
34 |
images = og.Images.open(image)
|
35 |
inputs = processor(prompt=prompt, images=images, return_tensors="pt")
|
36 |
|
37 |
+
print(f"Pre-processing took {time.time() - start_time} seconds")
|
38 |
# start here
|
39 |
+
print("Setting up the generator")
|
40 |
+
start_time = time.time()
|
41 |
params = og.GeneratorParams(model)
|
42 |
params.set_inputs(inputs)
|
43 |
params.set_search_options(max_length=7680)
|
44 |
|
45 |
generator = og.Generator(model, params)
|
46 |
+
print(f"Generator setup took {time.time() - start_time} seconds")
|
47 |
+
|
48 |
start_time = time.time()
|
49 |
|
50 |
response = ""
|
|
|
53 |
|
54 |
new_token = generator.get_next_tokens()[0]
|
55 |
response += tokenizer_stream.decode(new_token) + " "
|
56 |
+
print(f">>> Response\n{response}")
|
57 |
|
58 |
total_run_time = time.time() - start_time
|
59 |
print(f"Total Time : {total_run_time:.2f}")
|