|
1 | 1 | import base64
|
2 | 2 | import io
|
3 | 3 | import time
|
| 4 | +import copy |
4 | 5 | import datetime
|
5 | 6 | import uvicorn
|
6 | 7 | import gradio as gr
|
@@ -739,10 +740,50 @@ def post_invocations(self, b64images, quality):
|
739 | 740 | return images
|
740 | 741 | else:
|
741 | 742 | return b64images
|
| 743 | + |
| 744 | + def print_content(self, req: InvocationsRequest): |
| 745 | + try: |
| 746 | + new_req = copy.deepcopy(req) |
| 747 | + if req.img2img_payload != None: |
| 748 | + new_req.img2img_payload.init_images=['a total of ' + str(len(new_req.img2img_payload.init_images)) + ' images were sent as base 64'] |
| 749 | + print(new_req) |
| 750 | + except Exception as e: |
| 751 | + print("printing method did not work, bypassing...error:", e) |
| 752 | + |
| 753 | + def truncate_content(self, value, limit=200): |
| 754 | + if isinstance(value, str): # Only truncate if the value is a string |
| 755 | + if len(value) > limit: |
| 756 | + return value[:limit] + '...' |
| 757 | + return value |
| 758 | + |
| 759 | + def req_logging(self, obj, indent=0): |
| 760 | + if "__dict__" in dir(obj): # if value is an object, dive into it |
| 761 | + items = obj.__dict__.items() |
| 762 | + elif isinstance(obj, dict): # if value is a dictionary, get items |
| 763 | + items = obj.items() |
| 764 | + elif isinstance(obj, list): # if value is a list, enumerate items |
| 765 | + items = enumerate(obj) |
| 766 | + else: # if value is not an object or dict or list, just print it |
| 767 | + print(" " * indent + f"{self.truncate_content(obj)}") |
| 768 | + return |
| 769 | + |
| 770 | + for attr, value in items: |
| 771 | + if value is None or value == {} or value == []: |
| 772 | + continue |
| 773 | + if isinstance(value, (list, dict)) or "__dict__" in dir(value): |
| 774 | + print(" " * indent + f"{attr}:") |
| 775 | + self.req_logging(value, indent + 1) |
| 776 | + else: |
| 777 | + print(" " * indent + f"{attr}: {self.truncate_content(value)}") |
| 778 | + |
742 | 779 |
|
743 | 780 | def invocations(self, req: InvocationsRequest):
|
744 |
| - print('-------invocation------') |
745 |
| - print(req) |
| 781 | + print('----------------------------invocation---------------------------') |
| 782 | + # self.print_nested_dictionary(req, 50) # this is where debug happens |
| 783 | + try: |
| 784 | + self.req_logging(req) |
| 785 | + except Exception as e: |
| 786 | + print("console Log ran into issue: ",e) |
746 | 787 |
|
747 | 788 | try:
|
748 | 789 | if req.vae != None:
|
|
0 commit comments