Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files15 unmodified lines1617181920192021226 unmodified lines293031333432333436353637389 unmodified lines48495052515254535455565758596061626364656667686970717225 unmodified lines9899100911011021031041051069710710810911011111211311411538 unmodified lines15415515614415715815916016116215016316416516616716816917017191 unmodified lines2632642652502662672522682692702718 unmodified lines28028128226728315 unmodified linesfrom transformers import ( Qwen2_5_VLForConditionalGeneration, Qwen2VLForConditionalGeneration, Gemma3ForConditionalGeneration, LlavaForConditionalGeneration, Llama4ForConditionalGeneration, AutoProcessor, TextIteratorStreamer,)6 unmodified lines
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
# Load gemma-3-4b-itMODEL_ID_M = "google/gemma-3-4b-it"# 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 = Gemma3ForConditionalGeneration.from_pretrained(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 = "fancyfeast/llama-joycaption-beta-one-hf-llava"MODEL_ID_Z = "Qwen/Qwen2.5-VL-3B-Instruct"processor_z = AutoProcessor.from_pretrained(MODEL_ID_Z, trust_remote_code=True)model_z = LlavaForConditionalGeneration.from_pretrained(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 == "gemma-3-4b-it": if model_name == "Llama-4": processor = processor_m model = model_m elif model_name == "coreOCR-7B-050325-preview": processor = processor_x model = model_x elif model_name == "llama-joycaption": elif model_name == "Qwen2.5-VL-3B": processor = processor_z model = model_z elif model_name == "Imgscope-OCR-2B": processor = processor_t model = model_t else: yield "Invalid model selected." return38 unmodified lines """ Generates responses using the selected model for video input. """ if model_name == "gemma-3-4b-it": if model_name == "Llama-4": processor = processor_m model = model_m elif model_name == "coreOCR-7B-050325-preview": processor = processor_x model = model_x elif model_name == "llama-joycaption": elif model_name == "Qwen2.5-VL-3B": processor = processor_z model = model_z elif model_name == "Imgscope-OCR-2B": processor = processor_t model = model_t else: yield "Invalid model selected." return91 unmodified lines with 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"], choices=["Llama-4", "coreOCR-7B-050325-preview", "Imgscope-OCR-2B", "Qwen2.5-VL-3B"], label="Select Model", value="gemma-3-4b-it" value="Llama-4" ) 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) demo.queue(max_size=40).launch(share=True, mcp_server=True, ssr_mode=False, show_error=True)app.py+30-14