Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files15 unmodified lines16171819202122236 unmodified lines303132333435363738399 unmodified lines495051525354555657585960616225 unmodified lines88899091929394959697989910010110238 unmodified lines14114214314414514614714814915015115215315415591 unmodified lines2472482492502512522532542558 unmodified lines26426526626715 unmodified linesfrom transformers import (Qwen2_5_VLForConditionalGeneration,Qwen2VLForConditionalGeneration,Gemma3ForConditionalGeneration,LlavaForConditionalGeneration,AutoProcessor,TextIteratorStreamer,)6 unmodified linesdevice = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")# Load gemma-3-4b-itMODEL_ID_M = "google/gemma-3-4b-it"processor_m = AutoProcessor.from_pretrained(MODEL_ID_M, trust_remote_code=True)model_m = Gemma3ForConditionalGeneration.from_pretrained(MODEL_ID_M,trust_remote_code=True,torch_dtype=torch.float169 unmodified lines).to(device).eval()# Load RelaxedMODEL_ID_Z = "fancyfeast/llama-joycaption-beta-one-hf-llava"processor_z = AutoProcessor.from_pretrained(MODEL_ID_Z, trust_remote_code=True)model_z = LlavaForConditionalGeneration.from_pretrained(MODEL_ID_Z,trust_remote_code=True,torch_dtype=torch.float16).to(device).eval()def downsample_video(video_path):"""Downsamples the video to evenly spaced frames.25 unmodified lines"""Generates responses using the selected model for image input."""if model_name == "gemma-3-4b-it":processor = processor_mmodel = model_melif model_name == "coreOCR-7B-050325-preview":processor = processor_xmodel = model_xelif model_name == "llama-joycaption":processor = processor_zmodel = model_zelse:yield "Invalid model selected."return38 unmodified lines"""Generates responses using the selected model for video input."""if model_name == "gemma-3-4b-it":processor = processor_mmodel = model_melif model_name == "coreOCR-7B-050325-preview":processor = processor_xmodel = model_xelif model_name == "llama-joycaption":processor = processor_zmodel = model_zelse:yield "Invalid model selected."return91 unmodified lineswith gr.Column():output = gr.Textbox(label="Output", interactive=False, lines=2, scale=2)model_choice = gr.Radio(choices=["gemma-3-4b-it", "coreOCR-7B-050325-preview", "llama-joycaption"],label="Select Model",value="gemma-3-4b-it")image_submit.click(8 unmodified lines)if __name__ == "__main__":demo.queue(max_size=30).launch(share=True, mcp_server=True, ssr_mode=False, show_error=True)15 unmodified lines161718192021226 unmodified lines293031323334353637389 unmodified lines4849505152535455565758596061626364656667686970717225 unmodified lines989910010110210310410510610710810911011111211311411538 unmodified lines15415515615715815916016116216316416516616716816917017191 unmodified lines2632642652662672682692702718 unmodified lines28028128228315 unmodified linesfrom transformers import (Qwen2_5_VLForConditionalGeneration,Qwen2VLForConditionalGeneration,Llama4ForConditionalGeneration,AutoProcessor,TextIteratorStreamer,)6 unmodified linesdevice = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")# Load meta-llama/Llama-Guard-4-12BMODEL_ID_M = "meta-llama/Llama-Guard-4-12B"processor_m = AutoProcessor.from_pretrained(MODEL_ID_M, trust_remote_code=True)model_m = Llama4ForConditionalGeneration.from_pretrained(MODEL_ID_M,trust_remote_code=True,torch_dtype=torch.float169 unmodified lines).to(device).eval()# Load RelaxedMODEL_ID_Z = "Qwen/Qwen2.5-VL-3B-Instruct"processor_z = AutoProcessor.from_pretrained(MODEL_ID_Z, trust_remote_code=True)model_z = Qwen2_5_VLForConditionalGeneration.from_pretrained(MODEL_ID_Z,trust_remote_code=True,torch_dtype=torch.float16).to(device).eval()# Load ImageScopeMODEL_ID_T = "prithivMLmods/Imgscope-OCR-2B-0527"processor_t = AutoProcessor.from_pretrained(MODEL_ID_X, trust_remote_code=True)model_t = Qwen2VLForConditionalGeneration.from_pretrained(MODEL_ID_T,trust_remote_code=True,torch_dtype=torch.float16).to(device).eval()def downsample_video(video_path):"""Downsamples the video to evenly spaced frames.25 unmodified lines"""Generates responses using the selected model for image input."""if model_name == "Llama-4":processor = processor_mmodel = model_melif model_name == "coreOCR-7B-050325-preview":processor = processor_xmodel = model_xelif model_name == "Qwen2.5-VL-3B":processor = processor_zmodel = model_zelif model_name == "Imgscope-OCR-2B":processor = processor_tmodel = model_telse:yield "Invalid model selected."return38 unmodified lines"""Generates responses using the selected model for video input."""if model_name == "Llama-4":processor = processor_mmodel = model_melif model_name == "coreOCR-7B-050325-preview":processor = processor_xmodel = model_xelif model_name == "Qwen2.5-VL-3B":processor = processor_zmodel = model_zelif model_name == "Imgscope-OCR-2B":processor = processor_tmodel = model_telse:yield "Invalid model selected."return91 unmodified lineswith gr.Column():output = gr.Textbox(label="Output", interactive=False, lines=2, scale=2)model_choice = gr.Radio(choices=["Llama-4", "coreOCR-7B-050325-preview", "Imgscope-OCR-2B", "Qwen2.5-VL-3B"],label="Select Model",value="Llama-4")image_submit.click(8 unmodified lines)if __name__ == "__main__":demo.queue(max_size=40).launch(share=True, mcp_server=True, ssr_mode=False, show_error=True)
app.py+30-14