Spaces:
Runtime error
Runtime error
Update app_dialogue.py
Browse files- app_dialogue.py +14 -3
app_dialogue.py
CHANGED
|
@@ -14,6 +14,20 @@ from gradio_client.client import DEFAULT_TEMP_DIR
|
|
| 14 |
from text_generation import Client
|
| 15 |
from transformers import AutoProcessor
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
MODELS = [ # TODO uncomment
|
| 19 |
"HuggingFaceM4/idefics-9b-instruct",
|
|
@@ -519,9 +533,7 @@ with gr.Blocks(title="IDEFICS Playground", theme=gr.themes.Base()) as demo:
|
|
| 519 |
stream = client.generate_stream(prompt=query, **generation_args)
|
| 520 |
|
| 521 |
acc_text = ""
|
| 522 |
-
import time
|
| 523 |
for idx, response in enumerate(stream):
|
| 524 |
-
start = time.time()
|
| 525 |
text_token = response.token.text
|
| 526 |
|
| 527 |
if response.details:
|
|
@@ -539,7 +551,6 @@ with gr.Blocks(title="IDEFICS Playground", theme=gr.themes.Base()) as demo:
|
|
| 539 |
last_turn = chat_history.pop(-1)
|
| 540 |
last_turn[-1] += acc_text
|
| 541 |
chat_history.append(last_turn)
|
| 542 |
-
print(">", time.time() - start)
|
| 543 |
yield "", None, chat_history
|
| 544 |
acc_text = ""
|
| 545 |
|
|
|
|
| 14 |
from text_generation import Client
|
| 15 |
from transformers import AutoProcessor
|
| 16 |
|
| 17 |
+
def timer_decorator(func):
|
| 18 |
+
def wrapper(*args, **kwargs):
|
| 19 |
+
start_time = time.time()
|
| 20 |
+
result = func(*args, **kwargs)
|
| 21 |
+
end_time = time.time()
|
| 22 |
+
elapsed_time = end_time - start_time
|
| 23 |
+
print(f"{func.__name__} took {elapsed_time:.5f} seconds to run.")
|
| 24 |
+
return result
|
| 25 |
+
return wrapper
|
| 26 |
+
|
| 27 |
+
gr.Blocks.preprocess_data = timer_decorator(gr.Blocks.preprocess_data)
|
| 28 |
+
gr.Blocks.call_function = timer_decorator(gr.Blocks.call_function)
|
| 29 |
+
gr.Blocks.postprocess_data = timer_decorator(gr.Blocks.postprocess_data)
|
| 30 |
+
|
| 31 |
|
| 32 |
MODELS = [ # TODO uncomment
|
| 33 |
"HuggingFaceM4/idefics-9b-instruct",
|
|
|
|
| 533 |
stream = client.generate_stream(prompt=query, **generation_args)
|
| 534 |
|
| 535 |
acc_text = ""
|
|
|
|
| 536 |
for idx, response in enumerate(stream):
|
|
|
|
| 537 |
text_token = response.token.text
|
| 538 |
|
| 539 |
if response.details:
|
|
|
|
| 551 |
last_turn = chat_history.pop(-1)
|
| 552 |
last_turn[-1] += acc_text
|
| 553 |
chat_history.append(last_turn)
|
|
|
|
| 554 |
yield "", None, chat_history
|
| 555 |
acc_text = ""
|
| 556 |
|