Spaces:
Runtime error
Runtime error
fancyfeast commited on
Commit ·
2a3d557
1
Parent(s): f4d3067
Man the chatinterface is weird #3
Browse files71 unmodified lines727374757677787980816 unmodified lines8889909192939453 unmodified lines14814915015115215315415 unmodified lines1701711721731741751761771781791801811821831 unmodified line18518618718818919019119219319419519619719819920020120220320420520620771 unmodified lines@spaces.GPU()@torch.no_grad()def chat_joycaption(message: dict, history, temperature: float, max_new_tokens: int) -> Generator[str, None, None]:torch.cuda.empty_cache()print(message)# Prompts are always stripped in training for nowprompt = message['text'].strip()6 unmodified linesimage = Image.open(message["files"][0])# Log the promptprint(f"Prompt: {prompt}")# Preprocess image# NOTE: I found the default processor for so400M to have worse results than just using PIL directly53 unmodified linesuse_cache=True,temperature=temperature,top_k=None,top_p=0.9,streamer=streamer,)15 unmodified lineswith gr.Blocks() as demo:gr.HTML(TITLE)gr.Markdown(DESCRIPTION)gr.ChatInterface(fn=chat_joycaption,chatbot=chatbot,type="messages",fill_height=True,multimodal=True,textbox=textbox,additional_inputs_accordion=None,#gr.Accordion(label="⚙️ Parameters", open=False, render=False),additional_inputs=[gr.Slider(minimum=0,maximum=1,1 unmodified linevalue=0.6,label="Temperature",render=False),gr.Slider(minimum=128,maximum=4096,step=1,value=1024,label="Max new tokens",render=False ),],examples=[['How to setup a human base on Mars? Give short answer.'],['Explain theory of relativity to me like I’m 8 years old.'],['What is 9,000 * 9,000?'],['Write a pun-filled happy birthday message to my friend Alex.'],['Justify why a penguin might make a good king of the jungle.']],cache_examples=False,)if __name__ == "__main__":demo.launch()71 unmodified lines727374757677787980816 unmodified lines888990919293949553 unmodified lines14915015115215315415515 unmodified lines1711721731741751761771781791801811821831841 unmodified line18618718818919019119219319419519619719819920020120220320420520620720820921021121271 unmodified lines@spaces.GPU()@torch.no_grad()def chat_joycaption(message: dict, history, temperature: float, top_p: float, max_new_tokens: int, log_prompt: bool) -> Generator[str, None, None]:torch.cuda.empty_cache()chat_interface.chatbot_state# Prompts are always stripped in training for nowprompt = message['text'].strip()6 unmodified linesimage = Image.open(message["files"][0])# Log the promptif log_prompt:print(f"Prompt: {prompt}")# Preprocess image# NOTE: I found the default processor for so400M to have worse results than just using PIL directly53 unmodified linesuse_cache=True,temperature=temperature,top_k=None,top_p=top_p,streamer=streamer,)15 unmodified lineswith gr.Blocks() as demo:gr.HTML(TITLE)gr.Markdown(DESCRIPTION)chat_interface = gr.ChatInterface(fn=chat_joycaption,chatbot=chatbot,type="messages",fill_height=True,multimodal=True,textbox=textbox,additional_inputs_accordion=gr.Accordion(label="⚙️ Parameters", open=True, render=True),additional_inputs=[gr.Slider(minimum=0,maximum=1,1 unmodified linevalue=0.6,label="Temperature",render=False),gr.Slider(minimum=0,maximum=1,step=0.05,value=0.9,label="Top p",render=False),gr.Slider(minimum=8,maximum=4096,step=1,value=1024,label="Max new tokens",render=False ),gr.Checkbox(label="Help improve JoyCaption by logging your text query", default=True, render=True),],)def new_trim_history(self, message, history_with_input):return message, []chat_interface._process_msg_and_trim_history = new_trim_history.__get__(chat_interface, chat_interface.__class__)if __name__ == "__main__":demo.launch()
app.py+21-16