Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files12343 unmodified lines891011121315 unmodified lines2930313233343517 unmodified lines53545556575859601 unmodified line626364656667686928 unmodified lines9899100101102103104105106107108109110111112113114115116117import timefrom threading import Threadfrom llava_llama3.serve.cli import chat_llavafrom llava_llama3.model.builder import load_pretrained_model3 unmodified linesimport argparseimport spacesimport osroot_path = os.path.dirname(os.path.abspath(__file__))print(root_path)15 unmodified lines'llava_llama3',args.load_8bit,args.load_4bit,device=args.device)@spaces.GPUdef bot_streaming(message, history):17 unmodified linesif image is None:raise gr.Error("You need to upload an image for LLaVA to work.")# Load the imageimage = Image.open(image)# Generate the prompt for the modelprompt = message['text']1 unmodified line# Use a streamer to generate the output in a streaming fashionstreamer = []image_file = image if isinstance(image, str) else image.filename# Define a function to call chat_llava in a separate threaddef generate_output():output = chat_llava(28 unmodified linesyield bufferchatbot=gr.Chatbot(scale=1)chat_input = gr.MultimodalTextbox(interactive=True, file_types=["image"], placeholder="Enter message or upload file...", show_label=False)with gr.Blocks(fill_height=True, ) as demo:gr.ChatInterface(fn=bot_streaming,title="FinLLaVA",examples=[{"text": "What is on the flower?", "files": ["./bee.jpg"]},{"text": "How to make this pastry?", "files": ["./baklava.png"]}],stop_btn="Stop Generation",multimodal=True,textbox=chat_input,chatbot=chatbot,)demo.queue(api_open=False)demo.launch(show_api=False, share=False)1233 unmodified lines7891011121315 unmodified lines293031323334353617 unmodified lines5455565758596061621 unmodified line64656667686928 unmodified lines9899100101102103104105106107108109110111112113114115116from threading import Threadfrom llava_llama3.serve.cli import chat_llavafrom llava_llama3.model.builder import load_pretrained_model3 unmodified linesimport argparseimport spacesimport osimport timeroot_path = os.path.dirname(os.path.abspath(__file__))print(root_path)15 unmodified lines'llava_llama3',args.load_8bit,args.load_4bit,device=args.device)@spaces.GPUdef bot_streaming(message, history):17 unmodified linesif image is None:raise gr.Error("You need to upload an image for LLaVA to work.")# Load the image if it's a path, otherwise use the existing PIL imageif isinstance(image, str):image = Image.open(image).convert('RGB')# Generate the prompt for the modelprompt = message['text']1 unmodified line# Use a streamer to generate the output in a streaming fashionstreamer = []# Define a function to call chat_llava in a separate threaddef generate_output():output = chat_llava(28 unmodified linesyield bufferchatbot = gr.Chatbot(scale=1)chat_input = gr.MultimodalTextbox(interactive=True, file_types=["image"], placeholder="Enter message or upload file...", show_label=False)with gr.Blocks(fill_height=True) as demo:gr.ChatInterface(fn=bot_streaming,title="FinLLaVA",examples=[{"text": "What is on the flower?", "files": ["./bee.jpg"]},{"text": "How to make this pastry?", "files": ["./baklava.png"]}],stop_btn="Stop Generation",multimodal=True,textbox=chat_input,chatbot=chatbot,)demo.queue(api_open=False)demo.launch(show_api=False, share=False)
app.py+17-18