Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files16 unmodified lines1718192021222324252619 unmodified lines46474849505152531 unmodified line55565758596061626364656636 unmodified lines10310410510610710810911011111246 unmodified lines15916016116216316416516616716893 unmodified lines26226326426526626726816 unmodified linesQwen2_5_VLForConditionalGeneration,Qwen2VLForConditionalGeneration,AutoProcessor,TextIteratorStreamer,)from transformers.image_utils import load_image# Constants for text generationMAX_MAX_NEW_TOKENS = 2048DEFAULT_MAX_NEW_TOKENS = 102419 unmodified linestorch_dtype=torch.float16).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,1 unmodified linetorch_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()36 unmodified lineselif 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:46 unmodified lineselif 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:93 unmodified lineswith gr.Column():output = gr.Textbox(label="Output", interactive=False, lines=2, scale=2)model_choice = gr.Radio(choices=["coreOCR-7B-050325-preview", "typhoon-ocr-7b", "Qwen2.5-VL-3B", "Imgscope-OCR-2B"],label="Select Model",value="coreOCR-7B-050325-preview")16 unmodified lines17181920212223242526272829303119 unmodified lines51525354555657581 unmodified line6061626364656667686970717236 unmodified lines10911011111211311411511611711846 unmodified lines16516616716816917017117217317493 unmodified lines26826927027127227327416 unmodified linesQwen2_5_VLForConditionalGeneration,Qwen2VLForConditionalGeneration,AutoProcessor,AutoTokenizer,TextIteratorStreamer,)from transformers.image_utils import load_imageimport subprocesssubprocess.run('pip install flash-attn --no-build-isolation', env={'FLASH_ATTENTION_SKIP_CUDA_BUILD': "TRUE"}, shell=True)# Constants for text generationMAX_MAX_NEW_TOKENS = 2048DEFAULT_MAX_NEW_TOKENS = 102419 unmodified linestorch_dtype=torch.float16).to(device).eval()# Load Space ThinkerMODEL_ID_Z = "remyxai/SpaceThinker-Qwen2.5VL-3B"processor_z = AutoProcessor.from_pretrained(MODEL_ID_Z, trust_remote_code=True)model_z = Qwen2_5_VLForConditionalGeneration.from_pretrained(MODEL_ID_Z,1 unmodified linetorch_dtype=torch.float16).to(device).eval()# Load moondreamMODEL_ID_T = "moondream/moondream-2b-2025-04-14-4bit"processor_t = AutoTokenizer.from_pretrained(MODEL_ID_X, trust_remote_code=True)model_t = AutoModelForCausalLM.from_pretrained(MODEL_ID_T,trust_remote_code=True,attn_implementation="flash_attention_2",torch_dtype=torch.float16).to(device).eval()36 unmodified lineselif model_name == "coreOCR-7B-050325-preview":processor = processor_xmodel = model_xelif model_name == "SpaceThinker-Qwen2.5VL-3B":processor = processor_zmodel = model_zelif model_name == "moondream-2b-2025-04-14-4bit":processor = processor_tmodel = model_telse:46 unmodified lineselif model_name == "coreOCR-7B-050325-preview":processor = processor_xmodel = model_xelif model_name == "SpaceThinker-Qwen2.5VL-3B":processor = processor_zmodel = model_zelif model_name == "moondream-2b-2025-04-14-4bit":processor = processor_tmodel = model_telse:93 unmodified lineswith gr.Column():output = gr.Textbox(label="Output", interactive=False, lines=2, scale=2)model_choice = gr.Radio(choices=["coreOCR-7B-050325-preview", "typhoon-ocr-7b", "SpaceThinker-Qwen2.5VL-3B", "moondream-2b-2025-04-14-4bit"],label="Select Model",value="coreOCR-7B-050325-preview")
app.py+17-11