44import base64
55import numpy as np
66from PIL import Image , ImageChops
7- from transformers .pipelines import Conversation
87
98IMAGE_PREFIX = "data:image/"
109DEFAULT_IMAGE_FORMAT = "PNG"
@@ -29,13 +28,6 @@ def default(self, obj):
2928 + ";base64,"
3029 + base64 .b64encode (buf .getvalue ()).decode ()
3130 )
32- elif isinstance (obj , Conversation ):
33- return {
34- "uuid" : str (obj .uuid ),
35- "past_user_inputs" : obj .past_user_inputs ,
36- "generated_responses" : obj .generated_responses ,
37- "new_user_input" : obj .new_user_input ,
38- }
3931 else :
4032 return json .JSONEncoder .default (self , obj )
4133
@@ -69,29 +61,12 @@ def do(cls, raw):
6961 else :
7062 return raw
7163
72- @classmethod
73- def convert_conversation (cls , d : Dict [str , Any ]):
74- if set (d .keys ()) == conversation_keys :
75- return Conversation (
76- text = d ["new_user_input" ],
77- conversation_id = d ["uuid" ],
78- past_user_inputs = d ["past_user_inputs" ],
79- generated_responses = d ["generated_responses" ],
80- )
81- return None
82-
8364 @classmethod
8465 def convert_dict (cls , d : Dict [str , Any ]):
85- conversation = cls .convert_conversation (d )
86- if conversation is not None :
87- return conversation
8866 tmp = {}
8967 for k , v in d .items ():
9068 if isinstance (v , dict ):
91- if set (v .keys ()) == conversation_keys :
92- tmp [k ] = Conversation (text = v ["new_user_input" ])
93- else :
94- tmp [k ] = cls .convert_dict (v )
69+ tmp [k ] = cls .convert_dict (v )
9570 elif isinstance (v , list ):
9671 tmp [k ] = cls .convert_list (v )
9772 elif isinstance (v , str ):
0 commit comments