Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files73 unmodified lines7475767778798024 unmodified lines10510610710810911011 unmodified lines12212312412512612712812913013113221 unmodified lines1541551561571581591604 unmodified lines16516616716816917011 unmodified lines18218318418518618718818919019119232 unmodified lines22522622722822923023117 unmodified lines24925025125225325425 unmodified lines28028128228328428528628728828929029129229329429529629729829930030130230330430530630773 unmodified linestorch_dtype=torch.float16).to(device).eval()#video samplingdef downsample_video(video_path):"""Downsamples the video to evenly spaced frames.24 unmodified linesrepetition_penalty: float = 1.2):"""Generates responses using the selected model for image input."""if model_name == "SkyCaptioner-V1":processor = processor_m11 unmodified linesprocessor = processor_ymodel = model_yelse:yield "Invalid model selected."returnif image is None:yield "Please upload an image."returnmessages = [{21 unmodified linesbuffer += new_textbuffer = buffer.replace("<|im_end|>", "")time.sleep(0.01)yield buffer@spaces.GPUdef generate_video(model_name: str, text: str, video_path: str,4 unmodified linesrepetition_penalty: float = 1.2):"""Generates responses using the selected model for video input."""if model_name == "SkyCaptioner-V1":processor = processor_m11 unmodified linesprocessor = processor_ymodel = model_yelse:yield "Invalid model selected."returnif video_path is None:yield "Please upload a video."returnframes = downsample_video(video_path)32 unmodified linesbuffer += new_textbuffer = buffer.replace("<|im_end|>", "")time.sleep(0.01)yield buffer# Define examples for image and video inferenceimage_examples = [17 unmodified lines.submit-btn:hover {background-color: #3498db !important;}"""# Create the Gradio Interface25 unmodified linestop_k = gr.Slider(label="Top-k", minimum=1, maximum=1000, step=1, value=50)repetition_penalty = gr.Slider(label="Repetition penalty", minimum=1.0, maximum=2.0, step=0.05, value=1.2)with gr.Column():output = gr.Textbox(label="Output", interactive=False, lines=2, scale=2)model_choice = gr.Radio(choices=["SkyCaptioner-V1", "Behemoth-3B-070225-post0.1", "SpaceThinker-3B", "coreOCR-7B-050325-preview", "SpaceOm-3B"],label="Select Model",value="SkyCaptioner-V1")gr.Markdown("**Model Info 💻** | [Report Bug](https://huggingface.co/spaces/prithivMLmods/VisionScope-R2/discussions)")gr.Markdown("> [SkyCaptioner-V1](https://huggingface.co/Skywork/SkyCaptioner-V1): structural video captioning model designed to generate high-quality, structural descriptions for video data. It integrates specialized sub-expert models.")gr.Markdown("> [SpaceThinker-Qwen2.5VL-3B](https://huggingface.co/remyxai/SpaceThinker-Qwen2.5VL-3B): thinking/reasoning multimodal/vision-language model (VLM) trained to enhance spatial reasoning.")gr.Markdown("> [coreOCR-7B-050325-preview](https://huggingface.co/prithivMLmods/coreOCR-7B-050325-preview): model is a fine-tuned version of qwen/qwen2-vl-7b, optimized for document-level optical character recognition (ocr), long-context vision-language understanding.")gr.Markdown("> [SpaceOm](https://huggingface.co/remyxai/SpaceOm): SpaceOm, the reasoning traces in the spacethinker dataset average ~200 thinking tokens, so now included longer reasoning traces in the training data to help the model use more tokens in reasoning.")image_submit.click(fn=generate_image,inputs=[model_choice, image_query, image_upload, max_new_tokens, temperature, top_p, top_k, repetition_penalty],outputs=output)video_submit.click(fn=generate_video,inputs=[model_choice, video_query, video_upload, max_new_tokens, temperature, top_p, top_k, repetition_penalty],outputs=output)if __name__ == "__main__":73 unmodified lines7475767778798024 unmodified lines10510610710810911011111 unmodified lines12312412512612712812913013113213321 unmodified lines1551561571581591601614 unmodified lines16616716816917017117211 unmodified lines18418518618718818919019119219319432 unmodified lines22722822923023123223317 unmodified lines25125225325425525625725825926026125 unmodified lines28728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831973 unmodified linestorch_dtype=torch.float16).to(device).eval()# Video samplingdef downsample_video(video_path):"""Downsamples the video to evenly spaced frames.24 unmodified linesrepetition_penalty: float = 1.2):"""Generates responses using the selected model for image input.Yields raw text and Markdown-formatted text."""if model_name == "SkyCaptioner-V1":processor = processor_m11 unmodified linesprocessor = processor_ymodel = model_yelse:yield "Invalid model selected.", "Invalid model selected."returnif image is None:yield "Please upload an image.", "Please upload an image."returnmessages = [{21 unmodified linesbuffer += new_textbuffer = buffer.replace("<|im_end|>", "")time.sleep(0.01)yield buffer, buffer@spaces.GPUdef generate_video(model_name: str, text: str, video_path: str,4 unmodified linesrepetition_penalty: float = 1.2):"""Generates responses using the selected model for video input.Yields raw text and Markdown-formatted text."""if model_name == "SkyCaptioner-V1":processor = processor_m11 unmodified linesprocessor = processor_ymodel = model_yelse:yield "Invalid model selected.", "Invalid model selected."returnif video_path is None:yield "Please upload a video.", "Please upload a video."returnframes = downsample_video(video_path)32 unmodified linesbuffer += new_textbuffer = buffer.replace("<|im_end|>", "")time.sleep(0.01)yield buffer, buffer# Define examples for image and video inferenceimage_examples = [17 unmodified lines.submit-btn:hover {background-color: #3498db !important;}.canvas-output {border: 2px solid #4682B4;border-radius: 10px;padding: 20px;}"""# Create the Gradio Interface25 unmodified linestop_k = gr.Slider(label="Top-k", minimum=1, maximum=1000, step=1, value=50)repetition_penalty = gr.Slider(label="Repetition penalty", minimum=1.0, maximum=2.0, step=0.05, value=1.2)with gr.Column():with gr.Column(elem_classes="canvas-output"):gr.Markdown("## Result.Md")output = gr.Textbox(label="Raw Output Stream", interactive=False, lines=2, scale=2)with gr.Accordion("Formatted Result (Result.md)", open=False):markdown_output = gr.Markdown(label="Formatted Result")model_choice = gr.Radio(choices=["SkyCaptioner-V1", "Behemoth-3B-070225-post0.1", "SpaceThinker-3B", "coreOCR-7B-050325-preview", "SpaceOm-3B"],label="Select Model",value="SkyCaptioner-V1")gr.Markdown("**Model Info 💻** | [Report Bug](https://huggingface.co/spaces/prithivMLmods/VisionScope-R2/discussions)")gr.Markdown("> [SkyCaptioner-V1](https://huggingface.co/Skywork/SkyCaptioner-V1): structural video captioning model designed to generate high-quality, structural descriptions for video data. It integrates specialized sub-expert models.")gr.Markdown("> [SpaceThinker-Qwen2.5VL-3B](https://huggingface.co/remyxai/SpaceThinker-Qwen2.5VL-3B): thinking/reasoning multimodal/vision-language model (VLM) trained to enhance spatial reasoning.")gr.Markdown("> [coreOCR-7B-050325-preview](https://huggingface.co/prithivMLmods/coreOCR-7B-050325-preview): model is a fine-tuned version of qwen/qwen2-vl-7b, optimized for document-level optical character recognition (ocr), long-context vision-language understanding.")gr.Markdown("> [SpaceOm](https://huggingface.co/remyxai/SpaceOm): SpaceOm, the reasoning traces in the spacethinker dataset average ~200 thinking tokens, so now included longer reasoning traces in the training data to help the model use more tokens in reasoning.")gr.Markdown("> [Behemoth-3B-070225-post0.1](https://huggingface.co/prithivMLmods/Behemoth-3B-070225-post0.1): The behemoth-3b-070225-post0.1 model is a fine-tuned version of qwen2.5-vl-3b-instruct, optimized for detailed image captioning, OCR tasks, and chain-of-thought reasoning.")gr.Markdown(">⚠️note: all the models in space are not guaranteed to perform well in video inference use cases.")image_submit.click(fn=generate_image,inputs=[model_choice, image_query, image_upload, max_new_tokens, temperature, top_p, top_k, repetition_penalty],outputs=[output, markdown_output])video_submit.click(fn=generate_video,inputs=[model_choice, video_query, video_upload, max_new_tokens, temperature, top_p, top_k, repetition_penalty],outputs=[output, markdown_output])if __name__ == "__main__":
app.py+27-15