Spaces:
Sleeping
Sleeping
Update app.py
Browse files26 unmodified lines272829303132333435363738394052 unmodified lines9394959697989917 unmodified lines11711811912012112212326 unmodified linesdef llava(message, history):if message["files"]:image = message["files"][0]else:for hist in history:if type(hist[0])==tuple:image = hist[0][0]txt = message["text"]gr.Info("Analyzing image")image = Image.open(image).convert("RGB")52 unmodified linesuser_prompt = message# Handle image processingif message["files"]:inputs = llava(message, history)streamer = TextIteratorStreamer(processor, skip_prompt=True, **{"skip_special_tokens": True})generation_kwargs = dict(inputs, streamer=streamer, max_new_tokens=1024)17 unmodified linesfunc_caller.append({"role": "user", "content": f"{str(msg[0])}"})func_caller.append({"role": "assistant", "content": f"{str(msg[1])}"})message_text = message["text"]func_caller.append({"role": "user", "content": f'[SYSTEM]You are a helpful assistant. You have access to the following functions: \n {str(functions_metadata)}\n\nTo use these functions respond with:\n<functioncall> {{ "name": "function_name", "arguments": {{ "arg_1": "value_1", "arg_1": "value_1", ... }} }} </functioncall> [USER] {message_text}'})response = client_gemma.chat_completion(func_caller, max_tokens=200)26 unmodified lines272829303132333435363738394052 unmodified lines9394959697989917 unmodified lines11711811912012112212326 unmodified linesdef llava(message, history):if message.files:image = message.files[0]else:for hist in history:if type(hist[0])==tuple:image = hist[0][0]txt = message.textgr.Info("Analyzing image")image = Image.open(image).convert("RGB")52 unmodified linesuser_prompt = message# Handle image processingif message.files:inputs = llava(message, history)streamer = TextIteratorStreamer(processor, skip_prompt=True, **{"skip_special_tokens": True})generation_kwargs = dict(inputs, streamer=streamer, max_new_tokens=1024)17 unmodified linesfunc_caller.append({"role": "user", "content": f"{str(msg[0])}"})func_caller.append({"role": "assistant", "content": f"{str(msg[1])}"})message_text = message.textfunc_caller.append({"role": "user", "content": f'[SYSTEM]You are a helpful assistant. You have access to the following functions: \n {str(functions_metadata)}\n\nTo use these functions respond with:\n<functioncall> {{ "name": "function_name", "arguments": {{ "arg_1": "value_1", "arg_1": "value_1", ... }} }} </functioncall> [USER] {message_text}'})response = client_gemma.chat_completion(func_caller, max_tokens=200)
app.py+5-5